@nocobase/flow-engine 2.1.0-alpha.40 → 2.1.0-alpha.45
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/FlowContextProvider.d.ts +5 -1
- package/lib/FlowContextProvider.js +9 -2
- package/lib/components/settings/wrappers/contextual/DefaultSettingsIcon.js +8 -1
- package/lib/components/subModel/LazyDropdown.js +200 -16
- package/lib/data-source/index.d.ts +9 -0
- package/lib/data-source/index.js +12 -0
- package/lib/flowContext.js +3 -0
- package/lib/flowEngine.js +3 -3
- package/lib/models/flowModel.js +3 -3
- package/lib/utils/parsePathnameToViewParams.d.ts +5 -1
- package/lib/utils/parsePathnameToViewParams.js +28 -4
- package/lib/views/ViewNavigation.d.ts +12 -2
- package/lib/views/ViewNavigation.js +22 -7
- package/lib/views/createViewMeta.js +114 -50
- package/lib/views/inheritLayoutContext.d.ts +10 -0
- package/lib/views/inheritLayoutContext.js +50 -0
- package/lib/views/useDialog.js +2 -0
- package/lib/views/useDrawer.js +2 -0
- package/lib/views/usePage.js +2 -0
- package/package.json +4 -4
- package/src/FlowContextProvider.tsx +9 -1
- package/src/__tests__/createViewMeta.popup.test.ts +115 -1
- package/src/__tests__/flowEngine.removeModel.test.ts +47 -3
- package/src/components/settings/wrappers/contextual/DefaultSettingsIcon.tsx +11 -1
- package/src/components/settings/wrappers/contextual/__tests__/DefaultSettingsIcon.test.tsx +5 -2
- package/src/components/subModel/LazyDropdown.tsx +228 -16
- package/src/components/subModel/__tests__/AddSubModelButton.test.tsx +203 -1
- package/src/data-source/index.ts +18 -0
- package/src/executor/__tests__/flowExecutor.test.ts +28 -0
- package/src/flowContext.ts +3 -0
- package/src/flowEngine.ts +4 -3
- package/src/models/__tests__/flowEngine.resolveUse.test.ts +0 -15
- package/src/models/__tests__/flowModel.test.ts +33 -34
- package/src/models/flowModel.tsx +3 -3
- package/src/utils/__tests__/parsePathnameToViewParams.test.ts +21 -0
- package/src/utils/parsePathnameToViewParams.ts +45 -5
- package/src/views/ViewNavigation.ts +40 -7
- package/src/views/__tests__/ViewNavigation.test.ts +52 -0
- package/src/views/__tests__/inheritLayoutContext.test.ts +53 -0
- package/src/views/createViewMeta.ts +106 -34
- package/src/views/inheritLayoutContext.ts +26 -0
- package/src/views/useDialog.tsx +2 -0
- package/src/views/useDrawer.tsx +2 -0
- package/src/views/usePage.tsx +2 -0
|
@@ -13,6 +13,16 @@ import { ViewParam as SharedViewParam } from '../utils';
|
|
|
13
13
|
|
|
14
14
|
type ViewParams = Omit<SharedViewParam, 'viewUid'> & { viewUid?: string };
|
|
15
15
|
|
|
16
|
+
export interface GeneratePathnameFromViewParamsOptions {
|
|
17
|
+
prefix?: string;
|
|
18
|
+
basePath?: string;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export interface ViewNavigationOptions {
|
|
22
|
+
basePath?: string;
|
|
23
|
+
layoutBasePath?: string;
|
|
24
|
+
}
|
|
25
|
+
|
|
16
26
|
function encodeFilterByTk(val: SharedViewParam['filterByTk']): string {
|
|
17
27
|
if (val === undefined || val === null) return '';
|
|
18
28
|
// 1.x 兼容:对象按 key1=v1&key2=v2 拼接后整体 encodeURIComponent
|
|
@@ -30,6 +40,11 @@ function hasUsableSourceId(sourceId: unknown): sourceId is string | number {
|
|
|
30
40
|
return sourceId !== undefined && sourceId !== null && String(sourceId) !== '';
|
|
31
41
|
}
|
|
32
42
|
|
|
43
|
+
function normalizeBasePath(basePath?: string) {
|
|
44
|
+
const value = basePath || '/admin';
|
|
45
|
+
return `/${value.replace(/^\/+/, '').replace(/\/+$/, '')}`;
|
|
46
|
+
}
|
|
47
|
+
|
|
33
48
|
/**
|
|
34
49
|
* 将 ViewParam 数组转换为 pathname
|
|
35
50
|
*
|
|
@@ -43,12 +58,17 @@ function hasUsableSourceId(sourceId: unknown): sourceId is string | number {
|
|
|
43
58
|
* generatePathnameFromViewParams([{ viewUid: 'xxx' }, { viewUid: 'yyy' }]) // '/admin/xxx/view/yyy'
|
|
44
59
|
* ```
|
|
45
60
|
*/
|
|
46
|
-
export function generatePathnameFromViewParams(
|
|
61
|
+
export function generatePathnameFromViewParams(
|
|
62
|
+
viewParams: ViewParams[],
|
|
63
|
+
options: GeneratePathnameFromViewParamsOptions = {},
|
|
64
|
+
): string {
|
|
65
|
+
const basePath = normalizeBasePath(options.basePath || options.prefix);
|
|
66
|
+
|
|
47
67
|
if (!viewParams || viewParams.length === 0) {
|
|
48
|
-
return
|
|
68
|
+
return basePath;
|
|
49
69
|
}
|
|
50
70
|
|
|
51
|
-
const segments =
|
|
71
|
+
const segments = basePath.replace(/^\/+/, '').split('/').filter(Boolean);
|
|
52
72
|
|
|
53
73
|
viewParams.forEach((viewParam, index) => {
|
|
54
74
|
// 如果不是第一个视图,添加 'view' 关键字
|
|
@@ -81,10 +101,12 @@ export class ViewNavigation {
|
|
|
81
101
|
viewStack: ReadonlyArray<ViewParams>; // 只能通过 setViewStack 修改
|
|
82
102
|
ctx: FlowEngineContext;
|
|
83
103
|
viewParams: ViewParams;
|
|
104
|
+
private readonly basePath?: string;
|
|
84
105
|
|
|
85
|
-
constructor(ctx: FlowEngineContext, viewParams: ViewParams[]) {
|
|
106
|
+
constructor(ctx: FlowEngineContext, viewParams: ViewParams[], options: ViewNavigationOptions = {}) {
|
|
86
107
|
this.setViewStack(viewParams);
|
|
87
108
|
this.ctx = ctx;
|
|
109
|
+
this.basePath = options.basePath || options.layoutBasePath;
|
|
88
110
|
|
|
89
111
|
define(this, {
|
|
90
112
|
viewParams: observable,
|
|
@@ -106,7 +128,7 @@ export class ViewNavigation {
|
|
|
106
128
|
});
|
|
107
129
|
|
|
108
130
|
// 2. 根据 viewStack 生成新的 pathname
|
|
109
|
-
const newPathname = generatePathnameFromViewParams(newViewStack);
|
|
131
|
+
const newPathname = generatePathnameFromViewParams(newViewStack, { basePath: this.getLayoutBasePath() });
|
|
110
132
|
|
|
111
133
|
// 3. 触发一次跳转。使用 replace 的方式
|
|
112
134
|
this.ctx.router.navigate(newPathname, { replace: true });
|
|
@@ -115,7 +137,9 @@ export class ViewNavigation {
|
|
|
115
137
|
navigateTo(viewParam: ViewParams, opts?: { replace?: boolean; state?: any }) {
|
|
116
138
|
// 1. 基于当前 viewStack 生成一个 pathname
|
|
117
139
|
// 2. 将当前传入的参数转为 path string
|
|
118
|
-
const newViewPathname = generatePathnameFromViewParams([...this.viewStack, viewParam]
|
|
140
|
+
const newViewPathname = generatePathnameFromViewParams([...this.viewStack, viewParam], {
|
|
141
|
+
basePath: this.getLayoutBasePath(),
|
|
142
|
+
});
|
|
119
143
|
|
|
120
144
|
// 3. 与 pathname 拼接成新的 pathname(这里直接使用新生成的 pathname)
|
|
121
145
|
const newPathname = newViewPathname;
|
|
@@ -126,7 +150,16 @@ export class ViewNavigation {
|
|
|
126
150
|
|
|
127
151
|
back() {
|
|
128
152
|
const prevStack = this.viewStack.slice(0, -1);
|
|
129
|
-
const prevPath = generatePathnameFromViewParams(prevStack);
|
|
153
|
+
const prevPath = generatePathnameFromViewParams(prevStack, { basePath: this.getLayoutBasePath() });
|
|
130
154
|
this.ctx.router.navigate(prevPath, { replace: true });
|
|
131
155
|
}
|
|
156
|
+
|
|
157
|
+
private getLayoutBasePath() {
|
|
158
|
+
const routePath = (this.ctx as any).layout?.routePath;
|
|
159
|
+
return (
|
|
160
|
+
this.basePath ||
|
|
161
|
+
(this.ctx as any).layoutRoute?.basePathname ||
|
|
162
|
+
(routePath?.startsWith('/') ? routePath : '/admin')
|
|
163
|
+
);
|
|
164
|
+
}
|
|
132
165
|
}
|
|
@@ -146,6 +146,47 @@ describe('ViewNavigation', () => {
|
|
|
146
146
|
|
|
147
147
|
expect(mockCtx.router.navigate).toHaveBeenCalledWith('/admin', { replace: true });
|
|
148
148
|
});
|
|
149
|
+
|
|
150
|
+
it('should use explicit basePath when navigating back', () => {
|
|
151
|
+
viewNavigation = new ViewNavigation(mockCtx, [{ viewUid: 'view1' }], { basePath: '/embed' });
|
|
152
|
+
|
|
153
|
+
viewNavigation.back();
|
|
154
|
+
|
|
155
|
+
expect(mockCtx.router.navigate).toHaveBeenCalledWith('/embed', { replace: true });
|
|
156
|
+
});
|
|
157
|
+
|
|
158
|
+
it('should use layout route basePathname when explicit basePath is absent', () => {
|
|
159
|
+
mockCtx.layoutRoute = {
|
|
160
|
+
basePathname: '/mobile',
|
|
161
|
+
};
|
|
162
|
+
viewNavigation = new ViewNavigation(mockCtx, [{ viewUid: 'view1' }]);
|
|
163
|
+
|
|
164
|
+
viewNavigation.back();
|
|
165
|
+
|
|
166
|
+
expect(mockCtx.router.navigate).toHaveBeenCalledWith('/mobile', { replace: true });
|
|
167
|
+
});
|
|
168
|
+
|
|
169
|
+
it('should fall back to layout routePath when explicit basePath is absent', () => {
|
|
170
|
+
mockCtx.layout = {
|
|
171
|
+
routePath: '/mobile',
|
|
172
|
+
};
|
|
173
|
+
viewNavigation = new ViewNavigation(mockCtx, [{ viewUid: 'view1' }]);
|
|
174
|
+
|
|
175
|
+
viewNavigation.back();
|
|
176
|
+
|
|
177
|
+
expect(mockCtx.router.navigate).toHaveBeenCalledWith('/mobile', { replace: true });
|
|
178
|
+
});
|
|
179
|
+
|
|
180
|
+
it('should ignore relative layout routePath when runtime basePathname is absent', () => {
|
|
181
|
+
mockCtx.layout = {
|
|
182
|
+
routePath: 'public-forms',
|
|
183
|
+
};
|
|
184
|
+
viewNavigation = new ViewNavigation(mockCtx, [{ viewUid: 'view1' }]);
|
|
185
|
+
|
|
186
|
+
viewNavigation.back();
|
|
187
|
+
|
|
188
|
+
expect(mockCtx.router.navigate).toHaveBeenCalledWith('/admin', { replace: true });
|
|
189
|
+
});
|
|
149
190
|
});
|
|
150
191
|
});
|
|
151
192
|
|
|
@@ -160,6 +201,17 @@ describe('generatePathnameFromViewParams', () => {
|
|
|
160
201
|
expect(generatePathnameFromViewParams([{ viewUid: 'xxx' }])).toBe('/admin/xxx');
|
|
161
202
|
});
|
|
162
203
|
|
|
204
|
+
it('should generate path with custom prefix', () => {
|
|
205
|
+
expect(generatePathnameFromViewParams([{ viewUid: 'xxx' }], { basePath: '/embed' })).toBe('/embed/xxx');
|
|
206
|
+
expect(generatePathnameFromViewParams([], { basePath: '/embed' })).toBe('/embed');
|
|
207
|
+
});
|
|
208
|
+
|
|
209
|
+
it('should generate path with nested basePath', () => {
|
|
210
|
+
expect(generatePathnameFromViewParams([{ viewUid: 'xxx' }], { basePath: '/admin/settings/public-forms' })).toBe(
|
|
211
|
+
'/admin/settings/public-forms/xxx',
|
|
212
|
+
);
|
|
213
|
+
});
|
|
214
|
+
|
|
163
215
|
it('should generate view with tab', () => {
|
|
164
216
|
expect(generatePathnameFromViewParams([{ viewUid: 'xxx', tabUid: 'yyy' }])).toBe('/admin/xxx/tab/yyy');
|
|
165
217
|
});
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* This file is part of the NocoBase (R) project.
|
|
3
|
+
* Copyright (c) 2020-2024 NocoBase Co., Ltd.
|
|
4
|
+
* Authors: NocoBase Team.
|
|
5
|
+
*
|
|
6
|
+
* This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License.
|
|
7
|
+
* For more information, please refer to: https://www.nocobase.com/agreement.
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
import { describe, expect, it } from 'vitest';
|
|
11
|
+
import { FlowContext } from '../../flowContext';
|
|
12
|
+
import { inheritLayoutContextForDetachedView } from '../inheritLayoutContext';
|
|
13
|
+
|
|
14
|
+
describe('inheritLayoutContextForDetachedView', () => {
|
|
15
|
+
it('inherits layout context for detached view contexts', () => {
|
|
16
|
+
const sourceContext = new FlowContext();
|
|
17
|
+
const engineContext = new FlowContext();
|
|
18
|
+
const layoutContext = new FlowContext();
|
|
19
|
+
const viewContext = new FlowContext();
|
|
20
|
+
|
|
21
|
+
engineContext.defineProperty('skipAclCheck', { value: false });
|
|
22
|
+
layoutContext.defineProperty('skipAclCheck', { value: true });
|
|
23
|
+
sourceContext.defineProperty('engine', {
|
|
24
|
+
value: {
|
|
25
|
+
context: engineContext,
|
|
26
|
+
},
|
|
27
|
+
});
|
|
28
|
+
sourceContext.defineProperty('layoutContext', { value: layoutContext });
|
|
29
|
+
|
|
30
|
+
viewContext.addDelegate(engineContext);
|
|
31
|
+
inheritLayoutContextForDetachedView(viewContext, sourceContext);
|
|
32
|
+
|
|
33
|
+
expect(viewContext.skipAclCheck).toBe(true);
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
it('does nothing when source context has no layout context', () => {
|
|
37
|
+
const sourceContext = new FlowContext();
|
|
38
|
+
const engineContext = new FlowContext();
|
|
39
|
+
const viewContext = new FlowContext();
|
|
40
|
+
|
|
41
|
+
engineContext.defineProperty('skipAclCheck', { value: false });
|
|
42
|
+
sourceContext.defineProperty('engine', {
|
|
43
|
+
value: {
|
|
44
|
+
context: engineContext,
|
|
45
|
+
},
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
viewContext.addDelegate(engineContext);
|
|
49
|
+
inheritLayoutContextForDetachedView(viewContext, sourceContext);
|
|
50
|
+
|
|
51
|
+
expect(viewContext.skipAclCheck).toBe(false);
|
|
52
|
+
});
|
|
53
|
+
});
|
|
@@ -15,6 +15,82 @@ import type { FlowView } from './FlowView';
|
|
|
15
15
|
|
|
16
16
|
type PopupModelLike = { getStepParams?: (a: string, b: string) => any } | undefined;
|
|
17
17
|
|
|
18
|
+
function isDefined(value: any) {
|
|
19
|
+
return value !== undefined && value !== null;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
function isSameViewParamValue(left: any, right: any) {
|
|
23
|
+
if (left === right) return true;
|
|
24
|
+
if (!isDefined(left) || !isDefined(right)) return false;
|
|
25
|
+
|
|
26
|
+
try {
|
|
27
|
+
return JSON.stringify(left) === JSON.stringify(right);
|
|
28
|
+
} catch (_) {
|
|
29
|
+
return String(left) === String(right);
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
function getViewStack(view?: FlowView): any[] {
|
|
34
|
+
const stack = view?.navigation?.viewStack;
|
|
35
|
+
return Array.isArray(stack) ? stack : [];
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
function getAnchoredViewStackIndex(view?: FlowView, stack = getViewStack(view)): number {
|
|
39
|
+
if (!stack.length) return -1;
|
|
40
|
+
|
|
41
|
+
const args = view?.inputArgs || {};
|
|
42
|
+
const navParams = view?.navigation?.viewParams || {};
|
|
43
|
+
const viewUid = args.viewUid ?? navParams.viewUid;
|
|
44
|
+
|
|
45
|
+
if (!viewUid) {
|
|
46
|
+
return stack.length - 1;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
const candidates = stack.map((item, index) => ({ item, index })).filter(({ item }) => item?.viewUid === viewUid);
|
|
50
|
+
|
|
51
|
+
if (!candidates.length) {
|
|
52
|
+
return stack.length - 1;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
const keys = ['filterByTk', 'sourceId', 'tabUid'];
|
|
56
|
+
let bestIndex = candidates[candidates.length - 1].index;
|
|
57
|
+
let bestScore = -1;
|
|
58
|
+
|
|
59
|
+
for (const { item, index } of candidates) {
|
|
60
|
+
let score = 0;
|
|
61
|
+
let matched = true;
|
|
62
|
+
|
|
63
|
+
for (const key of keys) {
|
|
64
|
+
if (!isDefined(args[key])) continue;
|
|
65
|
+
if (!isSameViewParamValue(item?.[key], args[key])) {
|
|
66
|
+
matched = false;
|
|
67
|
+
break;
|
|
68
|
+
}
|
|
69
|
+
score += 1;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
if (!matched) continue;
|
|
73
|
+
if (score >= bestScore) {
|
|
74
|
+
bestIndex = index;
|
|
75
|
+
bestScore = score;
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
return bestIndex;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
function getPopupView(ctx: FlowContext, anchorView?: FlowView) {
|
|
83
|
+
return anchorView ?? ctx.view;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
function isPopupView(view?: FlowView): boolean {
|
|
87
|
+
if (!view) return false;
|
|
88
|
+
const stack = getViewStack(view);
|
|
89
|
+
const openerUids = view?.inputArgs?.openerUids;
|
|
90
|
+
const hasOpener = Array.isArray(openerUids) && openerUids.length > 0;
|
|
91
|
+
return getAnchoredViewStackIndex(view, stack) >= 1 || hasOpener;
|
|
92
|
+
}
|
|
93
|
+
|
|
18
94
|
// 判断是否为普通对象(Plain Object),避免对类实例/代理等进行深度遍历
|
|
19
95
|
function isPlainObject(val: any) {
|
|
20
96
|
if (val === null || typeof val !== 'object') return false;
|
|
@@ -79,19 +155,11 @@ function makeMetaFromValue(value: any, title?: string, seen?: WeakSet<any>): any
|
|
|
79
155
|
export function createPopupMeta(ctx: FlowContext, anchorView?: FlowView): PropertyMetaFactory {
|
|
80
156
|
const t = (k: string) => ctx.t(k);
|
|
81
157
|
|
|
82
|
-
const
|
|
83
|
-
if (!view) return false;
|
|
84
|
-
const stack = Array.isArray(view.navigation?.viewStack) ? view.navigation.viewStack : [];
|
|
85
|
-
const openerUids = view?.inputArgs?.openerUids;
|
|
86
|
-
const hasOpener = Array.isArray(openerUids) && openerUids.length > 0;
|
|
87
|
-
return stack.length >= 2 || hasOpener;
|
|
88
|
-
};
|
|
89
|
-
|
|
90
|
-
const hasPopupNow = (): boolean => isPopupView(anchorView ?? ctx.view);
|
|
158
|
+
const hasPopupNow = (flowCtx: FlowContext = ctx): boolean => isPopupView(getPopupView(flowCtx, anchorView));
|
|
91
159
|
|
|
92
160
|
// 统一解析锚定视图下的 RecordRef,避免在设置弹窗等二级视图中被误导
|
|
93
161
|
const resolveRecordRef = async (flowCtx: FlowContext): Promise<RecordRef | undefined> => {
|
|
94
|
-
const view = anchorView
|
|
162
|
+
const view = getPopupView(flowCtx, anchorView);
|
|
95
163
|
if (!view || !isPopupView(view)) return undefined;
|
|
96
164
|
|
|
97
165
|
const base = await buildPopupRuntime(flowCtx, view);
|
|
@@ -119,11 +187,12 @@ export function createPopupMeta(ctx: FlowContext, anchorView?: FlowView): Proper
|
|
|
119
187
|
const getParentRecordRef = async (level: number, flowCtx?: FlowContext): Promise<RecordRef | undefined> => {
|
|
120
188
|
try {
|
|
121
189
|
const useCtx = flowCtx || ctx;
|
|
122
|
-
const
|
|
123
|
-
const stack =
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
190
|
+
const view = getPopupView(useCtx, anchorView);
|
|
191
|
+
const stack = getViewStack(view);
|
|
192
|
+
const currentIndex = getAnchoredViewStackIndex(view, stack);
|
|
193
|
+
if (currentIndex < 1 || level < 1) return undefined;
|
|
194
|
+
const idx = currentIndex - level;
|
|
195
|
+
if (idx < 1) return undefined;
|
|
127
196
|
const parent = stack[idx];
|
|
128
197
|
if (!parent?.viewUid) return undefined;
|
|
129
198
|
|
|
@@ -156,9 +225,10 @@ export function createPopupMeta(ctx: FlowContext, anchorView?: FlowView): Proper
|
|
|
156
225
|
|
|
157
226
|
const hasParentNow = (level: number): boolean => {
|
|
158
227
|
try {
|
|
159
|
-
const
|
|
160
|
-
const stack =
|
|
161
|
-
|
|
228
|
+
const view = getPopupView(ctx, anchorView);
|
|
229
|
+
const stack = getViewStack(view);
|
|
230
|
+
const currentIndex = getAnchoredViewStackIndex(view, stack);
|
|
231
|
+
return currentIndex - level >= 1; // level=1 需要至少一个上级弹窗
|
|
162
232
|
} catch (_) {
|
|
163
233
|
return false;
|
|
164
234
|
}
|
|
@@ -231,9 +301,10 @@ export function createPopupMeta(ctx: FlowContext, anchorView?: FlowView): Proper
|
|
|
231
301
|
disabled: () => !hasPopupNow(),
|
|
232
302
|
hidden: () => !hasPopupNow(),
|
|
233
303
|
buildVariablesParams: async (c) => {
|
|
234
|
-
if (!hasPopupNow()) return undefined;
|
|
304
|
+
if (!hasPopupNow(c)) return undefined;
|
|
235
305
|
const ref = await resolveRecordRef(c);
|
|
236
|
-
const
|
|
306
|
+
const view = getPopupView(c, anchorView);
|
|
307
|
+
const inputArgs = view?.inputArgs;
|
|
237
308
|
type PopupVariableParams = {
|
|
238
309
|
record?: RecordRef;
|
|
239
310
|
sourceRecord?: RecordRef;
|
|
@@ -253,9 +324,9 @@ export function createPopupMeta(ctx: FlowContext, anchorView?: FlowView): Proper
|
|
|
253
324
|
|
|
254
325
|
// 构建 parent 链(用于服务端解析 ctx.popup.parent[.parent...].record.*)
|
|
255
326
|
try {
|
|
256
|
-
const
|
|
257
|
-
const
|
|
258
|
-
if (
|
|
327
|
+
const stack = getViewStack(view);
|
|
328
|
+
const currentIndex = getAnchoredViewStackIndex(view, stack);
|
|
329
|
+
if (currentIndex >= 2) {
|
|
259
330
|
let cur: Record<string, any> = params;
|
|
260
331
|
let level = 1;
|
|
261
332
|
let parentRef = await getParentRecordRef(level, c);
|
|
@@ -315,20 +386,21 @@ export function createPopupMeta(ctx: FlowContext, anchorView?: FlowView): Proper
|
|
|
315
386
|
}
|
|
316
387
|
// 当 view.inputArgs 带有 sourceId + associationName 时,提供“上级记录”变量(基于 sourceId 推断)
|
|
317
388
|
try {
|
|
318
|
-
const
|
|
389
|
+
const view = getPopupView(ctx, anchorView);
|
|
390
|
+
const inputArgs = view?.inputArgs;
|
|
319
391
|
const srcId = inputArgs?.sourceId;
|
|
320
392
|
let assoc: string | undefined = inputArgs?.associationName;
|
|
321
393
|
let dsKey: string = inputArgs?.dataSourceKey || 'main';
|
|
322
394
|
|
|
323
395
|
// 兜底:若 associationName 缺失或不含“.”,尝试从当前视图模型的 openView 参数推断
|
|
324
396
|
if (!assoc || typeof assoc !== 'string' || !assoc.includes('.')) {
|
|
325
|
-
const
|
|
326
|
-
const
|
|
327
|
-
const
|
|
328
|
-
if (
|
|
329
|
-
let model = ctx?.engine?.getModel(
|
|
397
|
+
const stack = getViewStack(view);
|
|
398
|
+
const currentIndex = getAnchoredViewStackIndex(view, stack);
|
|
399
|
+
const current = currentIndex >= 0 ? stack?.[currentIndex] : undefined;
|
|
400
|
+
if (current?.viewUid) {
|
|
401
|
+
let model = ctx?.engine?.getModel(current.viewUid, true) as PopupModelLike;
|
|
330
402
|
if (!model) {
|
|
331
|
-
model = (await ctx.engine.loadModel({ uid:
|
|
403
|
+
model = (await ctx.engine.loadModel({ uid: current.viewUid })) as PopupModelLike;
|
|
332
404
|
}
|
|
333
405
|
const p = model?.getStepParams?.('popupSettings', 'openView') || {};
|
|
334
406
|
assoc = p?.associationName || assoc;
|
|
@@ -406,12 +478,12 @@ interface PopupNode {
|
|
|
406
478
|
}
|
|
407
479
|
|
|
408
480
|
export async function buildPopupRuntime(ctx: FlowContext, view: FlowView): Promise<PopupNode | undefined> {
|
|
409
|
-
const
|
|
410
|
-
const
|
|
481
|
+
const stack = getViewStack(view);
|
|
482
|
+
const currentIndex = getAnchoredViewStackIndex(view, stack);
|
|
411
483
|
|
|
412
484
|
const openerUids = view?.inputArgs?.openerUids;
|
|
413
485
|
const hasOpener = Array.isArray(openerUids) && openerUids.length > 0;
|
|
414
|
-
const hasStackPopup =
|
|
486
|
+
const hasStackPopup = currentIndex >= 1;
|
|
415
487
|
const isPopup = hasStackPopup || hasOpener;
|
|
416
488
|
if (!isPopup) return undefined;
|
|
417
489
|
|
|
@@ -457,7 +529,7 @@ export async function buildPopupRuntime(ctx: FlowContext, view: FlowView): Promi
|
|
|
457
529
|
if (parentNode) node.parent = parentNode;
|
|
458
530
|
return node;
|
|
459
531
|
};
|
|
460
|
-
const currentNode = await buildNode(
|
|
532
|
+
const currentNode = await buildNode(currentIndex);
|
|
461
533
|
return currentNode;
|
|
462
534
|
}
|
|
463
535
|
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* This file is part of the NocoBase (R) project.
|
|
3
|
+
* Copyright (c) 2020-2024 NocoBase Co., Ltd.
|
|
4
|
+
* Authors: NocoBase Team.
|
|
5
|
+
*
|
|
6
|
+
* This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License.
|
|
7
|
+
* For more information, please refer to: https://www.nocobase.com/agreement.
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
import { FlowContext } from '../flowContext';
|
|
11
|
+
|
|
12
|
+
export function inheritLayoutContextForDetachedView(viewContext: FlowContext, sourceContext: FlowContext) {
|
|
13
|
+
const layoutContext = sourceContext?.layoutContext;
|
|
14
|
+
const engineContext = sourceContext?.engine?.context;
|
|
15
|
+
|
|
16
|
+
if (!(layoutContext instanceof FlowContext)) {
|
|
17
|
+
return;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
if (layoutContext === sourceContext || layoutContext === engineContext) {
|
|
21
|
+
return;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
// inheritContext=false 只隔离业务上下文,Layout 运行时上下文仍需要传给弹窗/嵌入视图。
|
|
25
|
+
viewContext.addDelegate(layoutContext);
|
|
26
|
+
}
|
package/src/views/useDialog.tsx
CHANGED
|
@@ -20,6 +20,7 @@ import { FlowEngineProvider } from '../provider';
|
|
|
20
20
|
import { createViewScopedEngine } from '../ViewScopedFlowEngine';
|
|
21
21
|
import { createViewRecordResolveOnServer, getViewRecordFromParent } from '../utils/variablesParams';
|
|
22
22
|
import { runViewBeforeClose } from './runViewBeforeClose';
|
|
23
|
+
import { inheritLayoutContextForDetachedView } from './inheritLayoutContext';
|
|
23
24
|
|
|
24
25
|
let uuid = 0;
|
|
25
26
|
|
|
@@ -88,6 +89,7 @@ export function useDialog() {
|
|
|
88
89
|
ctx.addDelegate(flowContext);
|
|
89
90
|
} else {
|
|
90
91
|
ctx.addDelegate(flowContext.engine.context);
|
|
92
|
+
inheritLayoutContextForDetachedView(ctx, flowContext);
|
|
91
93
|
}
|
|
92
94
|
|
|
93
95
|
// 幂等保护:防止 FlowPage 路由清理时二次调用 destroy
|
package/src/views/useDrawer.tsx
CHANGED
|
@@ -20,6 +20,7 @@ import { FlowEngineProvider } from '../provider';
|
|
|
20
20
|
import { createViewScopedEngine } from '../ViewScopedFlowEngine';
|
|
21
21
|
import { createViewRecordResolveOnServer, getViewRecordFromParent } from '../utils/variablesParams';
|
|
22
22
|
import { runViewBeforeClose } from './runViewBeforeClose';
|
|
23
|
+
import { inheritLayoutContextForDetachedView } from './inheritLayoutContext';
|
|
23
24
|
|
|
24
25
|
export function useDrawer() {
|
|
25
26
|
const holderRef = React.useRef(null);
|
|
@@ -117,6 +118,7 @@ export function useDrawer() {
|
|
|
117
118
|
ctx.addDelegate(flowContext);
|
|
118
119
|
} else {
|
|
119
120
|
ctx.addDelegate(flowContext.engine.context);
|
|
121
|
+
inheritLayoutContextForDetachedView(ctx, flowContext);
|
|
120
122
|
}
|
|
121
123
|
|
|
122
124
|
// 幂等保护:防止 FlowPage 路由清理时二次调用 destroy
|
package/src/views/usePage.tsx
CHANGED
|
@@ -20,6 +20,7 @@ import { FlowEngineProvider } from '../provider';
|
|
|
20
20
|
import { createViewScopedEngine } from '../ViewScopedFlowEngine';
|
|
21
21
|
import { createViewRecordResolveOnServer, getViewRecordFromParent } from '../utils/variablesParams';
|
|
22
22
|
import { runViewBeforeClose } from './runViewBeforeClose';
|
|
23
|
+
import { inheritLayoutContextForDetachedView } from './inheritLayoutContext';
|
|
23
24
|
|
|
24
25
|
let uuid = 0;
|
|
25
26
|
|
|
@@ -223,6 +224,7 @@ export function usePage() {
|
|
|
223
224
|
ctx.addDelegate(flowContext);
|
|
224
225
|
} else {
|
|
225
226
|
ctx.addDelegate(flowContext.engine.context);
|
|
227
|
+
inheritLayoutContextForDetachedView(ctx, flowContext);
|
|
226
228
|
}
|
|
227
229
|
|
|
228
230
|
// 构造 currentPage 实例
|