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" >