From 1dd53c50b918b76148c8de835356089bb343d9f1 Mon Sep 17 00:00:00 2001 From: zhangzhulei Date: Thu, 18 Aug 2022 11:40:05 +0800 Subject: [PATCH] =?UTF-8?q?amis-saas-5348=20[Feature]=20=E3=80=8C=E7=BB=84?= =?UTF-8?q?=E4=BB=B6=E9=85=8D=E7=BD=AE=E3=80=8D=E5=B0=81=E8=A3=85=E6=95=B0?= =?UTF-8?q?=E6=8D=AE=E6=98=A0=E5=B0=84schema?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Change-Id: I0f2717eb1dd01cfc48ec1b3de997bc10c9d28b1f --- packages/amis-editor/src/plugin/Dialog.tsx | 67 +------------------ packages/amis-editor/src/plugin/Drawer.tsx | 64 +----------------- packages/amis-editor/src/tpl/options.tsx | 76 +++++++++++++++++++++- 3 files changed, 77 insertions(+), 130 deletions(-) diff --git a/packages/amis-editor/src/plugin/Dialog.tsx b/packages/amis-editor/src/plugin/Dialog.tsx index 6af6e616c..53a050c91 100644 --- a/packages/amis-editor/src/plugin/Dialog.tsx +++ b/packages/amis-editor/src/plugin/Dialog.tsx @@ -144,72 +144,7 @@ export class DialogPlugin extends BasePlugin { name: 'showLoading', value: true }), - getSchemaTpl('switch', { - label: tipedLabel( - '数据映射', - '
当开启数据映射时,弹框中的数据只会包含设置的部分,请绑定数据。如:{"a": "${a}", "b": 2}。
' - + '
当值为 __undefined时,表示删除对应的字段,可以结合{"&": "$$"}来达到黑名单效果。
' - ), - name: 'dataMapSwitch', - value: false, - className: 'm-b-xs', - onChange: (value: any, oldValue: any, model: any, form: any) => { - const newDataValue = value ? {} : null; - form.setValues({ - __dataMap: newDataValue, - data: newDataValue - }); - } - }), - { - type: 'alert', - level: 'info', - visibleOn: 'this.dataMapSwitch', - className: 'relative', - body: [ - { - type: 'tpl', - tpl: '${data["&"] ? "已开启定制参数功能,可点击关闭该功能。" : "如果需要在默认数据的基础上定制参数,请配置开启参数定制再定义key和value。"}' - }, - { - type: 'button', - label: '${data["&"] ? "立即关闭" : "立即开启"}', - level: 'link', - className: 'absolute bottom-3 right-10', - onClick: (e: any, props: any) => { - const newData = props.data.data?.['&'] === '$$' ? {} : {'&': '$$'}; - // 用onBulkChange保证代码视图和编辑区域数据保持同步 - props.onBulkChange({ - data: newData, - __dataMap: {} - }); - } - } - ], - showCloseButton: true - }, - getSchemaTpl('combo-container', { - type: 'input-kv', - syncDefaultValue: false, - name: '__dataMap', - value: null, - visibleOn: 'this.dataMapSwitch', - className: 'block -mt-5', - deleteBtn: { - icon: 'fa fa-trash' - }, - onChange: (value: any, oldValue: any, model: any, form: any) => { - // 用assign保证'&'第一个被遍历到 - const newDataMap = form.data.data?.['&'] ? - assign({'&': '$$'}, value) : cloneDeep(value); - form.setValues({ - data: newDataMap - }); - form.setValues({ - data: newDataMap - }); - } - }), + getSchemaTpl('dataMap'), ] } ]) diff --git a/packages/amis-editor/src/plugin/Drawer.tsx b/packages/amis-editor/src/plugin/Drawer.tsx index 342bd5872..26e90f850 100644 --- a/packages/amis-editor/src/plugin/Drawer.tsx +++ b/packages/amis-editor/src/plugin/Drawer.tsx @@ -178,69 +178,7 @@ export class DrawerPlugin extends BasePlugin { label: '可拖拽抽屉大小', value: false }), - getSchemaTpl('switch', { - label: tipedLabel( - '数据映射', - '
当开启数据映射时,弹框中的数据只会包含设置的部分,请绑定数据。如:{"a": "${a}", "b": 2}。
' - + '
当值为 __undefined时,表示删除对应的字段,可以结合{"&": "$$"}来达到黑名单效果。
' - ), - name: 'dataMapSwitch', - value: false, - className: 'm-b-xs', - onChange: (value: any, oldValue: any, model: any, form: any) => { - const newDataValue = value ? {} : null; - form.setValues({ - __dataMap: newDataValue, - data: newDataValue - }); - } - }), - { - type: 'alert', - level: 'info', - visibleOn: 'this.dataMapSwitch', - className: 'relative', - body: [ - { - type: 'tpl', - tpl: '${data["&"] ? "已开启定制参数功能,可点击关闭该功能。" : "如果需要在默认数据的基础上定制参数,请配置开启参数定制再定义key和value。"}' - }, - { - type: 'button', - label: '${data["&"] ? "立即关闭" : "立即开启"}', - level: 'link', - className: 'absolute bottom-3 right-10', - onClick: (e: any, props: any) => { - const newData = props.data.data?.['&'] === '$$' ? {} : {'&': '$$'}; - // 用onBulkChange保证代码视图和编辑区域数据保持同步 - props.onBulkChange({ - data: newData, - __dataMap: {} - }); - } - } - ], - showCloseButton: true - }, - getSchemaTpl('combo-container', { - type: 'input-kv', - syncDefaultValue: false, - name: '__dataMap', - value: null, - visibleOn: 'this.dataMapSwitch', - className: 'block -mt-5', - deleteBtn: { - icon: 'fa fa-trash' - }, - onChange: (value: any, oldValue: any, model: any, form: any) => { - // 用assign保证'&'第一个被遍历到 - const newDataMap = form.data.data?.['&'] ? - assign({'&': '$$'}, value) : cloneDeep(value); - form.setValues({ - data: newDataMap - }); - } - }) + getSchemaTpl('dataMap') ] } ]) diff --git a/packages/amis-editor/src/tpl/options.tsx b/packages/amis-editor/src/tpl/options.tsx index f91b93d0e..f529e4036 100644 --- a/packages/amis-editor/src/tpl/options.tsx +++ b/packages/amis-editor/src/tpl/options.tsx @@ -1,6 +1,8 @@ import {setSchemaTpl, getSchemaTpl, defaultValue} from 'amis-editor-core'; import {tipedLabel} from '../component/BaseControl'; import {SchemaObject} from 'amis/lib/Schema'; +import assign from 'lodash/assign'; +import cloneDeep from 'lodash/cloneDeep'; setSchemaTpl('options', { label: '选项 Options', @@ -319,4 +321,76 @@ setSchemaTpl('treeOptionControl', { mode: 'normal', name: 'options', type: 'ae-treeOptionControl' -}); \ No newline at end of file +}); + +setSchemaTpl('dataMap', { + type: 'container', + body: [ + getSchemaTpl('switch', { + label: tipedLabel( + '数据映射', + '
当开启数据映射时,弹框中的数据只会包含设置的部分,请绑定数据。如:{"a": "${a}", "b": 2}。
' + + '
当值为 __undefined时,表示删除对应的字段,可以结合{"&": "$$"}来达到黑名单效果。
' + ), + name: 'dataMapSwitch', + value: false, + className: 'm-b-xs', + onChange: (value: any, oldValue: any, model: any, form: any) => { + const newDataValue = value ? {} : null; + form.setValues({ + dataMap: newDataValue, + data: newDataValue + }); + } + }), + { + type: 'alert', + level: 'info', + visibleOn: 'this.dataMapSwitch', + className: 'relative', + body: [ + { + type: 'tpl', + tpl: '${data["&"] ? "已开启定制参数功能,可点击关闭该功能。" : "如果需要在默认数据的基础上定制参数,请配置开启参数定制再定义key和value。"}' + }, + { + type: 'button', + label: '${data["&"] ? "立即关闭" : "立即开启"}', + level: 'link', + className: 'absolute bottom-3 right-10', + onClick: (e: any, props: any) => { + const newData = props.data.data?.['&'] === '$$' ? {} : {'&': '$$'}; + // 用onBulkChange保证代码视图和编辑区域数据保持同步 + props.onBulkChange({ + data: newData, + dataMap: {} + }); + } + } + ], + showCloseButton: true + }, + getSchemaTpl('combo-container', { + type: 'input-kv', + syncDefaultValue: false, + name: 'dataMap', + value: null, + visibleOn: 'this.dataMapSwitch', + className: 'block -mt-5', + deleteBtn: { + icon: 'fa fa-trash' + }, + onChange: (value: any, oldValue: any, model: any, form: any) => { + // 用assign保证'&'第一个被遍历到 + const newDataMap = form.data.data?.['&'] ? + assign({'&': '$$'}, value) : cloneDeep(value); + form.setValues({ + data: newDataMap + }); + form.setValues({ + data: newDataMap + }); + } + }), + ] +}) \ No newline at end of file