Skip to content

Commit

Permalink
[Bug]: 列表搜索有时变更快速搜索框的过滤条件回车发出的请求会把搜索表单中的过滤条件还原为上次的条件,接口请求的条件也是使用上次的
Browse files Browse the repository at this point in the history
  • Loading branch information
yinlianghui committed Jan 10, 2025
1 parent d00a86c commit 02e1c39
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand All @@ -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;
}
Expand Down Expand Up @@ -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;
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("=getObjectFieldsFilterBarSchema==onSearchScript===event.data====", event.data);
let isLookup = event.data.isLookup;
let __lookupField = event.data.__lookupField;
const scope = event.context.scoped;
Expand All @@ -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";
Expand All @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"});
Expand Down Expand Up @@ -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);
`;
Expand Down Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -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;
Expand Down

0 comments on commit 02e1c39

Please sign in to comment.