Skip to content

Commit

Permalink
#504 lookup字段弹出的列表搜索按主列表搜索一样规则改进
Browse files Browse the repository at this point in the history
  • Loading branch information
yinlianghui committed Dec 2, 2023
1 parent 15999b2 commit 59bf92e
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,13 @@ export async function lookupToAmisPicker(field, readonly, ctx){
source.data.$self = "$$";

source.requestAdaptor = `
let __changedFilterFormValues = api.data.$self.__changedFilterFormValues || {};
let __changedSearchBoxValues = api.data.$self.__changedSearchBoxValues || {};
// 把表单搜索和快速搜索中的change事件中记录的过滤条件也拼到$self中,是为解决触发搜索请求时,两边输入的过滤条件都带上,即:
// 有时在搜索表单中输入过滤条件事,忘记点击回车键或搜索按钮,而是进一步修改快速搜索框中的关键字点击其中回车键触发搜索
// 这种情况下,触发的搜索请求中没有带上搜索表单中输入的过滤条件。
// 反过来先在快速搜索框中输入过滤条件却不点击其中回车键触发搜索,而是到搜索表单中触发搜索请求也是一样的。
Object.assign(api.data.$self, __changedSearchBoxValues, __changedFilterFormValues);
const selfData = JSON.parse(JSON.stringify(api.data.$self));
var filters = [];
var pageSize = api.data.pageSize || 10;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ export async function getObjectFieldsFilterBarSchema(objectSchema, ctx) {
const filterFormSchema = await getObjectFieldsFilterFormSchema(ctx);
const keywordsSearchBoxName = ctx.keywordsSearchBoxName || "__keywords";
const onSearchScript = `
// console.log("===onSearchScript=form==");
const scope = event.context.scoped;
var filterForm = scope.parent.parent.getComponents().find(function(n){
return n.props.type === "form";
Expand Down Expand Up @@ -156,6 +157,7 @@ export async function getObjectFieldsFilterBarSchema(objectSchema, ctx) {
crudService && crudService.setData({isFieldsFilterEmpty, showFieldsFilter});
`;
const onCancelScript = `
// console.log("===onCancelScript=form==");
const scope = event.context.scoped;
var filterForm = scope.parent.parent.getComponents().find(function(n){
return n.props.type === "form";
Expand Down Expand Up @@ -201,18 +203,22 @@ export async function getObjectFieldsFilterBarSchema(objectSchema, ctx) {
// filterForm.handleAction({},{
// "actionType": "clear"
// });
// 清除__changedFilterFormValues中的值
crud && crud.setData({__changedFilterFormValues: {}});
filterForm.handleFormSubmit(event);
// crud.handleFilterSubmit(removedValues);
let filterFormService = SteedosUI.getClosestAmisComponentByType(filterForm.context, "service");
filterFormService.setData({showFieldsFilter: !!!filterFormService.props.data.showFieldsFilter});
//触发amis crud 高度重算
setTimeout(()=>{
window.dispatchEvent(new Event("resize"))
}, 100);
// 移除搜索按钮上的红点,同时清除__changedFilterFormValues中的值
// 移除搜索按钮上的红点
// let crudService = scope.getComponentById("service_listview_" + event.data.objectName);
let crudService = crud && SteedosUI.getClosestAmisComponentByType(crud.context, "service");
crudService && crudService.setData({isFieldsFilterEmpty: true, showFieldsFilter: false, __changedFilterFormValues: {}});
crudService && crudService.setData({isFieldsFilterEmpty: true, showFieldsFilter: false});
`;
const dataProviderInited = `
const objectName = data.objectName;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,10 +104,12 @@ function getObjectHeaderQuickSearchBox(mainObject, fields, formFactor, { isLooku
const onChangeScript = `
const scope = event.context.scoped;
let crud = SteedosUI.getClosestAmisComponentByType(scope, "crud");
let crudService = crud && SteedosUI.getClosestAmisComponentByType(crud.context, "service");
// let crudService = crud && SteedosUI.getClosestAmisComponentByType(crud.context, "service");
let __changedSearchBoxValues = {};
__changedSearchBoxValues["${keywordsSearchBoxName}"] = event.data["${keywordsSearchBoxName}"];
crudService && crudService.setData({__changedSearchBoxValues: __changedSearchBoxValues});
// crudService && crudService.setData({__changedSearchBoxValues: __changedSearchBoxValues});
// 这里不用crudService而用crud是因为lookup字段弹出的列表中的crudService中的变量无法传入crud的发送适配器中
crud && crud.setData({__changedSearchBoxValues: __changedSearchBoxValues});
`;

// onSearchScript中加上了onChangeScript中的脚本,是因为amis 3.2不能用change事件执行onChangeScript
Expand Down Expand Up @@ -431,9 +433,10 @@ export async function getObjectFilter(objectSchema, fields, options) {
let filterFormValues = filterFormService.getData();
let crud = SteedosUI.getClosestAmisComponentByType(scope, "crud");
const changedFilterFormValues = _.pickBy(filterFormValues, function(n,k){return /^__searchable__/.test(k);});;
// crud && crud.setData(changedFilterFormValues);
let crudService = crud && SteedosUI.getClosestAmisComponentByType(crud.context, "service");
crudService && crudService.setData({__changedFilterFormValues: changedFilterFormValues});
// let crudService = crud && SteedosUI.getClosestAmisComponentByType(crud.context, "service");
// crudService && crudService.setData({__changedFilterFormValues: changedFilterFormValues});
// 这里不用crudService而用crud是因为lookup字段弹出的列表中的crudService中的变量无法传入crud的发送适配器中
crud && crud.setData({__changedFilterFormValues: changedFilterFormValues});
`;
return {
"title": "",
Expand Down

0 comments on commit 59bf92e

Please sign in to comment.