From 15999b2c34d2c1486c1c6e042948884665b9491c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=AE=B7=E4=BA=AE=E8=BE=89?= Date: Sat, 2 Dec 2023 19:24:21 +0800 Subject: [PATCH] =?UTF-8?q?#504=20=E5=BF=AB=E9=80=9F=E6=90=9C=E7=B4=A2?= =?UTF-8?q?=E6=A1=86=E5=86=85=E5=9B=9E=E8=BD=A6=E4=BA=8B=E4=BB=B6=E5=BA=94?= =?UTF-8?q?=E8=AF=A5=E4=BD=BF=E7=94=A8=E6=9C=80=E6=96=B0=E7=9A=84=E6=90=9C?= =?UTF-8?q?=E7=B4=A2=E6=9D=A1=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/lib/converter/amis/toolbar.js | 31 +++++++++++-------- 1 file changed, 18 insertions(+), 13 deletions(-) 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 590d3dea9..901f82447 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 @@ -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"); @@ -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", @@ -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": { @@ -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",