Skip to content

Commit

Permalink
#504 快速搜索框内回车事件应该使用最新的搜索条件
Browse files Browse the repository at this point in the history
  • Loading branch information
yinlianghui committed Dec 2, 2023
1 parent 2af5fa9 commit 15999b2
Showing 1 changed file with 18 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -101,9 +101,23 @@ function getObjectHeaderQuickSearchBox(mainObject, fields, formFactor, { isLooku
crudKeywords = (localListViewProps && localListViewProps.__keywords) || "";
}

const onSearchScript = `
// 这段脚本只为解决点击搜索表单取消按钮,再重新在其中输入过滤条件但是不点击搜索按钮或回车按键触发搜索,此时在快速搜索框输入过滤条件按回车按键会把搜索表单中的过滤条件清空的问题
const onChangeScript = `
const scope = event.context.scoped;
let crud = SteedosUI.getClosestAmisComponentByType(scope, "crud");
let crudService = crud && SteedosUI.getClosestAmisComponentByType(crud.context, "service");
let __changedSearchBoxValues = {};
__changedSearchBoxValues["${keywordsSearchBoxName}"] = event.data["${keywordsSearchBoxName}"];
crudService && crudService.setData({__changedSearchBoxValues: __changedSearchBoxValues});
`;

// onSearchScript中加上了onChangeScript中的脚本,是因为amis 3.2不能用change事件执行onChangeScript
// 而点击回车按键又不会触发blur事件,所以只能每次回车事件中额外再执行一次onChangeScript
// 等升级到amis 3.4+,blur事件换成change事件执行onChangeScript,就可以不用在onSearchScript中执行onChangeScript了
const onSearchScript = `
${onChangeScript}
// 下面的脚本只为解决点击搜索表单取消按钮,再重新在其中输入过滤条件但是不点击搜索按钮或回车按键触发搜索,此时在快速搜索框输入过滤条件按回车按键会把搜索表单中的过滤条件清空的问题
// const scope = event.context.scoped;
// 如果点击过顶部搜索栏表单的取消按钮,会把此处event.data.__super.__super.__super中的搜索表单项的所有字段设置为null
// 点击取消按钮后继续在表单项中输入过滤条件且最后没有点击回车按键或点击表单项搜索按钮的话,在快速搜索中点击回车按钮提交搜索会所顶部搜索表单中的字段值清空
let filterForm = SteedosUI.getClosestAmisComponentByType(scope, "form");
Expand All @@ -112,15 +126,6 @@ function getObjectHeaderQuickSearchBox(mainObject, fields, formFactor, { isLooku
}, 500);
`;

const onChangeScript = `
const scope = event.context.scoped;
let crud = SteedosUI.getClosestAmisComponentByType(scope, "crud");
let crudService = crud && SteedosUI.getClosestAmisComponentByType(crud.context, "service");
let __changedSearchBoxValues = {};
__changedSearchBoxValues["${keywordsSearchBoxName}"] = event.data.value;
crudService && crudService.setData({__changedSearchBoxValues: __changedSearchBoxValues});
`;

return {
"type": "tooltip-wrapper",
"id": "steedos_crud_toolbar_quick_search",
Expand All @@ -139,7 +144,7 @@ function getObjectHeaderQuickSearchBox(mainObject, fields, formFactor, { isLooku
"placeholder": "搜索此列表",
"value": crudKeywords,
"clearable": true,
"clearAndSubmit": true,
// "clearAndSubmit": true,//因为清除并不会触发失去焦点事件,只有禁用,但是它会触发change事件,所以等升级到amis 3.4+后可以重新放开
"searchImediately": false,
"onEvent": {
"search": {
Expand All @@ -150,7 +155,7 @@ function getObjectHeaderQuickSearchBox(mainObject, fields, formFactor, { isLooku
}
]
},
"blur": { //这里把change事件换成blur是因为amis 3.2change事件中setData会卡
"blur": { //这里把change事件换成blur是因为amis 3.2change事件中setData会卡,升级到3.4+后就可以换回change事件
"actions": [
{
"actionType": "custom",
Expand Down

0 comments on commit 15999b2

Please sign in to comment.