From 9c7d711c167c5e8ee1e9d8a8e89d66d245070dee Mon Sep 17 00:00:00 2001 From: roymondchen Date: Wed, 12 Mar 2025 14:22:33 +0800 Subject: [PATCH] =?UTF-8?q?fix(editor):=20=E6=95=B0=E6=8D=AE=E6=BA=90?= =?UTF-8?q?=E4=BF=AE=E6=94=B9=E5=90=8E=EF=BC=8C=E4=BE=9D=E8=B5=96=E9=87=8D?= =?UTF-8?q?=E6=96=B0=E6=94=B6=E9=9B=86=E4=B8=8D=E5=87=86=E7=A1=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/editor/src/initService.ts | 44 +++++++++++++++++++++-------- packages/editor/src/services/dep.ts | 6 ++-- 2 files changed, 36 insertions(+), 14 deletions(-) diff --git a/packages/editor/src/initService.ts b/packages/editor/src/initService.ts index 4bffbdfb..2751c90c 100644 --- a/packages/editor/src/initService.ts +++ b/packages/editor/src/initService.ts @@ -502,6 +502,7 @@ export const initServiceEvents = ( isModifyField = changeRecord.propPath === 'fields' || /fields.(\d)+.name/.test(changeRecord.propPath) || + /fields.(\d)+.defaultValue/.test(changeRecord.propPath) || /fields.(\d)+$/.test(changeRecord.propPath); isModifyMock = changeRecord.propPath === 'mocks'; @@ -523,25 +524,35 @@ export const initServiceEvents = ( if (Array.isArray(root?.items)) { depService.clearIdleTasks(); - removeDataSourceTarget(config.id); - initDataSourceDepTarget(config); - let collectIdlePromises: Promise[] = []; if (isModifyField) { + depService.removeTarget(config.id, DepTargetType.DATA_SOURCE); + depService.removeTarget(config.id, DepTargetType.DATA_SOURCE_COND); + + depService.addTarget(createDataSourceTarget(config, reactive({}))); + depService.addTarget(createDataSourceCondTarget(config, reactive({}))); + collectIdlePromises = [ collectIdle(root.items, true, DepTargetType.DATA_SOURCE), collectIdle(root.items, true, DepTargetType.DATA_SOURCE_COND), ]; } else if (isModifyMock) { + depService.removeTarget(config.id, DepTargetType.DATA_SOURCE); + + depService.addTarget(createDataSourceTarget(config, reactive({}))); + collectIdlePromises = [collectIdle(root.items, true, DepTargetType.DATA_SOURCE)]; } else if (isModifyMethod) { + depService.removeTarget(config.id, DepTargetType.DATA_SOURCE_METHOD); + + depService.addTarget(createDataSourceMethodTarget(config, reactive({}))); + collectIdlePromises = [collectIdle(root.items, true, DepTargetType.DATA_SOURCE_METHOD)]; } - Promise.all(collectIdlePromises).then(() => { - updateDataSourceSchema(); - updateDsData(); - updateStageNodes(root.items); - }); + Promise.all(collectIdlePromises) + .then(() => updateDataSourceSchema()) + .then(() => updateDsData()) + .then(() => updateStageNodes(root.items)); } } else if (root?.dataSources) { updateDsData(); @@ -616,20 +627,31 @@ export const initServiceEvents = ( } root.dataSourceCondDeps[target.id] = target.deps; } + + if (target.type === DepTargetType.DATA_SOURCE_METHOD) { + if (!root.dataSourceMethodDeps) { + root.dataSourceMethodDeps = {}; + } + root.dataSourceMethodDeps[target.id] = target.deps; + } }; - const targetRemoveHandler = (id: string | number) => { + const targetRemoveHandler = (id: string | number, type: DepTargetType) => { const root = editorService.get('root'); if (!root) return; - if (root.dataSourceDeps) { + if (root.dataSourceDeps && type === DepTargetType.DATA_SOURCE) { delete root.dataSourceDeps[id]; } - if (root.dataSourceCondDeps) { + if (root.dataSourceCondDeps && type === DepTargetType.DATA_SOURCE_COND) { delete root.dataSourceCondDeps[id]; } + + if (root.dataSourceMethodDeps && type === DepTargetType.DATA_SOURCE_METHOD) { + delete root.dataSourceMethodDeps[id]; + } }; depService.on('add-target', targetAddHandler); diff --git a/packages/editor/src/services/dep.ts b/packages/editor/src/services/dep.ts index aeb7b2dd..5893db7e 100644 --- a/packages/editor/src/services/dep.ts +++ b/packages/editor/src/services/dep.ts @@ -28,7 +28,7 @@ import BaseService from './BaseService'; export interface DepEvents { 'add-target': [target: Target]; - 'remove-target': [id: string | number]; + 'remove-target': [id: string | number, type: string | DepTargetType]; collected: [nodes: MNode[], deep: boolean]; 'ds-collected': [nodes: MNode[], deep: boolean]; } @@ -77,7 +77,7 @@ class Dep extends BaseService { if (!targets) return; for (const target of Object.values(targets)) { - this.emit('remove-target', target.id); + this.emit('remove-target', target.id, type); } } @@ -96,7 +96,7 @@ class Dep extends BaseService { public removeTarget(id: Id, type: string = DepTargetType.DEFAULT) { this.watcher.removeTarget(id, type); - this.emit('remove-target', id); + this.emit('remove-target', id, type); } public clearTargets() {