fix(data-source, ui): 页面配置配置数据源字段模块出错

This commit is contained in:
roymondchen 2024-02-28 14:56:45 +08:00
parent 06ff39b800
commit 455c696ff0
4 changed files with 16 additions and 4 deletions

View File

@ -17,8 +17,8 @@
*/ */
import { cloneDeep, union } from 'lodash-es'; import { cloneDeep, union } from 'lodash-es';
import type { AppCore } from '@tmagic/schema'; import type { AppCore, MApp, MNode, MPage, MPageFragment } from '@tmagic/schema';
import { getDepNodeIds, getNodes, replaceChildNode } from '@tmagic/utils'; import { getDepNodeIds, getNodes, isPage, isPageFragment, replaceChildNode } from '@tmagic/utils';
import DataSourceManager from './DataSourceManager'; import DataSourceManager from './DataSourceManager';
import type { ChangeEvent, DataSourceManagerData } from './types'; import type { ChangeEvent, DataSourceManagerData } from './types';
@ -39,13 +39,13 @@ export const createDataSourceManager = (app: AppCore, useMock?: boolean, initial
if (dsl.dataSources && dsl.dataSourceCondDeps && platform !== 'editor') { if (dsl.dataSources && dsl.dataSourceCondDeps && platform !== 'editor') {
getNodes(getDepNodeIds(dsl.dataSourceCondDeps), dsl.items).forEach((node) => { getNodes(getDepNodeIds(dsl.dataSourceCondDeps), dsl.items).forEach((node) => {
node.condResult = dataSourceManager.compliedConds(node); node.condResult = dataSourceManager.compliedConds(node);
replaceChildNode(node, dsl!.items); updateNode(node, dsl!);
}); });
} }
if (dsl.dataSources && dsl.dataSourceDeps) { if (dsl.dataSources && dsl.dataSourceDeps) {
getNodes(getDepNodeIds(dsl.dataSourceDeps), dsl.items).forEach((node) => { getNodes(getDepNodeIds(dsl.dataSourceDeps), dsl.items).forEach((node) => {
replaceChildNode(dataSourceManager.compiledNode(node), dsl!.items); updateNode(dataSourceManager.compiledNode(node), dsl!);
}); });
} }
@ -73,3 +73,12 @@ export const createDataSourceManager = (app: AppCore, useMock?: boolean, initial
return dataSourceManager; return dataSourceManager;
}; };
const updateNode = (node: MNode, dsl: MApp) => {
if (isPage(node) || isPageFragment(node)) {
const index = dsl.items?.findIndex((child: MNode) => child.id === node.id);
dsl.items.splice(index, 1, node as MPage | MPageFragment);
} else {
replaceChildNode(node, dsl!.items);
}
};

View File

@ -26,6 +26,7 @@ export default [
{ {
text: '页面标题', text: '页面标题',
name: 'title', name: 'title',
type: 'data-source-input',
}, },
{ {
name: 'layout', name: 'layout',

View File

@ -26,6 +26,7 @@ export default [
{ {
text: '页面标题', text: '页面标题',
name: 'title', name: 'title',
type: 'data-source-input',
}, },
{ {
name: 'layout', name: 'layout',

View File

@ -26,6 +26,7 @@ export default [
{ {
text: '页面标题', text: '页面标题',
name: 'title', name: 'title',
type: 'data-source-input',
}, },
{ {
name: 'layout', name: 'layout',