From 74c9deaa29ba1fb6bd14486b17f68f8c8ab5afce Mon Sep 17 00:00:00 2001 From: roymondchen Date: Wed, 28 Jun 2023 16:39:47 +0800 Subject: [PATCH] =?UTF-8?q?feat(editor,=20core):=20=E6=94=AF=E6=8C=81?= =?UTF-8?q?=E7=9B=B4=E6=8E=A5=E7=BB=91=E5=AE=9A=E6=95=B4=E4=B8=AA=E6=95=B0?= =?UTF-8?q?=E6=8D=AE=E6=BA=90=E5=AF=B9=E8=B1=A1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/core/src/App.ts | 15 +++- .../editor/src/fields/DataSourceSelect.vue | 75 +++++++++++++++++++ packages/editor/src/index.ts | 3 + packages/editor/src/initService.ts | 4 + .../data-source/DataSourceListPanel.vue | 20 ++++- packages/editor/src/services/dep.ts | 1 + packages/editor/src/utils/dep.ts | 8 +- packages/form/src/fields/Select.vue | 26 ++++--- packages/form/src/schema.ts | 6 +- packages/utils/src/index.ts | 10 ++- playground/src/configs/dsl.ts | 47 +++++++++--- 11 files changed, 185 insertions(+), 30 deletions(-) create mode 100644 packages/editor/src/fields/DataSourceSelect.vue diff --git a/packages/core/src/App.ts b/packages/core/src/App.ts index 75d23ce0..78ad31fe 100644 --- a/packages/core/src/App.ts +++ b/packages/core/src/App.ts @@ -322,7 +322,20 @@ class App extends EventEmitter { } public compiledNode(node: MNode, content: DataSourceManagerData, sourceId?: Id) { - return compiledNode((str: string) => template(str)(content), cloneDeep(node), this.dsl?.dataSourceDeps, sourceId); + return compiledNode( + (value: any) => { + if (typeof value === 'string') { + return template(value)(content); + } + if (value?.isBindDataSource && value.dataSourceId) { + return content[value.dataSourceId]; + } + return value; + }, + cloneDeep(node), + this.dsl?.dataSourceDeps, + sourceId, + ); } public destroy() { diff --git a/packages/editor/src/fields/DataSourceSelect.vue b/packages/editor/src/fields/DataSourceSelect.vue new file mode 100644 index 00000000..961c4ca0 --- /dev/null +++ b/packages/editor/src/fields/DataSourceSelect.vue @@ -0,0 +1,75 @@ + + + diff --git a/packages/editor/src/index.ts b/packages/editor/src/index.ts index 46e4804b..9e6227d1 100644 --- a/packages/editor/src/index.ts +++ b/packages/editor/src/index.ts @@ -23,6 +23,7 @@ import CodeSelect from './fields/CodeSelect.vue'; import CodeSelectCol from './fields/CodeSelectCol.vue'; import DataSourceFields from './fields/DataSourceFields.vue'; import DataSourceInput from './fields/DataSourceInput.vue'; +import DataSourceSelect from './fields/DataSourceSelect.vue'; import EventSelect from './fields/EventSelect.vue'; import KeyValue from './fields/KeyValue.vue'; import uiSelect from './fields/UISelect.vue'; @@ -53,6 +54,7 @@ export { default as CodeSelect } from './fields/CodeSelect.vue'; export { default as CodeSelectCol } from './fields/CodeSelectCol.vue'; export { default as DataSourceFields } from './fields/DataSourceFields.vue'; export { default as DataSourceInput } from './fields/DataSourceInput.vue'; +export { default as DataSourceSelect } from './fields/DataSourceSelect.vue'; export { default as EventSelect } from './fields/EventSelect.vue'; export { default as KeyValue } from './fields/KeyValue.vue'; export { default as CodeBlockList } from './layouts/sidebar/code-block/CodeBlockList.vue'; @@ -87,5 +89,6 @@ export default { app.component('m-fields-data-source-fields', DataSourceFields); app.component('m-fields-key-value', KeyValue); app.component('m-fields-data-source-input', DataSourceInput); + app.component('m-fields-data-source-select', DataSourceSelect); }, }; diff --git a/packages/editor/src/initService.ts b/packages/editor/src/initService.ts index 43147660..f8d31cdb 100644 --- a/packages/editor/src/initService.ts +++ b/packages/editor/src/initService.ts @@ -236,18 +236,22 @@ export const initServiceEvents = ( } }; + // 新增节点,收集依赖 const nodeAddHandler = (nodes: MNode[]) => { depService.collect(nodes); }; + // 节点更新,收集依赖 const nodeUpdateHandler = (nodes: MNode[]) => { depService.collect(nodes); }; + // 节点删除,清除对齐的依赖收集 const nodeRemoveHandler = (nodes: MNode[]) => { depService.clear(nodes); }; + // 由于历史记录变化是更新整个page,所以历史记录变化时,需要重新收集依赖 const historyChangeHandler = (page: MPage) => { depService.collect([page], true); }; diff --git a/packages/editor/src/layouts/sidebar/data-source/DataSourceListPanel.vue b/packages/editor/src/layouts/sidebar/data-source/DataSourceListPanel.vue index 7ebd9b22..5a74ed6c 100644 --- a/packages/editor/src/layouts/sidebar/data-source/DataSourceListPanel.vue +++ b/packages/editor/src/layouts/sidebar/data-source/DataSourceListPanel.vue @@ -15,6 +15,7 @@ :expand-on-click-node="false" :data="list" :highlight-current="true" + @node-click="clickHandler" >