@nocobase/client-v2 2.1.0-beta.29 → 2.1.0-beta.30
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/es/flow/actions/index.d.ts +1 -1
- package/es/flow/actions/linkageRules.d.ts +2 -0
- package/es/flow/admin-shell/admin-layout/AdminLayoutMenuModels.d.ts +4 -0
- package/es/flow/admin-shell/admin-layout/AdminLayoutModel.d.ts +7 -0
- package/es/flow/admin-shell/admin-layout/resolveAdminRouteRuntimeTarget.d.ts +5 -0
- package/es/flow/models/fields/AssociationFieldModel/SubTableFieldModel/SubTableColumnModel.d.ts +3 -0
- package/es/index.mjs +78 -73
- package/lib/index.js +59 -54
- package/package.json +5 -5
- package/src/__tests__/nocobase-buildin-plugin-auth.test.tsx +67 -46
- package/src/__tests__/settings-center.test.tsx +30 -0
- package/src/flow/__tests__/FlowRoute.test.tsx +4 -5
- package/src/flow/actions/__tests__/actionLinkageRules.race.repro.test.ts +199 -0
- package/src/flow/actions/__tests__/linkageRules.formValueDrivenRefresh.test.ts +6 -1
- package/src/flow/actions/__tests__/linkageRules.menu.test.ts +90 -0
- package/src/flow/actions/index.ts +2 -0
- package/src/flow/actions/linkageRules.tsx +77 -23
- package/src/flow/actions/linkageRulesFormValueRefresh.ts +2 -8
- package/src/flow/admin-shell/admin-layout/AdminLayoutComponent.tsx +8 -1
- package/src/flow/admin-shell/admin-layout/AdminLayoutMenuModels.tsx +70 -12
- package/src/flow/admin-shell/admin-layout/AdminLayoutMenuUtils.tsx +26 -87
- package/src/flow/admin-shell/admin-layout/AdminLayoutModel.tsx +11 -0
- package/src/flow/admin-shell/admin-layout/AdminLayoutSlotModels.tsx +5 -1
- package/src/flow/admin-shell/admin-layout/__tests__/AdminLayoutMenuModels.test.ts +292 -31
- package/src/flow/admin-shell/admin-layout/resolveAdminRouteRuntimeTarget.test.ts +50 -12
- package/src/flow/admin-shell/admin-layout/resolveAdminRouteRuntimeTarget.ts +77 -56
- package/src/flow/components/AdminLayout.tsx +2 -2
- package/src/flow/components/FlowRoute.tsx +17 -4
- package/src/flow/models/fields/AssociationFieldModel/PopupSubTableFieldModel/PopupSubTableFieldModel.tsx +4 -0
- package/src/flow/models/fields/AssociationFieldModel/SubTableFieldModel/SubTableColumnModel.tsx +7 -0
- package/src/flow/models/fields/AssociationFieldModel/SubTableFieldModel/index.tsx +4 -1
- package/src/flow/system-settings/useSystemSettings.tsx +36 -1
|
@@ -8,15 +8,21 @@
|
|
|
8
8
|
*/
|
|
9
9
|
|
|
10
10
|
import type { BaseApplication } from '../../../BaseApplication';
|
|
11
|
-
import { convertV2AdminPathToLegacy } from '../../../authRedirect';
|
|
12
11
|
import { NocoBaseDesktopRouteType, type NocoBaseDesktopRoute } from '../../../flow-compat';
|
|
13
12
|
|
|
14
13
|
export type AdminRouteNavigationMode = 'spa' | 'document';
|
|
14
|
+
export type AdminRouteRuntimeTargetReason =
|
|
15
|
+
| 'ok'
|
|
16
|
+
| 'missingSchemaUid'
|
|
17
|
+
| 'unsupportedV2Runtime'
|
|
18
|
+
| 'emptyGroup'
|
|
19
|
+
| 'unsupportedRouteType';
|
|
15
20
|
|
|
16
21
|
export type AdminRouteRuntimeTarget = {
|
|
17
22
|
runtimePath: string | null;
|
|
18
23
|
navigationMode: AdminRouteNavigationMode;
|
|
19
24
|
isLegacy: boolean;
|
|
25
|
+
reason: AdminRouteRuntimeTargetReason;
|
|
20
26
|
};
|
|
21
27
|
|
|
22
28
|
const V2_PUBLIC_PATH_SUFFIX = '/v2/';
|
|
@@ -45,6 +51,7 @@ const EMPTY_TARGET: AdminRouteRuntimeTarget = {
|
|
|
45
51
|
runtimePath: null,
|
|
46
52
|
navigationMode: 'spa',
|
|
47
53
|
isLegacy: false,
|
|
54
|
+
reason: 'unsupportedRouteType',
|
|
48
55
|
};
|
|
49
56
|
|
|
50
57
|
function normalizeRootRelativePath(pathname: string) {
|
|
@@ -60,14 +67,8 @@ function normalizePublicPath(value = '/') {
|
|
|
60
67
|
return normalized.endsWith('/') ? normalized : `${normalized}/`;
|
|
61
68
|
}
|
|
62
69
|
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
*
|
|
66
|
-
* @param {ResolveAdminRouteRuntimeTargetOptions['app']} app 当前应用实例
|
|
67
|
-
* @returns {boolean} 是否启用 v2 到 v1 的经典页跳转
|
|
68
|
-
*/
|
|
69
|
-
function shouldUseLegacyDocumentNavigation(app: ResolveAdminRouteRuntimeTargetOptions['app']) {
|
|
70
|
-
return normalizePublicPath(app.getPublicPath()).endsWith(V2_PUBLIC_PATH_SUFFIX);
|
|
70
|
+
export function isV2AdminRuntime(app?: ResolveAdminRouteRuntimeTargetOptions['app']) {
|
|
71
|
+
return !!app?.getPublicPath && normalizePublicPath(app.getPublicPath()).endsWith(V2_PUBLIC_PATH_SUFFIX);
|
|
71
72
|
}
|
|
72
73
|
|
|
73
74
|
export function toRouterNavigationPath(pathname: string, basename?: string) {
|
|
@@ -114,12 +115,6 @@ function appendLocationState(pathname: string, location?: LocationLike) {
|
|
|
114
115
|
return `${pathname}${search}${hash}`;
|
|
115
116
|
}
|
|
116
117
|
|
|
117
|
-
function isSameOrDescendantPath(pathname: string, basePath: string) {
|
|
118
|
-
const normalizedPathname = normalizeRootRelativePath(pathname);
|
|
119
|
-
const normalizedBasePath = normalizeRootRelativePath(basePath);
|
|
120
|
-
return normalizedPathname === normalizedBasePath || normalizedPathname.startsWith(`${normalizedBasePath}/`);
|
|
121
|
-
}
|
|
122
|
-
|
|
123
118
|
function logInvalidTarget(
|
|
124
119
|
logger: ResolveAdminRouteRuntimeTargetOptions['log'],
|
|
125
120
|
reason: string,
|
|
@@ -134,6 +129,47 @@ function isSkippableRoute(route: NocoBaseDesktopRoute | undefined) {
|
|
|
134
129
|
);
|
|
135
130
|
}
|
|
136
131
|
|
|
132
|
+
export function isV2MenuRoute(route: NocoBaseDesktopRoute | undefined): boolean {
|
|
133
|
+
if (!route || route.hidden === true || route.hideInMenu === true) {
|
|
134
|
+
return false;
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
if (route.type === NocoBaseDesktopRouteType.flowPage || route.type === NocoBaseDesktopRouteType.link) {
|
|
138
|
+
return true;
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
if (route.type === NocoBaseDesktopRouteType.group) {
|
|
142
|
+
return Array.isArray(route.children) && route.children.some((child) => isV2MenuRoute(child));
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
return false;
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
export function findFirstV2LandingRoute(routes: NocoBaseDesktopRoute[] | undefined): NocoBaseDesktopRoute | undefined {
|
|
149
|
+
if (!Array.isArray(routes)) {
|
|
150
|
+
return undefined;
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
for (const route of routes) {
|
|
154
|
+
if (!route || route.hidden === true || route.hideInMenu === true || route.type === NocoBaseDesktopRouteType.tabs) {
|
|
155
|
+
continue;
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
if (route.type === NocoBaseDesktopRouteType.flowPage) {
|
|
159
|
+
return route;
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
if (route.type === NocoBaseDesktopRouteType.group) {
|
|
163
|
+
const nested = findFirstV2LandingRoute(route.children);
|
|
164
|
+
if (nested) {
|
|
165
|
+
return nested;
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
return undefined;
|
|
171
|
+
}
|
|
172
|
+
|
|
137
173
|
export function findFirstAccessiblePageRoute(
|
|
138
174
|
routes: NocoBaseDesktopRoute[] | undefined,
|
|
139
175
|
): NocoBaseDesktopRoute | undefined {
|
|
@@ -161,64 +197,44 @@ export function findFirstAccessiblePageRoute(
|
|
|
161
197
|
return undefined;
|
|
162
198
|
}
|
|
163
199
|
|
|
164
|
-
function resolvePageRuntimeTarget(
|
|
200
|
+
function resolvePageRuntimeTarget(
|
|
201
|
+
options: ResolveAdminRouteRuntimeTargetOptions,
|
|
202
|
+
route: NocoBaseDesktopRoute,
|
|
203
|
+
): AdminRouteRuntimeTarget {
|
|
165
204
|
const { app, preserveLocationState, location, log = console.warn } = options;
|
|
166
205
|
|
|
167
206
|
if (!route.schemaUid) {
|
|
168
207
|
logInvalidTarget(log, 'Missing schemaUid.', route);
|
|
169
|
-
return EMPTY_TARGET;
|
|
170
|
-
}
|
|
171
|
-
|
|
172
|
-
if (route.type === NocoBaseDesktopRouteType.flowPage) {
|
|
173
208
|
return {
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
isLegacy: false,
|
|
209
|
+
...EMPTY_TARGET,
|
|
210
|
+
reason: 'missingSchemaUid',
|
|
177
211
|
};
|
|
178
212
|
}
|
|
179
213
|
|
|
180
|
-
if (
|
|
214
|
+
if (route.type === NocoBaseDesktopRouteType.flowPage) {
|
|
181
215
|
return {
|
|
182
|
-
runtimePath:
|
|
183
|
-
preserveLocationState && location
|
|
184
|
-
? appendLocationState(getV2AdminPath(app, route.schemaUid), location)
|
|
185
|
-
: getV2AdminPath(app, route.schemaUid),
|
|
216
|
+
runtimePath: getV2AdminPath(app, route.schemaUid),
|
|
186
217
|
navigationMode: 'spa' as const,
|
|
187
218
|
isLegacy: false,
|
|
219
|
+
reason: 'ok' as const,
|
|
188
220
|
};
|
|
189
221
|
}
|
|
190
222
|
|
|
191
|
-
|
|
192
|
-
const legacyPath = convertV2AdminPathToLegacy(app, v2RuntimePath);
|
|
193
|
-
|
|
194
|
-
if (!legacyPath) {
|
|
195
|
-
logInvalidTarget(log, 'Failed to resolve legacy runtimePath.', route);
|
|
196
|
-
return EMPTY_TARGET;
|
|
197
|
-
}
|
|
198
|
-
|
|
199
|
-
if (preserveLocationState && location) {
|
|
200
|
-
if (isSameOrDescendantPath(location.pathname, v2RuntimePath)) {
|
|
201
|
-
const correctedCurrentPath = convertV2AdminPathToLegacy(app, location);
|
|
202
|
-
if (correctedCurrentPath) {
|
|
203
|
-
return {
|
|
204
|
-
runtimePath: correctedCurrentPath,
|
|
205
|
-
navigationMode: 'document' as const,
|
|
206
|
-
isLegacy: true,
|
|
207
|
-
};
|
|
208
|
-
}
|
|
209
|
-
}
|
|
210
|
-
|
|
223
|
+
if (isV2AdminRuntime(app)) {
|
|
211
224
|
return {
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
isLegacy: true,
|
|
225
|
+
...EMPTY_TARGET,
|
|
226
|
+
reason: 'unsupportedV2Runtime',
|
|
215
227
|
};
|
|
216
228
|
}
|
|
217
229
|
|
|
218
230
|
return {
|
|
219
|
-
runtimePath:
|
|
220
|
-
|
|
221
|
-
|
|
231
|
+
runtimePath:
|
|
232
|
+
preserveLocationState && location
|
|
233
|
+
? appendLocationState(getV2AdminPath(app, route.schemaUid), location)
|
|
234
|
+
: getV2AdminPath(app, route.schemaUid),
|
|
235
|
+
navigationMode: 'spa' as const,
|
|
236
|
+
isLegacy: false,
|
|
237
|
+
reason: 'ok' as const,
|
|
222
238
|
};
|
|
223
239
|
}
|
|
224
240
|
|
|
@@ -242,9 +258,14 @@ export function resolveAdminRouteRuntimeTarget(
|
|
|
242
258
|
}
|
|
243
259
|
|
|
244
260
|
if (route.type === NocoBaseDesktopRouteType.group) {
|
|
245
|
-
const firstAccessibleRoute =
|
|
261
|
+
const firstAccessibleRoute = isV2AdminRuntime(options.app)
|
|
262
|
+
? findFirstV2LandingRoute(route.children)
|
|
263
|
+
: findFirstAccessiblePageRoute(route.children);
|
|
246
264
|
if (!firstAccessibleRoute) {
|
|
247
|
-
return
|
|
265
|
+
return {
|
|
266
|
+
...EMPTY_TARGET,
|
|
267
|
+
reason: 'emptyGroup',
|
|
268
|
+
};
|
|
248
269
|
}
|
|
249
270
|
return resolveAdminRouteRuntimeTarget({
|
|
250
271
|
...options,
|
|
@@ -14,7 +14,7 @@ import { useApp } from '../../hooks/useApp';
|
|
|
14
14
|
import { useLocation, useNavigate, useParams } from 'react-router-dom';
|
|
15
15
|
import { NocoBaseDesktopRouteType } from '../../flow-compat';
|
|
16
16
|
import {
|
|
17
|
-
|
|
17
|
+
findFirstV2LandingRoute,
|
|
18
18
|
resolveAdminRouteRuntimeTarget,
|
|
19
19
|
toRouterNavigationPath,
|
|
20
20
|
} from '../admin-shell/admin-layout/resolveAdminRouteRuntimeTarget';
|
|
@@ -92,7 +92,7 @@ const AdminLayoutEntryGuard: FC<{ children: React.ReactNode }> = ({ children })
|
|
|
92
92
|
return;
|
|
93
93
|
}
|
|
94
94
|
|
|
95
|
-
const firstAccessibleRoute =
|
|
95
|
+
const firstAccessibleRoute = findFirstV2LandingRoute(routeRepository?.listAccessible?.() || []);
|
|
96
96
|
if (!firstAccessibleRoute) {
|
|
97
97
|
if (active) {
|
|
98
98
|
setReady(true);
|
|
@@ -15,10 +15,12 @@ import { useParams } from 'react-router-dom';
|
|
|
15
15
|
import { useApp } from '../../hooks/useApp';
|
|
16
16
|
import { NocoBaseDesktopRouteType } from '../../flow-compat';
|
|
17
17
|
import { resolveAdminRouteRuntimeTarget } from '../admin-shell/admin-layout/resolveAdminRouteRuntimeTarget';
|
|
18
|
+
import { AppNotFound } from '../../components';
|
|
18
19
|
|
|
19
20
|
type FlowRouteGuardState = {
|
|
20
21
|
pending: boolean;
|
|
21
22
|
allowBridge: boolean;
|
|
23
|
+
notFound: boolean;
|
|
22
24
|
};
|
|
23
25
|
|
|
24
26
|
const BridgeFlowRoute = ({ pageUid }: { pageUid: string }) => {
|
|
@@ -91,6 +93,7 @@ const FlowRoute = () => {
|
|
|
91
93
|
const [guardState, setGuardState] = useState<FlowRouteGuardState>({
|
|
92
94
|
pending: true,
|
|
93
95
|
allowBridge: false,
|
|
96
|
+
notFound: false,
|
|
94
97
|
});
|
|
95
98
|
const replaceTriggeredRef = useRef(false);
|
|
96
99
|
const requestIdRef = useRef(0);
|
|
@@ -104,14 +107,14 @@ const FlowRoute = () => {
|
|
|
104
107
|
const requestId = ++requestIdRef.current;
|
|
105
108
|
|
|
106
109
|
const run = async () => {
|
|
107
|
-
setGuardState({ pending: true, allowBridge: false });
|
|
110
|
+
setGuardState({ pending: true, allowBridge: false, notFound: false });
|
|
108
111
|
|
|
109
112
|
if (!routeRepository?.isAccessibleLoaded?.()) {
|
|
110
113
|
try {
|
|
111
114
|
await routeRepository?.ensureAccessibleLoaded?.();
|
|
112
115
|
} catch (_error) {
|
|
113
116
|
if (active && requestId === requestIdRef.current) {
|
|
114
|
-
setGuardState({ pending: false, allowBridge: true });
|
|
117
|
+
setGuardState({ pending: false, allowBridge: true, notFound: false });
|
|
115
118
|
}
|
|
116
119
|
return;
|
|
117
120
|
}
|
|
@@ -139,10 +142,17 @@ const FlowRoute = () => {
|
|
|
139
142
|
window.location.replace(target.runtimePath);
|
|
140
143
|
return;
|
|
141
144
|
}
|
|
145
|
+
|
|
146
|
+
if (target.reason === 'unsupportedV2Runtime') {
|
|
147
|
+
if (active && requestId === requestIdRef.current) {
|
|
148
|
+
setGuardState({ pending: false, allowBridge: false, notFound: true });
|
|
149
|
+
}
|
|
150
|
+
return;
|
|
151
|
+
}
|
|
142
152
|
}
|
|
143
153
|
|
|
144
154
|
if (active && requestId === requestIdRef.current) {
|
|
145
|
-
setGuardState({ pending: false, allowBridge: true });
|
|
155
|
+
setGuardState({ pending: false, allowBridge: true, notFound: false });
|
|
146
156
|
}
|
|
147
157
|
};
|
|
148
158
|
|
|
@@ -159,11 +169,14 @@ const FlowRoute = () => {
|
|
|
159
169
|
}
|
|
160
170
|
|
|
161
171
|
if (!guardState.allowBridge) {
|
|
172
|
+
if (guardState.notFound) {
|
|
173
|
+
return <AppNotFound />;
|
|
174
|
+
}
|
|
162
175
|
return null;
|
|
163
176
|
}
|
|
164
177
|
|
|
165
178
|
return <BridgeFlowRoute pageUid={pageUid} />;
|
|
166
|
-
}, [guardState.allowBridge, guardState.pending, pageUid]);
|
|
179
|
+
}, [guardState.allowBridge, guardState.notFound, guardState.pending, pageUid]);
|
|
167
180
|
|
|
168
181
|
return content;
|
|
169
182
|
};
|
|
@@ -30,6 +30,7 @@ import { useTranslation } from 'react-i18next';
|
|
|
30
30
|
import { buildRecordPickerPopupContextInputArgs, RecordPickerContent } from '../RecordPickerFieldModel';
|
|
31
31
|
import { AssociationFieldModel } from '../AssociationFieldModel';
|
|
32
32
|
import { adjustColumnOrder } from '../../../blocks/table/utils';
|
|
33
|
+
import { isSubTableColumnFieldComponentContext } from '../SubTableFieldModel/SubTableColumnModel';
|
|
33
34
|
import { EditFormContent } from './actions/PopupSubTableEditActionModel';
|
|
34
35
|
import { QuickEditFormModel } from '../../../blocks/form/QuickEditFormModel';
|
|
35
36
|
import { ActionWithoutPermission } from '../../../base/ActionModel';
|
|
@@ -901,6 +902,9 @@ PopupSubTableFieldModel.define({
|
|
|
901
902
|
EditableItemModel.bindModelToInterface('PopupSubTableFieldModel', ['m2m', 'o2m', 'mbm'], {
|
|
902
903
|
order: 300,
|
|
903
904
|
when: (ctx, field) => {
|
|
905
|
+
if (isSubTableColumnFieldComponentContext(ctx)) {
|
|
906
|
+
return false;
|
|
907
|
+
}
|
|
904
908
|
if (field.targetCollection) {
|
|
905
909
|
return field.targetCollection.template !== 'file';
|
|
906
910
|
}
|
package/src/flow/models/fields/AssociationFieldModel/SubTableFieldModel/SubTableColumnModel.tsx
CHANGED
|
@@ -36,6 +36,12 @@ import { FieldDeletePlaceholder, CustomWidth } from '../../../blocks/table/Table
|
|
|
36
36
|
import { buildDynamicNamePath } from '../../../blocks/form/dynamicNamePath';
|
|
37
37
|
import { getSubTableRowIdentity } from './rowIdentity';
|
|
38
38
|
|
|
39
|
+
export const SUB_TABLE_COLUMN_FIELD_COMPONENT_CONTEXT = 'subTableColumn';
|
|
40
|
+
|
|
41
|
+
export function isSubTableColumnFieldComponentContext(ctx) {
|
|
42
|
+
return (ctx?.model?.constructor as any)?.fieldComponentContext === SUB_TABLE_COLUMN_FIELD_COMPONENT_CONTEXT;
|
|
43
|
+
}
|
|
44
|
+
|
|
39
45
|
const SubTableRowRuleBinder: React.FC<{ model: any }> = ({ model }) => {
|
|
40
46
|
React.useEffect(() => {
|
|
41
47
|
const emitter = model?.flowEngine?.emitter;
|
|
@@ -401,6 +407,7 @@ export class SubTableColumnModel<
|
|
|
401
407
|
T extends SubTableColumnModelStructure = SubTableColumnModelStructure,
|
|
402
408
|
> extends EditableItemModel<T> {
|
|
403
409
|
static renderMode = ModelRenderMode.RenderFunction;
|
|
410
|
+
static fieldComponentContext = SUB_TABLE_COLUMN_FIELD_COMPONENT_CONTEXT;
|
|
404
411
|
|
|
405
412
|
renderHiddenInConfig() {
|
|
406
413
|
return <FieldWithoutPermissionPlaceholder targetModel={this} />;
|
|
@@ -21,7 +21,7 @@ import { uid } from '@formily/shared';
|
|
|
21
21
|
import { FormItemModel } from '../../../blocks/form';
|
|
22
22
|
import { AssociationFieldModel } from '../AssociationFieldModel';
|
|
23
23
|
import { buildRecordPickerPopupContextInputArgs, RecordPickerContent } from '../RecordPickerFieldModel';
|
|
24
|
-
import { SubTableColumnModel } from './SubTableColumnModel';
|
|
24
|
+
import { isSubTableColumnFieldComponentContext, SubTableColumnModel } from './SubTableColumnModel';
|
|
25
25
|
import { SubTableField } from './SubTableField';
|
|
26
26
|
import { adjustColumnOrder } from '../../../blocks/table/utils';
|
|
27
27
|
|
|
@@ -389,6 +389,9 @@ export { SubTableColumnModel };
|
|
|
389
389
|
FormItemModel.bindModelToInterface('SubTableFieldModel', ['m2m', 'o2m', 'mbm'], {
|
|
390
390
|
order: 200,
|
|
391
391
|
when: (ctx, field) => {
|
|
392
|
+
if (isSubTableColumnFieldComponentContext(ctx)) {
|
|
393
|
+
return false;
|
|
394
|
+
}
|
|
392
395
|
if (field.targetCollection) {
|
|
393
396
|
return field.targetCollection.template !== 'file';
|
|
394
397
|
}
|
|
@@ -7,8 +7,10 @@
|
|
|
7
7
|
* For more information, please refer to: https://www.nocobase.com/agreement.
|
|
8
8
|
*/
|
|
9
9
|
|
|
10
|
+
import { useFlowEngine } from '@nocobase/flow-engine';
|
|
10
11
|
import { useApp } from '../../flow-compat';
|
|
11
|
-
import
|
|
12
|
+
import languageCodes from '../../locale/languageCodes';
|
|
13
|
+
import { useEffect, useMemo, useState } from 'react';
|
|
12
14
|
|
|
13
15
|
/**
|
|
14
16
|
* 读取系统设置并兼容旧 hook 的返回结构。
|
|
@@ -25,7 +27,19 @@ import { useEffect, useState } from 'react';
|
|
|
25
27
|
export const useSystemSettings = () => {
|
|
26
28
|
const app = useApp();
|
|
27
29
|
const source = app.systemSettings;
|
|
30
|
+
const flowEngine = useFlowEngine({ throwError: false });
|
|
28
31
|
const [, forceUpdate] = useState(0);
|
|
32
|
+
const enabledLanguages = source.data?.data?.enabledLanguages;
|
|
33
|
+
const languageOptions = useMemo(
|
|
34
|
+
() =>
|
|
35
|
+
(Array.isArray(enabledLanguages) ? enabledLanguages : [])
|
|
36
|
+
.filter((code) => languageCodes[code])
|
|
37
|
+
.map((code) => ({
|
|
38
|
+
label: languageCodes[code].label,
|
|
39
|
+
value: code,
|
|
40
|
+
})),
|
|
41
|
+
[enabledLanguages],
|
|
42
|
+
);
|
|
29
43
|
|
|
30
44
|
useEffect(() => {
|
|
31
45
|
void source.load();
|
|
@@ -34,6 +48,27 @@ export const useSystemSettings = () => {
|
|
|
34
48
|
});
|
|
35
49
|
}, [source]);
|
|
36
50
|
|
|
51
|
+
useEffect(() => {
|
|
52
|
+
if (!flowEngine) {
|
|
53
|
+
return;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
flowEngine.context.defineProperty('locale', {
|
|
57
|
+
get: (ctx) => ctx.api?.auth?.locale || ctx.i18n?.language,
|
|
58
|
+
cache: false,
|
|
59
|
+
meta: {
|
|
60
|
+
type: 'string',
|
|
61
|
+
title: '{{t("Current language")}}',
|
|
62
|
+
sort: 970,
|
|
63
|
+
interface: 'select',
|
|
64
|
+
uiSchema: {
|
|
65
|
+
enum: languageOptions,
|
|
66
|
+
'x-component': 'Select',
|
|
67
|
+
},
|
|
68
|
+
},
|
|
69
|
+
});
|
|
70
|
+
}, [flowEngine, languageOptions]);
|
|
71
|
+
|
|
37
72
|
return {
|
|
38
73
|
loading: source.loading,
|
|
39
74
|
data: source.data,
|