diff --git a/packages/@steedos-widgets/amis-lib/src/lib/converter/amis/fields/table.js b/packages/@steedos-widgets/amis-lib/src/lib/converter/amis/fields/table.js index 6eb5d17f3..7a2a5f84b 100644 --- a/packages/@steedos-widgets/amis-lib/src/lib/converter/amis/fields/table.js +++ b/packages/@steedos-widgets/amis-lib/src/lib/converter/amis/fields/table.js @@ -1295,6 +1295,8 @@ export async function getTableApi(mainObject, fields, options){ // 反过来先在快速搜索框中输入过滤条件却不点击其中回车键触发搜索,而是到搜索表单中触发搜索请求也是一样的。 // 这里直接合并到api.data.$self,而不是后面定义的selfData变量,是因为可以省去在接收适配器中写一样的合并逻辑 // 如果有问题可以改为合并到selfData变量中,但是要在接收适配器中写上一样的合并逻辑,否则里面的过滤条件不会存入本地存储中 + console.log("==requestAdaptor==__changedSearchBoxValues===", __changedSearchBoxValues); + console.log("==requestAdaptor==__changedFilterFormValues===", __changedFilterFormValues); Object.assign(api.data.$self, __changedSearchBoxValues, __changedFilterFormValues); // selfData 中的数据由 CRUD 控制. selfData中,只能获取到 CRUD 给定的data. 无法从数据链中获取数据. let selfData = JSON.parse(JSON.stringify(api.data.$self)); @@ -1308,6 +1310,7 @@ export async function getTableApi(mainObject, fields, options){ if(localListViewProps){ localListViewProps = JSON.parse(localListViewProps); selfData = Object.assign({}, localListViewProps, selfData); + // Object.assign(api.data.$self, selfData); if(!api.data.filter){ api.data.filter = localListViewProps.filter; } @@ -1610,6 +1613,8 @@ export async function getTableApi(mainObject, fields, options){ } } ${options.adaptor || ''} + console.log("==adaptor==api===", api); + console.log("==adaptor==payload===", payload); return payload; `; return api; diff --git a/packages/@steedos-widgets/amis-lib/src/lib/converter/amis/fields_filter.js b/packages/@steedos-widgets/amis-lib/src/lib/converter/amis/fields_filter.js index ba21aeb47..bd4c576b5 100644 --- a/packages/@steedos-widgets/amis-lib/src/lib/converter/amis/fields_filter.js +++ b/packages/@steedos-widgets/amis-lib/src/lib/converter/amis/fields_filter.js @@ -100,6 +100,7 @@ export async function getObjectFieldsFilterBarSchema(objectSchema, ctx) { const filterFormSchema = await getObjectFieldsFilterFormSchema(ctx); const keywordsSearchBoxName = ctx.keywordsSearchBoxName || "__keywords"; const onSearchScript = ` + console.log("=getObjectFieldsFilterBarSchema==onSearchScript===event.data====", event.data); let isLookup = event.data.isLookup; let __lookupField = event.data.__lookupField; const scope = event.context.scoped; @@ -109,6 +110,8 @@ export async function getObjectFieldsFilterBarSchema(objectSchema, ctx) { }); // 使用filterForm.getValues()的话,并不能拿到本地存储中的过滤条件,所以需要从event.data中取,因为本地存储中的过滤条件自动填充到表单上时filterForm.getValues()拿不到。 let filterFormValues = event.data; + filterFormValues = JSON.parse(JSON.stringify(filterFormValues)); //只取当层数据域中数据,去除__super层数据 + const changedFilterFormValues = _.pickBy(filterFormValues, function(n,k){return /^__searchable__/.test(k);}); // 同步__changedFilterFormValues中的值 // crud && crud.setData({__changedFilterFormValues: {}}); let __changedFilterFormValuesKey = "__changedFilterFormValues"; @@ -119,9 +122,10 @@ export async function getObjectFieldsFilterBarSchema(objectSchema, ctx) { } __changedFilterFormValuesKey += lookupTag; } + console.log("=getObjectFieldsFilterBarSchema==onSearchScript====__changedFilterFormValues===", changedFilterFormValues); if(crud){ let crudData = crud.getData(); - crudData[__changedFilterFormValuesKey] = filterFormValues; + crudData[__changedFilterFormValuesKey] = changedFilterFormValues; crud.setData(crudData); } filterForm.handleFormSubmit(event); diff --git a/packages/@steedos-widgets/amis-lib/src/lib/converter/amis/toolbar.js b/packages/@steedos-widgets/amis-lib/src/lib/converter/amis/toolbar.js index 2a416ab63..78e389378 100644 --- a/packages/@steedos-widgets/amis-lib/src/lib/converter/amis/toolbar.js +++ b/packages/@steedos-widgets/amis-lib/src/lib/converter/amis/toolbar.js @@ -105,7 +105,7 @@ function getObjectHeaderQuickSearchBox(mainObject, fields, formFactor, { isLooku } const onChangeScript = ` - // console.log("==search=onChangeScript==="); + console.log("==getObjectHeaderQuickSearchBox====onChangeScript=onChangeScript===", event.data); const scope = event.context.scoped; let crud = SteedosUI.getClosestAmisComponentByType(scope, "crud"); // let crudService = crud && SteedosUI.getClosestAmisComponentByType(crud.context, "service", {name: "service_object_table_crud"}); @@ -147,7 +147,9 @@ function getObjectHeaderQuickSearchBox(mainObject, fields, formFactor, { isLooku } __changedFilterFormValuesKey += lookupTag; } + console.log("===getObjectHeaderQuickSearchBox====onSearchScript==__changedFilterFormValues====", JSON.stringify(event.data[__changedFilterFormValuesKey])); setTimeout(function(){ + console.log("==onChangeScript==onSearchScript====setTimeout===__changedFilterFormValues====", JSON.stringify(event.data[__changedFilterFormValuesKey])); filterForm && filterForm.setValues(event.data[__changedFilterFormValuesKey]); }, 500); `; @@ -455,6 +457,7 @@ export function getObjectFooterToolbar(mainObject, formFactor, options) { export async function getObjectFilter(objectSchema, fields, options) { const fieldsFilterBarSchema = await getObjectListHeaderFieldsFilterBar(objectSchema, null, options); let onSubmitSuccScript = ` + console.log("=getObjectFilter==onSubmitSuccScript===event.data====", event.data); let isLookup = event.data.isLookup; if(isLookup){ return; @@ -476,12 +479,37 @@ export async function getObjectFilter(objectSchema, fields, options) { let filterFormService = SteedosUI.getClosestAmisComponentByType(filterForm.context, "service"); // 使用event.data的话,并不能拿到本地存储中的过滤条件,所以需要从filterFormService中取。 let filterFormValues = filterFormService.getData(); + filterFormValues = JSON.parse(JSON.stringify(filterFormValues)); //只取当层数据域中数据,去除__super层数据 + console.log("=getObjectFilter==onSubmitSuccScript===filterFormValues====", filterFormValues); let isFieldsFilterEmpty = SteedosUI.isFilterFormValuesEmpty(filterFormValues); let crud = SteedosUI.getClosestAmisComponentByType(scope, "crud"); + const changedFilterFormValues = _.pickBy(filterFormValues, function(n,k){return /^__searchable__/.test(k);}); + // 这里不用crudService而用crud是因为lookup字段弹出的列表中的crudService中的变量无法传入crud的发送适配器中 + // crud && crud.setData({__changedFilterFormValues: changedFilterFormValues}); + let __changedFilterFormValuesKey = "__changedFilterFormValues"; + if(isLookup && __lookupField){ + let lookupTag = "__lookup__" + __lookupField.name + "__" + __lookupField.reference_to; + if(__lookupField.reference_to_field){ + lookupTag += "__" + __lookupField.reference_to_field; + } + __changedFilterFormValuesKey += lookupTag; + } + console.log("=getObjectFilter==onSubmitSuccScript===changedFilterFormValues====", changedFilterFormValues); + if(crud){ + // 这里加setTimeout是因为不加的话,crud中作用域中的__changedFilterFormValues变量又会还原到上一次的值 + // 大概会是crud组件内部的bug,因为这个onSubmitSuccScript事件后只有crud api的接收适配器代码要执行,而crud api的接收适配器代码中并没有对__changedFilterFormValues变量进行操作 + setTimeout(function(){ + let crudData = crud.getData(); + crudData[__changedFilterFormValuesKey] = changedFilterFormValues; + crud.setData(crudData); + }, 500); + } + let crudService = crud && SteedosUI.getClosestAmisComponentByType(crud.context, "service", {name: "service_object_table_crud"}); crudService && crudService.setData({isFieldsFilterEmpty}); `; let onChangeScript = ` + console.log("=getObjectFilter==onChangeScript===event.data====", event.data); let isLookup = event.data.isLookup; let __lookupField = event.data.__lookupField; const scope = event.context.scoped; @@ -505,6 +533,7 @@ export async function getObjectFilter(objectSchema, fields, options) { } __changedFilterFormValuesKey += lookupTag; } + console.log("=getObjectFilter==onChangeScript===changedFilterFormValues====", changedFilterFormValues); if(crud){ let crudData = crud.getData(); crudData[__changedFilterFormValuesKey] = changedFilterFormValues;