@nocobase/flow-engine 2.1.0-alpha.7 → 2.1.0-alpha.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/JSRunner.d.ts +10 -1
- package/lib/JSRunner.js +50 -5
- package/lib/ViewScopedFlowEngine.js +5 -1
- package/lib/components/dnd/gridDragPlanner.js +6 -2
- package/lib/components/settings/wrappers/contextual/StepSettingsDialog.js +16 -2
- package/lib/components/subModel/AddSubModelButton.js +15 -0
- package/lib/executor/FlowExecutor.js +25 -8
- package/lib/flowContext.js +4 -1
- package/lib/flowEngine.d.ts +19 -0
- package/lib/flowEngine.js +29 -1
- package/lib/runjs-context/registry.d.ts +1 -1
- package/lib/runjs-context/setup.js +19 -12
- package/lib/scheduler/ModelOperationScheduler.d.ts +5 -1
- package/lib/scheduler/ModelOperationScheduler.js +3 -2
- package/lib/utils/parsePathnameToViewParams.js +1 -1
- package/lib/views/useDialog.js +10 -0
- package/lib/views/useDrawer.js +10 -0
- package/package.json +4 -4
- package/src/JSRunner.ts +68 -4
- package/src/ViewScopedFlowEngine.ts +4 -0
- package/src/__tests__/JSRunner.test.ts +27 -1
- package/src/__tests__/runjsContext.test.ts +13 -0
- package/src/__tests__/runjsPreprocessDefault.test.ts +23 -0
- package/src/components/__tests__/gridDragPlanner.test.ts +88 -0
- package/src/components/dnd/gridDragPlanner.ts +8 -2
- package/src/components/settings/wrappers/contextual/StepSettingsDialog.tsx +18 -2
- package/src/components/subModel/AddSubModelButton.tsx +16 -0
- package/src/components/subModel/__tests__/AddSubModelButton.test.tsx +50 -0
- package/src/executor/FlowExecutor.ts +28 -9
- package/src/executor/__tests__/flowExecutor.test.ts +26 -0
- package/src/flowContext.ts +5 -3
- package/src/flowEngine.ts +33 -1
- package/src/models/__tests__/dispatchEvent.when.test.ts +214 -0
- package/src/runjs-context/registry.ts +1 -1
- package/src/runjs-context/setup.ts +21 -12
- package/src/scheduler/ModelOperationScheduler.ts +14 -3
- package/src/utils/__tests__/parsePathnameToViewParams.test.ts +7 -0
- package/src/utils/parsePathnameToViewParams.ts +2 -2
- package/src/views/__tests__/useDialog.closeDestroy.test.tsx +1 -0
- package/src/views/useDialog.tsx +14 -0
- package/src/views/useDrawer.tsx +14 -0
- package/src/views/usePage.tsx +1 -0
package/src/flowEngine.ts
CHANGED
|
@@ -117,6 +117,13 @@ export class FlowEngine {
|
|
|
117
117
|
private _previousEngine?: FlowEngine;
|
|
118
118
|
private _nextEngine?: FlowEngine;
|
|
119
119
|
|
|
120
|
+
/**
|
|
121
|
+
* 视图销毁回调。由 useDrawer / useDialog 在创建弹窗视图时注册,
|
|
122
|
+
* 供外部(如 afterSuccess)通过引擎栈遍历来关闭多层弹窗。
|
|
123
|
+
* embed 视图(usePage)不注册此回调,因此 destroyView() 会自然跳过。
|
|
124
|
+
*/
|
|
125
|
+
private _destroyView?: () => void;
|
|
126
|
+
|
|
120
127
|
private _resources = new Map<string, typeof FlowResource>();
|
|
121
128
|
|
|
122
129
|
/**
|
|
@@ -282,6 +289,28 @@ export class FlowEngine {
|
|
|
282
289
|
}
|
|
283
290
|
}
|
|
284
291
|
|
|
292
|
+
/**
|
|
293
|
+
* 注册视图销毁回调(由 useDrawer / useDialog 调用)。
|
|
294
|
+
*/
|
|
295
|
+
public setDestroyView(fn: () => void): void {
|
|
296
|
+
this._destroyView = fn;
|
|
297
|
+
}
|
|
298
|
+
|
|
299
|
+
/**
|
|
300
|
+
* 关闭当前引擎关联的弹窗视图。
|
|
301
|
+
* 路由触发的弹窗会先 navigation.back() 清理 URL,再 destroy() 移除元素;
|
|
302
|
+
* 非路由弹窗直接 destroy()。
|
|
303
|
+
* embed 视图不注册回调,调用时返回 false 自动跳过。
|
|
304
|
+
* @returns 是否成功执行
|
|
305
|
+
*/
|
|
306
|
+
public destroyView(): boolean {
|
|
307
|
+
if (this._destroyView) {
|
|
308
|
+
this._destroyView();
|
|
309
|
+
return true;
|
|
310
|
+
}
|
|
311
|
+
return false;
|
|
312
|
+
}
|
|
313
|
+
|
|
285
314
|
// (已移除)getModelGlobal/forEachModelGlobal/getAllModelsGlobal:不再维护冗余全局遍历 API
|
|
286
315
|
|
|
287
316
|
/**
|
|
@@ -959,6 +988,7 @@ export class FlowEngine {
|
|
|
959
988
|
async loadOrCreateModel<T extends FlowModel = FlowModel>(
|
|
960
989
|
options,
|
|
961
990
|
extra?: {
|
|
991
|
+
skipSave?: boolean;
|
|
962
992
|
delegateToParent?: boolean;
|
|
963
993
|
delegate?: FlowContext;
|
|
964
994
|
},
|
|
@@ -984,7 +1014,9 @@ export class FlowEngine {
|
|
|
984
1014
|
model = this.createModel<T>(data as any, extra);
|
|
985
1015
|
} else {
|
|
986
1016
|
model = this.createModel<T>(options, extra);
|
|
987
|
-
|
|
1017
|
+
if (!extra?.skipSave) {
|
|
1018
|
+
await model.save();
|
|
1019
|
+
}
|
|
988
1020
|
}
|
|
989
1021
|
if (model.parent) {
|
|
990
1022
|
const subModel = model.parent.findSubModel(model.subKey, (m) => {
|
|
@@ -105,6 +105,45 @@ describe('dispatchEvent dynamic event flow phase (scheduleModelOperation integra
|
|
|
105
105
|
expect(calls).toEqual(['static-a', 'dynamic']);
|
|
106
106
|
});
|
|
107
107
|
|
|
108
|
+
test("phase='afterAllFlows': skips when event aborted by ctx.exitAll()", async () => {
|
|
109
|
+
const engine = new FlowEngine();
|
|
110
|
+
class M extends FlowModel {}
|
|
111
|
+
engine.registerModels({ M });
|
|
112
|
+
|
|
113
|
+
const calls: string[] = [];
|
|
114
|
+
|
|
115
|
+
M.registerFlow({
|
|
116
|
+
key: 'S',
|
|
117
|
+
on: { eventName: 'go' },
|
|
118
|
+
steps: {
|
|
119
|
+
a: { handler: async () => void calls.push('static-a') } as any,
|
|
120
|
+
},
|
|
121
|
+
});
|
|
122
|
+
|
|
123
|
+
const model = engine.createModel({ use: 'M' });
|
|
124
|
+
model.registerFlow('Abort', {
|
|
125
|
+
on: { eventName: 'go' },
|
|
126
|
+
sort: -10,
|
|
127
|
+
steps: {
|
|
128
|
+
d: {
|
|
129
|
+
handler: async (ctx: any) => {
|
|
130
|
+
calls.push('abort');
|
|
131
|
+
ctx.exitAll();
|
|
132
|
+
},
|
|
133
|
+
} as any,
|
|
134
|
+
},
|
|
135
|
+
});
|
|
136
|
+
model.registerFlow('AfterAll', {
|
|
137
|
+
on: { eventName: 'go', phase: 'afterAllFlows' },
|
|
138
|
+
steps: {
|
|
139
|
+
d: { handler: async () => void calls.push('after-all') } as any,
|
|
140
|
+
},
|
|
141
|
+
});
|
|
142
|
+
|
|
143
|
+
await model.dispatchEvent('go');
|
|
144
|
+
expect(calls).toEqual(['abort']);
|
|
145
|
+
});
|
|
146
|
+
|
|
108
147
|
test("phase='beforeFlow': instance flow runs before the target static flow", async () => {
|
|
109
148
|
const engine = new FlowEngine();
|
|
110
149
|
class M extends FlowModel {}
|
|
@@ -161,6 +200,39 @@ describe('dispatchEvent dynamic event flow phase (scheduleModelOperation integra
|
|
|
161
200
|
expect(calls).toEqual(['static-a', 'static-b', 'dynamic']);
|
|
162
201
|
});
|
|
163
202
|
|
|
203
|
+
test("phase='afterFlow': skips when anchor flow is aborted by ctx.exitAll()", async () => {
|
|
204
|
+
const engine = new FlowEngine();
|
|
205
|
+
class M extends FlowModel {}
|
|
206
|
+
engine.registerModels({ M });
|
|
207
|
+
|
|
208
|
+
const calls: string[] = [];
|
|
209
|
+
|
|
210
|
+
M.registerFlow({
|
|
211
|
+
key: 'S',
|
|
212
|
+
on: { eventName: 'go' },
|
|
213
|
+
steps: {
|
|
214
|
+
a: {
|
|
215
|
+
handler: async (ctx: any) => {
|
|
216
|
+
calls.push('static-a');
|
|
217
|
+
ctx.exitAll();
|
|
218
|
+
},
|
|
219
|
+
} as any,
|
|
220
|
+
b: { handler: async () => void calls.push('static-b') } as any,
|
|
221
|
+
},
|
|
222
|
+
});
|
|
223
|
+
|
|
224
|
+
const model = engine.createModel({ use: 'M' });
|
|
225
|
+
model.registerFlow('D', {
|
|
226
|
+
on: { eventName: 'go', phase: 'afterFlow', flowKey: 'S' },
|
|
227
|
+
steps: {
|
|
228
|
+
d: { handler: async () => void calls.push('dynamic') } as any,
|
|
229
|
+
},
|
|
230
|
+
});
|
|
231
|
+
|
|
232
|
+
await model.dispatchEvent('go');
|
|
233
|
+
expect(calls).toEqual(['static-a']);
|
|
234
|
+
});
|
|
235
|
+
|
|
164
236
|
test("phase='beforeStep': instance flow runs before the target static step", async () => {
|
|
165
237
|
const engine = new FlowEngine();
|
|
166
238
|
class M extends FlowModel {}
|
|
@@ -217,6 +289,39 @@ describe('dispatchEvent dynamic event flow phase (scheduleModelOperation integra
|
|
|
217
289
|
expect(calls).toEqual(['static-a', 'dynamic', 'static-b']);
|
|
218
290
|
});
|
|
219
291
|
|
|
292
|
+
test("phase='afterStep': skips when anchor step is aborted by ctx.exitAll()", async () => {
|
|
293
|
+
const engine = new FlowEngine();
|
|
294
|
+
class M extends FlowModel {}
|
|
295
|
+
engine.registerModels({ M });
|
|
296
|
+
|
|
297
|
+
const calls: string[] = [];
|
|
298
|
+
|
|
299
|
+
M.registerFlow({
|
|
300
|
+
key: 'S',
|
|
301
|
+
on: { eventName: 'go' },
|
|
302
|
+
steps: {
|
|
303
|
+
a: {
|
|
304
|
+
handler: async (ctx: any) => {
|
|
305
|
+
calls.push('static-a');
|
|
306
|
+
ctx.exitAll();
|
|
307
|
+
},
|
|
308
|
+
} as any,
|
|
309
|
+
b: { handler: async () => void calls.push('static-b') } as any,
|
|
310
|
+
},
|
|
311
|
+
});
|
|
312
|
+
|
|
313
|
+
const model = engine.createModel({ use: 'M' });
|
|
314
|
+
model.registerFlow('D', {
|
|
315
|
+
on: { eventName: 'go', phase: 'afterStep', flowKey: 'S', stepKey: 'a' },
|
|
316
|
+
steps: {
|
|
317
|
+
d: { handler: async () => void calls.push('dynamic') } as any,
|
|
318
|
+
},
|
|
319
|
+
});
|
|
320
|
+
|
|
321
|
+
await model.dispatchEvent('go');
|
|
322
|
+
expect(calls).toEqual(['static-a']);
|
|
323
|
+
});
|
|
324
|
+
|
|
220
325
|
test("phase='beforeFlow': ctx.exitAll() stops anchor flow and subsequent flows", async () => {
|
|
221
326
|
const engine = new FlowEngine();
|
|
222
327
|
class M extends FlowModel {}
|
|
@@ -430,6 +535,115 @@ describe('dispatchEvent dynamic event flow phase (scheduleModelOperation integra
|
|
|
430
535
|
expect(calls).toEqual(['static-a', 'dynamic']);
|
|
431
536
|
});
|
|
432
537
|
|
|
538
|
+
test('fallback to event:end (missing anchor) skips when event aborted by ctx.exitAll()', async () => {
|
|
539
|
+
const engine = new FlowEngine();
|
|
540
|
+
class M extends FlowModel {}
|
|
541
|
+
engine.registerModels({ M });
|
|
542
|
+
|
|
543
|
+
const calls: string[] = [];
|
|
544
|
+
|
|
545
|
+
M.registerFlow({
|
|
546
|
+
key: 'S',
|
|
547
|
+
on: { eventName: 'go' },
|
|
548
|
+
steps: {
|
|
549
|
+
a: { handler: async () => void calls.push('static-a') } as any,
|
|
550
|
+
},
|
|
551
|
+
});
|
|
552
|
+
|
|
553
|
+
const model = engine.createModel({ use: 'M' });
|
|
554
|
+
model.registerFlow('Abort', {
|
|
555
|
+
on: { eventName: 'go' },
|
|
556
|
+
sort: -10,
|
|
557
|
+
steps: {
|
|
558
|
+
d: {
|
|
559
|
+
handler: async (ctx: any) => {
|
|
560
|
+
calls.push('abort');
|
|
561
|
+
ctx.exitAll();
|
|
562
|
+
},
|
|
563
|
+
} as any,
|
|
564
|
+
},
|
|
565
|
+
});
|
|
566
|
+
model.registerFlow('FallbackToEnd', {
|
|
567
|
+
on: { eventName: 'go', phase: 'beforeFlow', flowKey: 'missing' },
|
|
568
|
+
steps: {
|
|
569
|
+
d: { handler: async () => void calls.push('fallback-end') } as any,
|
|
570
|
+
},
|
|
571
|
+
});
|
|
572
|
+
|
|
573
|
+
await model.dispatchEvent('go');
|
|
574
|
+
expect(calls).toEqual(['abort']);
|
|
575
|
+
});
|
|
576
|
+
|
|
577
|
+
test('event:end is still emitted with aborted=true when exitAll happens', async () => {
|
|
578
|
+
const engine = new FlowEngine();
|
|
579
|
+
class M extends FlowModel {}
|
|
580
|
+
engine.registerModels({ M });
|
|
581
|
+
|
|
582
|
+
const endEvents: any[] = [];
|
|
583
|
+
const onEnd = (payload: any) => {
|
|
584
|
+
endEvents.push(payload);
|
|
585
|
+
};
|
|
586
|
+
engine.emitter.on('model:event:go:end', onEnd);
|
|
587
|
+
|
|
588
|
+
const model = engine.createModel({ use: 'M' });
|
|
589
|
+
model.registerFlow('Abort', {
|
|
590
|
+
on: { eventName: 'go' },
|
|
591
|
+
steps: {
|
|
592
|
+
d: {
|
|
593
|
+
handler: async (ctx: any) => {
|
|
594
|
+
ctx.exitAll();
|
|
595
|
+
},
|
|
596
|
+
} as any,
|
|
597
|
+
},
|
|
598
|
+
});
|
|
599
|
+
|
|
600
|
+
await model.dispatchEvent('go');
|
|
601
|
+
engine.emitter.off('model:event:go:end', onEnd);
|
|
602
|
+
|
|
603
|
+
expect(endEvents).toHaveLength(1);
|
|
604
|
+
expect(endEvents[0]?.aborted).toBe(true);
|
|
605
|
+
});
|
|
606
|
+
|
|
607
|
+
test('flow:end/step:end are emitted with aborted=true when exitAll happens', async () => {
|
|
608
|
+
const engine = new FlowEngine();
|
|
609
|
+
class M extends FlowModel {}
|
|
610
|
+
engine.registerModels({ M });
|
|
611
|
+
|
|
612
|
+
const flowEndEvents: any[] = [];
|
|
613
|
+
const stepEndEvents: any[] = [];
|
|
614
|
+
const onFlowEnd = (payload: any) => {
|
|
615
|
+
flowEndEvents.push(payload);
|
|
616
|
+
};
|
|
617
|
+
const onStepEnd = (payload: any) => {
|
|
618
|
+
stepEndEvents.push(payload);
|
|
619
|
+
};
|
|
620
|
+
engine.emitter.on('model:event:go:flow:S:end', onFlowEnd);
|
|
621
|
+
engine.emitter.on('model:event:go:flow:S:step:a:end', onStepEnd);
|
|
622
|
+
|
|
623
|
+
M.registerFlow({
|
|
624
|
+
key: 'S',
|
|
625
|
+
on: { eventName: 'go' },
|
|
626
|
+
steps: {
|
|
627
|
+
a: {
|
|
628
|
+
handler: async (ctx: any) => {
|
|
629
|
+
ctx.exitAll();
|
|
630
|
+
},
|
|
631
|
+
} as any,
|
|
632
|
+
},
|
|
633
|
+
});
|
|
634
|
+
|
|
635
|
+
const model = engine.createModel({ use: 'M' });
|
|
636
|
+
await model.dispatchEvent('go');
|
|
637
|
+
|
|
638
|
+
engine.emitter.off('model:event:go:flow:S:end', onFlowEnd);
|
|
639
|
+
engine.emitter.off('model:event:go:flow:S:step:a:end', onStepEnd);
|
|
640
|
+
|
|
641
|
+
expect(flowEndEvents).toHaveLength(1);
|
|
642
|
+
expect(stepEndEvents).toHaveLength(1);
|
|
643
|
+
expect(flowEndEvents[0]?.aborted).toBe(true);
|
|
644
|
+
expect(stepEndEvents[0]?.aborted).toBe(true);
|
|
645
|
+
});
|
|
646
|
+
|
|
433
647
|
test('multiple flows on same anchor: executes by flow.sort asc (stable)', async () => {
|
|
434
648
|
const engine = new FlowEngine();
|
|
435
649
|
class M extends FlowModel {}
|
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
// 为避免在模块初始化阶段引入 FlowContext(从而触发循环依赖),不要在顶层导入各类 RunJSContext。
|
|
11
11
|
// 在需要默认映射时(首次 resolve)再使用 createRequire 同步加载对应模块。
|
|
12
12
|
|
|
13
|
-
export type RunJSVersion = 'v1' | (string & {});
|
|
13
|
+
export type RunJSVersion = 'v1' | 'v2' | (string & {});
|
|
14
14
|
export type RunJSContextCtor = new (delegate: any) => any;
|
|
15
15
|
export type RunJSContextMeta = {
|
|
16
16
|
scenes?: string[];
|
|
@@ -41,17 +41,26 @@ export async function setupRunJSContexts() {
|
|
|
41
41
|
import('./contexts/JSCollectionActionRunJSContext'),
|
|
42
42
|
]);
|
|
43
43
|
|
|
44
|
-
const
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
44
|
+
const registerBuiltins = (version: 'v1' | 'v2') => {
|
|
45
|
+
RunJSContextRegistry.register(version, '*', FlowRunJSContext);
|
|
46
|
+
RunJSContextRegistry.register(version, 'JSBlockModel', JSBlockRunJSContext, { scenes: ['block'] });
|
|
47
|
+
RunJSContextRegistry.register(version, 'JSFieldModel', JSFieldRunJSContext, { scenes: ['detail'] });
|
|
48
|
+
RunJSContextRegistry.register(version, 'JSEditableFieldModel', JSEditableFieldRunJSContext, { scenes: ['form'] });
|
|
49
|
+
RunJSContextRegistry.register(version, 'JSItemModel', JSItemRunJSContext, { scenes: ['form'] });
|
|
50
|
+
RunJSContextRegistry.register(version, 'JSColumnModel', JSColumnRunJSContext, { scenes: ['table'] });
|
|
51
|
+
RunJSContextRegistry.register(version, 'FormJSFieldItemModel', FormJSFieldItemRunJSContext, { scenes: ['form'] });
|
|
52
|
+
RunJSContextRegistry.register(version, 'JSRecordActionModel', JSRecordActionRunJSContext, { scenes: ['table'] });
|
|
53
|
+
RunJSContextRegistry.register(version, 'JSCollectionActionModel', JSCollectionActionRunJSContext, {
|
|
54
|
+
scenes: ['table'],
|
|
55
|
+
});
|
|
56
|
+
};
|
|
57
|
+
|
|
58
|
+
const versions: Array<'v1' | 'v2'> = ['v1', 'v2'];
|
|
59
|
+
for (const version of versions) {
|
|
60
|
+
registerBuiltins(version);
|
|
61
|
+
await applyRunJSContextContributions(version);
|
|
62
|
+
markRunJSContextsSetupDone(version);
|
|
63
|
+
}
|
|
64
|
+
|
|
55
65
|
done = true;
|
|
56
|
-
markRunJSContextsSetupDone(v1);
|
|
57
66
|
}
|
|
@@ -21,7 +21,11 @@ type LifecycleType =
|
|
|
21
21
|
| `event:${string}:end`
|
|
22
22
|
| `event:${string}:error`;
|
|
23
23
|
|
|
24
|
-
|
|
24
|
+
type EventPredicateWhen = ((e: LifecycleEvent) => boolean) & {
|
|
25
|
+
__eventType?: string;
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
export type ScheduleWhen = LifecycleType | EventPredicateWhen;
|
|
25
29
|
|
|
26
30
|
export interface ScheduleOptions {
|
|
27
31
|
when?: ScheduleWhen;
|
|
@@ -37,6 +41,7 @@ export interface LifecycleEvent {
|
|
|
37
41
|
error?: any;
|
|
38
42
|
inputArgs?: Record<string, any>;
|
|
39
43
|
result?: any;
|
|
44
|
+
aborted?: boolean;
|
|
40
45
|
flowKey?: string;
|
|
41
46
|
stepKey?: string;
|
|
42
47
|
}
|
|
@@ -216,8 +221,14 @@ export class ModelOperationScheduler {
|
|
|
216
221
|
}
|
|
217
222
|
|
|
218
223
|
private ensureEventSubscriptionIfNeeded(when?: ScheduleWhen) {
|
|
219
|
-
|
|
220
|
-
|
|
224
|
+
const eventType =
|
|
225
|
+
typeof when === 'string'
|
|
226
|
+
? when
|
|
227
|
+
: typeof when === 'function'
|
|
228
|
+
? (when as EventPredicateWhen).__eventType
|
|
229
|
+
: undefined;
|
|
230
|
+
if (!eventType) return;
|
|
231
|
+
const parsed = this.parseEventWhen(eventType as ScheduleWhen);
|
|
221
232
|
if (!parsed) return;
|
|
222
233
|
const { name } = parsed;
|
|
223
234
|
if (this.subscribedEventNames.has(name)) return;
|
|
@@ -109,6 +109,13 @@ describe('parsePathnameToViewParams', () => {
|
|
|
109
109
|
expect(result).toEqual([{ viewUid: 'xxx', filterByTk: { id: '1', tenant: 'ac' } }]);
|
|
110
110
|
});
|
|
111
111
|
|
|
112
|
+
test('should parse filterByTk from single key-value encoded segment into object', () => {
|
|
113
|
+
const kv = encodeURIComponent('id=1');
|
|
114
|
+
const path = `/admin/xxx/filterbytk/${kv}`;
|
|
115
|
+
const result = parsePathnameToViewParams(path);
|
|
116
|
+
expect(result).toEqual([{ viewUid: 'xxx', filterByTk: { id: '1' } }]);
|
|
117
|
+
});
|
|
118
|
+
|
|
112
119
|
test('should parse filterByTk from JSON object segment', () => {
|
|
113
120
|
const json = encodeURIComponent('{"id":"1","tenant":"ac"}');
|
|
114
121
|
const path = `/admin/xxx/filterbytk/${json}`;
|
|
@@ -116,8 +116,8 @@ export const parsePathnameToViewParams = (pathname: string): ViewParam[] => {
|
|
|
116
116
|
// 解析失败,按字符串保留
|
|
117
117
|
parsed = decoded;
|
|
118
118
|
}
|
|
119
|
-
} else if (decoded &&
|
|
120
|
-
// 形如 a=b&c=d 的整体段
|
|
119
|
+
} else if (decoded && /^[^=&]+=[^=&]*(?:&[^=&]+=[^=&]*)*$/.test(decoded)) {
|
|
120
|
+
// 形如 a=b 或 a=b&c=d 的整体段
|
|
121
121
|
parsed = parseKeyValuePairs(decoded);
|
|
122
122
|
}
|
|
123
123
|
currentView.filterByTk = parsed;
|
|
@@ -26,6 +26,7 @@ vi.mock('../../ViewScopedFlowEngine', () => ({
|
|
|
26
26
|
createViewScopedEngine: (engine) => ({
|
|
27
27
|
context: new FlowContext(),
|
|
28
28
|
unlinkFromStack: vi.fn(),
|
|
29
|
+
setDestroyView: vi.fn(),
|
|
29
30
|
// mimic real view stack linkage: previousEngine points to the last engine in chain
|
|
30
31
|
previousEngine: (engine as any)?.nextEngine || engine,
|
|
31
32
|
}),
|
package/src/views/useDialog.tsx
CHANGED
|
@@ -89,12 +89,17 @@ export function useDialog() {
|
|
|
89
89
|
ctx.addDelegate(flowContext.engine.context);
|
|
90
90
|
}
|
|
91
91
|
|
|
92
|
+
// 幂等保护:防止 FlowPage 路由清理时二次调用 destroy
|
|
93
|
+
let destroyed = false;
|
|
94
|
+
|
|
92
95
|
// 构造 currentDialog 实例
|
|
93
96
|
const currentDialog = {
|
|
94
97
|
type: 'dialog' as const,
|
|
95
98
|
inputArgs: config.inputArgs || {},
|
|
96
99
|
preventClose: !!config.preventClose,
|
|
97
100
|
destroy: (result?: any) => {
|
|
101
|
+
if (destroyed) return;
|
|
102
|
+
destroyed = true;
|
|
98
103
|
config.onClose?.();
|
|
99
104
|
dialogRef.current?.destroy();
|
|
100
105
|
closeFunc?.();
|
|
@@ -140,6 +145,15 @@ export function useDialog() {
|
|
|
140
145
|
get: () => currentDialog,
|
|
141
146
|
resolveOnServer: createViewRecordResolveOnServer(ctx, () => getViewRecordFromParent(flowContext, ctx)),
|
|
142
147
|
});
|
|
148
|
+
// 注册视图销毁回调,供外部(如 afterSuccess)通过引擎栈遍历来关闭多层弹窗。
|
|
149
|
+
// 对路由触发的弹窗:先 navigation.back() 清理 URL(replace 方式),再 destroy() 立即移除元素;
|
|
150
|
+
// 对非路由弹窗:直接 destroy()。destroy() 已做幂等保护,FlowPage 后续清理不会重复执行。
|
|
151
|
+
scopedEngine.setDestroyView(() => {
|
|
152
|
+
if (config.triggerByRouter && config.inputArgs?.navigation?.back) {
|
|
153
|
+
config.inputArgs.navigation.back();
|
|
154
|
+
}
|
|
155
|
+
currentDialog.destroy();
|
|
156
|
+
});
|
|
143
157
|
// 顶层 popup 变量:弹窗记录/数据源/上级弹窗链(去重封装)
|
|
144
158
|
registerPopupVariable(ctx, currentDialog);
|
|
145
159
|
// 内部组件,在 Provider 内部计算 content
|
package/src/views/useDrawer.tsx
CHANGED
|
@@ -118,12 +118,17 @@ export function useDrawer() {
|
|
|
118
118
|
ctx.addDelegate(flowContext.engine.context);
|
|
119
119
|
}
|
|
120
120
|
|
|
121
|
+
// 幂等保护:防止 FlowPage 路由清理时二次调用 destroy
|
|
122
|
+
let destroyed = false;
|
|
123
|
+
|
|
121
124
|
// 构造 currentDrawer 实例
|
|
122
125
|
const currentDrawer = {
|
|
123
126
|
type: 'drawer' as const,
|
|
124
127
|
inputArgs: config.inputArgs || {},
|
|
125
128
|
preventClose: !!config.preventClose,
|
|
126
129
|
destroy: (result?: any) => {
|
|
130
|
+
if (destroyed) return;
|
|
131
|
+
destroyed = true;
|
|
127
132
|
config.onClose?.();
|
|
128
133
|
drawerRef.current?.destroy();
|
|
129
134
|
closeFunc?.();
|
|
@@ -169,6 +174,15 @@ export function useDrawer() {
|
|
|
169
174
|
get: () => currentDrawer,
|
|
170
175
|
resolveOnServer: createViewRecordResolveOnServer(ctx, () => getViewRecordFromParent(flowContext, ctx)),
|
|
171
176
|
});
|
|
177
|
+
// 注册视图销毁回调,供外部(如 afterSuccess)通过引擎栈遍历来关闭多层弹窗。
|
|
178
|
+
// 对路由触发的弹窗:先 navigation.back() 清理 URL(replace 方式),再 destroy() 立即移除元素;
|
|
179
|
+
// 对非路由弹窗:直接 destroy()。destroy() 已做幂等保护,FlowPage 后续清理不会重复执行。
|
|
180
|
+
scopedEngine.setDestroyView(() => {
|
|
181
|
+
if (config.triggerByRouter && config.inputArgs?.navigation?.back) {
|
|
182
|
+
config.inputArgs.navigation.back();
|
|
183
|
+
}
|
|
184
|
+
currentDrawer.destroy();
|
|
185
|
+
});
|
|
172
186
|
// 顶层 popup 变量:弹窗记录/数据源/上级弹窗链(去重封装)
|
|
173
187
|
registerPopupVariable(ctx, currentDrawer);
|
|
174
188
|
|
package/src/views/usePage.tsx
CHANGED
|
@@ -178,6 +178,7 @@ export function usePage() {
|
|
|
178
178
|
// 仅当访问关联字段或前端无本地记录数据时,才交给服务端解析
|
|
179
179
|
resolveOnServer: createViewRecordResolveOnServer(ctx, () => getViewRecordFromParent(flowContext, ctx)),
|
|
180
180
|
});
|
|
181
|
+
// embed 视图不注册 destroyView,afterSuccess 关闭弹窗时自然跳过
|
|
181
182
|
// 顶层 popup 变量:弹窗记录/数据源/上级弹窗链(去重封装)
|
|
182
183
|
registerPopupVariable(ctx, currentPage);
|
|
183
184
|
|