From 9c96baca034e68c14e2f4fef3ed3060cfa105a43 Mon Sep 17 00:00:00 2001 From: hsm-lv Date: Tue, 18 Oct 2022 17:03:06 +0800 Subject: [PATCH] =?UTF-8?q?[amis-saas-7504]:=20crud=20reload=E5=A2=9E?= =?UTF-8?q?=E5=8A=A0resetPage?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Change-Id: I66386e5f6a22e16cdaa837df9a9e6f3fddf05126 --- packages/amis-editor/src/locale/en-US.ts | 5 +- packages/amis-editor/src/locale/zh-CN.ts | 4 +- .../src/renderer/event-control/actions.tsx | 218 ++++++++++-------- .../src/renderer/event-control/helper.tsx | 35 ++- 4 files changed, 154 insertions(+), 108 deletions(-) diff --git a/packages/amis-editor/src/locale/en-US.ts b/packages/amis-editor/src/locale/en-US.ts index 4fd57ae93..80aab3ee0 100644 --- a/packages/amis-editor/src/locale/en-US.ts +++ b/packages/amis-editor/src/locale/en-US.ts @@ -3284,5 +3284,8 @@ extendLocale('en-US', { 'Update the data field of the target component or the data value of the target form item', 'e7af71fb102cc86ab3be6a2fb32b5e3f': 'Data settings', '77b1081c177fa3334cc93c99f0ecee75': 'Direct assignment', - 'f5c5e3d69daee06ea1606378ef466765': 'Member assignment' + 'f5c5e3d69daee06ea1606378ef466765': 'Member assignment', + '697af73997072e0ce9ee65b15a7b3715': 'Reset PageNo', + 'd7bf42dd6e66f2818f9a232603c4a53b': + 'When "Yes" is selected, the crud component will request the first page of data' }); diff --git a/packages/amis-editor/src/locale/zh-CN.ts b/packages/amis-editor/src/locale/zh-CN.ts index 6bdad0be7..88cd8b40a 100644 --- a/packages/amis-editor/src/locale/zh-CN.ts +++ b/packages/amis-editor/src/locale/zh-CN.ts @@ -2903,5 +2903,7 @@ extendLocale('zh-CN', { '更新目标组件的数据域或目标表单项的数据值', 'e7af71fb102cc86ab3be6a2fb32b5e3f': '数据设置', '77b1081c177fa3334cc93c99f0ecee75': '直接赋值', - 'f5c5e3d69daee06ea1606378ef466765': '成员赋值' + 'f5c5e3d69daee06ea1606378ef466765': '成员赋值', + '697af73997072e0ce9ee65b15a7b3715': '重置页码', + 'd7bf42dd6e66f2818f9a232603c4a53b': '选择“是”时,将重新请求第一页数据。' }); diff --git a/packages/amis-editor/src/renderer/event-control/actions.tsx b/packages/amis-editor/src/renderer/event-control/actions.tsx index 89df9ddcd..edff4aead 100644 --- a/packages/amis-editor/src/renderer/event-control/actions.tsx +++ b/packages/amis-editor/src/renderer/event-control/actions.tsx @@ -692,110 +692,128 @@ const ACTION_TYPE_TREE = (manager: any): RendererPluginAction[] => { '目标组件', true, (value: string, oldVal: any, data: any, form: any) => { + form.setValueByName('args.resetPage', true); form.setValueByName('__addParam', true); form.setValueByName('__addParamType', 'default'); form.setValueByName('__reloadParam', []); } - ) - // { - // type: 'switch', - // name: '__addParam', - // label: '追加数据', - // labelRemark: { - // className: 'm-l-xs', - // icon: 'fa fa-question-circle', - // rootClose: true, - // content: `选择“是”时,会将源组件所在数据域变量同步到目标组件的数据域。
如果目标组件是增删改查组件,且增删改查组件的数据拉取接口是get请求,则源组件所在数据域变量将追加到目标组件的初始化请求query中。`, - // placement: 'top' - // }, - // onText: '是', - // offText: '否', - // mode: 'horizontal', - // pipeIn: defaultValue(true), - // visibleOn: `data.actionType === "reload" && ${IS_DATA_CONTAINER}` - // }, - // { - // type: 'radios', - // name: 'dataMergeMode', - // mode: 'horizontal', - // label: '追加方式', - // labelRemark: { - // className: 'm-l-xs', - // icon: 'fa fa-question-circle', - // rootClose: true, - // content: `选择“合并”时,会将数据合并到目标组件的数据域。
选择“覆盖”时,数据会直接覆盖目标组件的数据域。`, - // placement: 'top' - // }, - // pipeIn: defaultValue('merge'), - // visibleOn: `data.__addParam && data.actionType === "reload" && ${IS_DATA_CONTAINER}`, - // options: [ - // { - // label: '合并', - // value: 'merge' - // }, - // { - // label: '覆盖', - // value: 'override' - // } - // ] - // }, - // { - // type: 'radios', - // name: '__addParamType', - // mode: 'horizontal', - // label: '数据配置', - // labelRemark: { - // className: 'm-l-xs', - // icon: 'fa fa-question-circle', - // rootClose: true, - // content: `数据默认为源组件所在数据域,可以选择“自定义”来定制所需数据`, - // placement: 'top' - // }, - // pipeIn: defaultValue('default'), - // visibleOn: `data.__addParam && data.actionType === "reload" && ${IS_DATA_CONTAINER}`, - // options: [ - // { - // label: '源组件所在数据域', - // value: 'default' - // }, - // { - // label: '自定义', - // value: 'custom' - // } - // ] - // }, - // { - // type: 'combo', - // name: '__reloadParams', - // label: '', - // multiple: true, - // removable: true, - // addable: true, - // strictMode: false, - // canAccessSuperData: true, - // size: 'lg', - // mode: 'horizontal', - // items: [ - // { - // name: 'key', - // type: 'input-text', - // placeholder: '参数名', - // labelField: 'label', - // valueField: 'value', - // required: true - // }, - // { - // name: 'val', - // type: 'input-formula', - // placeholder: '参数值', - // variables: '${variables}', - // evalMode: false, - // variableMode: 'tabs', - // inputMode: 'input-group' - // } - // ], - // visibleOn: `data.__addParam && data.__addParamType === "custom" && data.actionType === "reload" && ${IS_DATA_CONTAINER}` - // } + ), + { + type: 'switch', + name: '__resetPage', + label: '重置页码', + labelRemark: { + className: 'm-l-xs', + icon: 'fa fa-question-circle', + rootClose: true, + content: `选择“是”时,将重新请求第一页数据。`, + placement: 'top' + }, + onText: '是', + offText: '否', + mode: 'horizontal', + pipeIn: defaultValue(true), + visibleOn: `data.actionType === "reload" && data.__rendererName === "crud"` + }, + { + type: 'switch', + name: '__addParam', + label: '追加数据', + labelRemark: { + className: 'm-l-xs', + icon: 'fa fa-question-circle', + rootClose: true, + content: `选择“是”时,会将源组件所在数据域变量同步到目标组件的数据域。
如果目标组件是增删改查组件,且增删改查组件的数据拉取接口是get请求,则源组件所在数据域变量将追加到目标组件的初始化请求query中。`, + placement: 'top' + }, + onText: '是', + offText: '否', + mode: 'horizontal', + pipeIn: defaultValue(true), + visibleOn: `data.actionType === "reload" && ${IS_DATA_CONTAINER}` + }, + { + type: 'radios', + name: 'dataMergeMode', + mode: 'horizontal', + label: '追加方式', + labelRemark: { + className: 'm-l-xs', + icon: 'fa fa-question-circle', + rootClose: true, + content: `选择“合并”时,会将数据合并到目标组件的数据域。
选择“覆盖”时,数据会直接覆盖目标组件的数据域。`, + placement: 'top' + }, + pipeIn: defaultValue('merge'), + visibleOn: `data.__addParam && data.actionType === "reload" && ${IS_DATA_CONTAINER}`, + options: [ + { + label: '合并', + value: 'merge' + }, + { + label: '覆盖', + value: 'override' + } + ] + }, + { + type: 'radios', + name: '__addParamType', + mode: 'horizontal', + label: '数据配置', + labelRemark: { + className: 'm-l-xs', + icon: 'fa fa-question-circle', + rootClose: true, + content: `数据默认为源组件所在数据域,可以选择“自定义”来定制所需数据`, + placement: 'top' + }, + pipeIn: defaultValue('default'), + visibleOn: `data.__addParam && data.actionType === "reload" && ${IS_DATA_CONTAINER}`, + options: [ + { + label: '源组件所在数据域', + value: 'default' + }, + { + label: '自定义', + value: 'custom' + } + ] + }, + { + type: 'combo', + name: '__reloadParams', + label: '', + multiple: true, + removable: true, + addable: true, + strictMode: false, + canAccessSuperData: true, + size: 'lg', + mode: 'horizontal', + items: [ + { + name: 'key', + type: 'input-text', + placeholder: '参数名', + labelField: 'label', + valueField: 'value', + required: true + }, + { + name: 'val', + type: 'input-formula', + placeholder: '参数值', + variables: '${variables}', + evalMode: false, + variableMode: 'tabs', + inputMode: 'input-group' + } + ], + visibleOn: `data.__addParam && data.__addParamType === "custom" && data.actionType === "reload" && ${IS_DATA_CONTAINER}` + } ] }, { diff --git a/packages/amis-editor/src/renderer/event-control/helper.tsx b/packages/amis-editor/src/renderer/event-control/helper.tsx index 0eabeb247..1df2e23db 100644 --- a/packages/amis-editor/src/renderer/event-control/helper.tsx +++ b/packages/amis-editor/src/renderer/event-control/helper.tsx @@ -1151,21 +1151,35 @@ export const getEventControlConfig = ( // 处理刷新组件动作的追加参数 if (config.actionType === 'reload') { - config.__addParam = config.args === undefined || !!config.args; + config.__resetPage = config.args?.resetPage; + config.__addParam = config.data === undefined || !!config.data; - if (config.args && typeof config.args === 'object') { + if ( + (config.data && typeof config.data === 'object') || + (config.args && + !Object.keys(config.args).length && + config.data === undefined) + ) { config.__addParamType = 'custom'; } if ( config.__addParam && config.__addParamType === 'custom' && - config.args + config.data + ) { + config.__reloadParams = objectToComboArray(config.data); + } else if ( + config.args && + !Object.keys(config.args).length && + config.data === undefined ) { config.__reloadParams = objectToComboArray(config.args); } } + delete config.data; + // 还原args为可视化配置结构(args + addOnArgs) if (config.args) { if (innerArgs) { @@ -1260,13 +1274,22 @@ export const getEventControlConfig = ( // 刷新组件时,处理是否追加事件变量 if (config.actionType === 'reload') { - action.args = null; + action.data = null; action.dataMergeMode = undefined; + + action.args = + action.__rendererName === 'crud' + ? { + ...action.args, + resetPage: config.__resetPage ?? true + } + : undefined; + if (config.__addParam) { action.dataMergeMode = config.dataMergeMode || 'merge'; - action.args = undefined; + action.data = undefined; if (config.__addParamType === 'custom') { - action.args = comboArrayToObject(config.__reloadParams || []); + action.data = comboArrayToObject(config.__reloadParams || []); } } }