react-toolkits 2.9.11 → 2.9.13
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/CHANGELOG.md +12 -0
- package/lib/index.d.ts +10 -12
- package/lib/index.js +52 -48
- package/lib/index.js.map +1 -1
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
package/lib/index.d.ts
CHANGED
|
@@ -26,7 +26,6 @@ interface RequestOptions extends Omit<RequestInit, 'body'> {
|
|
|
26
26
|
body?: Record<string | number, any> | FormData | null;
|
|
27
27
|
params?: Record<string | number, any> | URLSearchParams | null;
|
|
28
28
|
responseType?: 'json' | 'blob' | 'text';
|
|
29
|
-
isGlobal?: boolean;
|
|
30
29
|
}
|
|
31
30
|
type RequestResponse<T> = Pick<Response, 'headers' | 'status' | 'statusText' | 'url'> & {
|
|
32
31
|
data: T;
|
|
@@ -222,14 +221,6 @@ interface Game {
|
|
|
222
221
|
is_new_game: 0 | 1;
|
|
223
222
|
server_type: string;
|
|
224
223
|
}
|
|
225
|
-
interface GameState {
|
|
226
|
-
initialized: boolean;
|
|
227
|
-
game: Game | null;
|
|
228
|
-
games: Game[];
|
|
229
|
-
isLoading: boolean;
|
|
230
|
-
setGame: (id: string | number) => Promise<void>;
|
|
231
|
-
refetchGames: (apiV2?: boolean) => Promise<void>;
|
|
232
|
-
}
|
|
233
224
|
|
|
234
225
|
interface GameSelectProps {
|
|
235
226
|
apiV2?: boolean;
|
|
@@ -270,6 +261,13 @@ declare const useLayoutStore: zustand.UseBoundStore<Omit<zustand.StoreApi<Layout
|
|
|
270
261
|
getOptions: () => Partial<zustand_middleware.PersistOptions<LayoutState, unknown>>;
|
|
271
262
|
};
|
|
272
263
|
}>;
|
|
264
|
+
interface GameState {
|
|
265
|
+
initialized: boolean;
|
|
266
|
+
game: Game | null;
|
|
267
|
+
games: Game[];
|
|
268
|
+
isLoading: boolean;
|
|
269
|
+
refetchGames: (apiV2?: boolean) => Promise<void>;
|
|
270
|
+
}
|
|
273
271
|
declare const useGameStore: zustand.UseBoundStore<Omit<zustand.StoreApi<GameState>, "persist"> & {
|
|
274
272
|
persist: {
|
|
275
273
|
setOptions: (options: Partial<zustand_middleware.PersistOptions<GameState, unknown>>) => void;
|
|
@@ -397,12 +395,12 @@ declare function useFormModal<Values extends AnyObject = AnyObject, ExtraValues
|
|
|
397
395
|
modal: react_jsx_runtime.JSX.Element;
|
|
398
396
|
};
|
|
399
397
|
|
|
400
|
-
declare function usePermissions(codes: string[],
|
|
398
|
+
declare function usePermissions(codes: string[], options?: Omit<RequestOptions, 'method' | 'body'>): {
|
|
401
399
|
data: Record<string, boolean> | undefined;
|
|
402
400
|
isValidating: boolean;
|
|
403
401
|
isLoading: boolean;
|
|
404
402
|
};
|
|
405
|
-
declare function usePermission(code: string | undefined,
|
|
403
|
+
declare function usePermission(code: string | undefined, options?: Omit<RequestOptions, 'method' | 'body'>): {
|
|
406
404
|
accessible: boolean;
|
|
407
405
|
isValidating: boolean;
|
|
408
406
|
isLoading: boolean;
|
|
@@ -456,4 +454,4 @@ declare const SignIn: FC<SignInProps>;
|
|
|
456
454
|
|
|
457
455
|
declare const mixedStorage: StateStorage;
|
|
458
456
|
|
|
459
|
-
export { ContextProvider, type ContextState, DynamicTags, type DynamicTagsProps, ExpandableParagraph, type ExpandableParagraphProps, FilterFormWrapper, type FilterFormWrapperProps, type Game,
|
|
457
|
+
export { ContextProvider, type ContextState, DynamicTags, type DynamicTagsProps, ExpandableParagraph, type ExpandableParagraphProps, FilterFormWrapper, type FilterFormWrapperProps, type Game, Highlight, type HighlightProps, InfiniteList, type InfiniteListProps, Layout, type LayoutState, NavMenu, type NavMenuItem, NotFound, OperationLogList, PermissionButton, type PermissionButtonProps, QueryList, QueryListAction, type QueryListProps, type QueryListRef, RequestError, type RequestOptions, type RequestResponse, RequirePermission, type RequirePermissionProps, SignIn, type TokenState, type UseFormModalProps, type UseModalOperation, type UseModalProps, UserWidget, type UserWidgetProps, contextStore, mixedStorage, _default as permissionRoutes, request, useFormModal, useGameStore, useLayoutStore, useModal, useModalStore, usePermission, usePermissions, useQueryListStore, useTokenStore, useTokenValidation, useToolkitsContext };
|
package/lib/index.js
CHANGED
|
@@ -389,7 +389,7 @@ var init_NavMenu = __esm({
|
|
|
389
389
|
const location = useLocation();
|
|
390
390
|
const flattenItems = useMemo(() => flatItems(items ?? []), [items]);
|
|
391
391
|
const codes = useMemo(() => flattenItems.map((item) => item.code).filter(Boolean), [flattenItems]);
|
|
392
|
-
const { data: permissions, isLoading } = usePermissions(codes,
|
|
392
|
+
const { data: permissions, isLoading } = usePermissions(codes, { headers: { "App-ID": "global" } });
|
|
393
393
|
const internalItems = useMemo(() => transformItems(items ?? [], permissions), [items, permissions]);
|
|
394
394
|
const { openKeys, selectedKeys, setOpenKeys, setSelectedKeys } = useNavStore();
|
|
395
395
|
const onOpenChange = useCallback(
|
|
@@ -447,7 +447,7 @@ function useTokenValidation(options) {
|
|
|
447
447
|
body: {
|
|
448
448
|
permissions: ["100001"]
|
|
449
449
|
},
|
|
450
|
-
|
|
450
|
+
headers: { "App-ID": "global" }
|
|
451
451
|
})
|
|
452
452
|
);
|
|
453
453
|
}
|
|
@@ -586,16 +586,6 @@ var init_stores2 = __esm({
|
|
|
586
586
|
isLoading: false,
|
|
587
587
|
game: null,
|
|
588
588
|
games: [],
|
|
589
|
-
async setGame(id2) {
|
|
590
|
-
if (id2 === get2().game?.game_id) {
|
|
591
|
-
return;
|
|
592
|
-
}
|
|
593
|
-
if (!get2().initialized) {
|
|
594
|
-
await get2().refetchGames();
|
|
595
|
-
}
|
|
596
|
-
const game = (get2().games ?? []).find((item) => item.game_id === id2) ?? null;
|
|
597
|
-
set({ game });
|
|
598
|
-
},
|
|
599
589
|
async refetchGames(apiV2) {
|
|
600
590
|
if (!get2().isLoading) {
|
|
601
591
|
try {
|
|
@@ -634,7 +624,7 @@ var init_GameSelect = __esm({
|
|
|
634
624
|
GameSelect = (props) => {
|
|
635
625
|
const { apiV2, filter, onGameChange } = props;
|
|
636
626
|
const { t } = useTranslation();
|
|
637
|
-
const { game, games, isLoading, refetchGames
|
|
627
|
+
const { game, games, isLoading, refetchGames } = useGameStore();
|
|
638
628
|
useEffect(() => {
|
|
639
629
|
refetchGames(apiV2);
|
|
640
630
|
}, []);
|
|
@@ -643,8 +633,9 @@ var init_GameSelect = __esm({
|
|
|
643
633
|
value: apiV2 ? item.game_id : item.id
|
|
644
634
|
}));
|
|
645
635
|
const onChange = async (id2) => {
|
|
646
|
-
|
|
647
|
-
|
|
636
|
+
const match = games.find((item) => String(apiV2 ? item.game_id : item.id) === String(id2));
|
|
637
|
+
useGameStore.setState({ game: match });
|
|
638
|
+
onGameChange?.(match);
|
|
648
639
|
};
|
|
649
640
|
return /* @__PURE__ */ jsxs(Space, { children: [
|
|
650
641
|
/* @__PURE__ */ jsx(Text, { children: t("GameSelect.label") }),
|
|
@@ -836,7 +827,7 @@ var init_layout = __esm({
|
|
|
836
827
|
});
|
|
837
828
|
async function request(url, opts = {}) {
|
|
838
829
|
const _opts = Object.assign(opts, { responseType: opts.responseType ?? "json" });
|
|
839
|
-
const { body, params, responseType,
|
|
830
|
+
const { body, params, responseType, ...rest } = _opts;
|
|
840
831
|
if (!url) {
|
|
841
832
|
throw new RequestError({
|
|
842
833
|
status: 400,
|
|
@@ -858,14 +849,10 @@ async function request(url, opts = {}) {
|
|
|
858
849
|
if (token) {
|
|
859
850
|
headers.set("Authorization", `Bearer ${token}`);
|
|
860
851
|
}
|
|
861
|
-
if (contextStore.getState().usePermissionApiV2) {
|
|
862
|
-
|
|
863
|
-
|
|
864
|
-
|
|
865
|
-
const game = useGameStore.getState().game;
|
|
866
|
-
if (game) {
|
|
867
|
-
headers.set("App-ID", String(game.game_id));
|
|
868
|
-
}
|
|
852
|
+
if (!headers.has("App-ID") && contextStore.getState().usePermissionApiV2) {
|
|
853
|
+
const game = useGameStore.getState().game;
|
|
854
|
+
if (game) {
|
|
855
|
+
headers.set("App-ID", String(game.game_id ?? game.id));
|
|
869
856
|
}
|
|
870
857
|
}
|
|
871
858
|
if (responseType === "blob") {
|
|
@@ -929,16 +916,16 @@ var init_request = __esm({
|
|
|
929
916
|
};
|
|
930
917
|
}
|
|
931
918
|
});
|
|
932
|
-
function usePermissions(codes,
|
|
919
|
+
function usePermissions(codes, options) {
|
|
933
920
|
const usePermissionApiV2 = useToolkitsContext((state) => state.usePermissionApiV2);
|
|
934
921
|
const { data, isValidating, isLoading } = useSWR3(
|
|
935
922
|
codes.length > 0 ? [usePermissionApiV2 ? "/api/usystem/user/checkV2" : "/api/usystem/user/check", codes] : null,
|
|
936
923
|
([url]) => request(url, {
|
|
924
|
+
...options,
|
|
937
925
|
method: "POST",
|
|
938
926
|
body: {
|
|
939
927
|
permissions: codes
|
|
940
|
-
}
|
|
941
|
-
isGlobal
|
|
928
|
+
}
|
|
942
929
|
}).then((response) => {
|
|
943
930
|
if (response.data?.has_all) {
|
|
944
931
|
return codes.reduce(
|
|
@@ -963,8 +950,8 @@ function usePermissions(codes, isGlobal) {
|
|
|
963
950
|
);
|
|
964
951
|
return { data, isValidating, isLoading };
|
|
965
952
|
}
|
|
966
|
-
function usePermission(code,
|
|
967
|
-
const { data, isValidating, isLoading } = usePermissions(code ? [code] : [],
|
|
953
|
+
function usePermission(code, options) {
|
|
954
|
+
const { data, isValidating, isLoading } = usePermissions(code ? [code] : [], options);
|
|
968
955
|
if (code === void 0) {
|
|
969
956
|
return {
|
|
970
957
|
accessible: true,
|
|
@@ -987,11 +974,11 @@ var init_permission = __esm({
|
|
|
987
974
|
var PermissionButton, PermissionButton_default;
|
|
988
975
|
var init_PermissionButton = __esm({
|
|
989
976
|
"src/components/permissionButton/PermissionButton.tsx"() {
|
|
990
|
-
init_locale();
|
|
991
977
|
init_permission();
|
|
978
|
+
init_locale();
|
|
992
979
|
PermissionButton = (props) => {
|
|
993
980
|
const { children, code, showLoading, isGlobal, disabled, ...restProps } = props;
|
|
994
|
-
const { data, isLoading } = usePermissions(Array.isArray(code) ? code : [code],
|
|
981
|
+
const { data, isLoading } = usePermissions(Array.isArray(code) ? code : [code], { headers: { "App-ID": "global" } });
|
|
995
982
|
const { t } = useTranslation();
|
|
996
983
|
if (isLoading) {
|
|
997
984
|
return /* @__PURE__ */ jsx(Button, { loading: showLoading, disabled: !showLoading, ...restProps, children });
|
|
@@ -1091,7 +1078,9 @@ var init_QueryList = __esm({
|
|
|
1091
1078
|
const { notification } = App.useApp();
|
|
1092
1079
|
const { t } = useTranslation();
|
|
1093
1080
|
const [_form] = Form.useForm(form);
|
|
1094
|
-
const { accessible, isLoading } = usePermission(code,
|
|
1081
|
+
const { accessible, isLoading } = usePermission(code, {
|
|
1082
|
+
headers: isGlobal ? { "App-ID": "global" } : void 0
|
|
1083
|
+
});
|
|
1095
1084
|
const action = useRef(3 /* Init */);
|
|
1096
1085
|
const { game } = useGameStore();
|
|
1097
1086
|
const usePermissionApiV2 = useToolkitsContext((state) => state.usePermissionApiV2);
|
|
@@ -1386,27 +1375,27 @@ var init_formModal = __esm({
|
|
|
1386
1375
|
function useAllPermissions() {
|
|
1387
1376
|
return useSWR3(
|
|
1388
1377
|
"/api/usystem/user/allPermssions",
|
|
1389
|
-
(url) => request(url, {
|
|
1378
|
+
(url) => request(url, { headers: { "App-ID": "global" } }).then((response) => response.data)
|
|
1390
1379
|
);
|
|
1391
1380
|
}
|
|
1392
1381
|
function useAllPermissionsV2() {
|
|
1393
1382
|
return useSWR3(
|
|
1394
1383
|
"/api/usystem/user/allPermissionsV2",
|
|
1395
|
-
(url) => request(url, {
|
|
1384
|
+
(url) => request(url, { headers: { "App-ID": "global" } }).then((response) => response.data)
|
|
1396
1385
|
);
|
|
1397
1386
|
}
|
|
1398
1387
|
function useAllRoles() {
|
|
1399
|
-
const { accessible } = usePermission("200005",
|
|
1388
|
+
const { accessible } = usePermission("200005", { headers: { "App-ID": "global" } });
|
|
1400
1389
|
return useSWR3(
|
|
1401
1390
|
accessible ? "/api/usystem/role/all" : null,
|
|
1402
|
-
(url) => request(url, {
|
|
1391
|
+
(url) => request(url, { headers: { "App-ID": "global" } }).then((response) => response.data)
|
|
1403
1392
|
);
|
|
1404
1393
|
}
|
|
1405
1394
|
function useRole(name) {
|
|
1406
1395
|
const usePermissionApiV2 = useToolkitsContext((state) => state.usePermissionApiV2);
|
|
1407
1396
|
return useSWR3(
|
|
1408
1397
|
`/api/usystem/role/${usePermissionApiV2 ? "infoV2" : "info"}?name=${name}`,
|
|
1409
|
-
(url) => request(url, {
|
|
1398
|
+
(url) => request(url, { headers: { "App-ID": "global" } }).then((response) => response.data)
|
|
1410
1399
|
);
|
|
1411
1400
|
}
|
|
1412
1401
|
function useCreateRole() {
|
|
@@ -1418,7 +1407,7 @@ function useCreateRole() {
|
|
|
1418
1407
|
}) => request(url, {
|
|
1419
1408
|
method: "post",
|
|
1420
1409
|
body: arg,
|
|
1421
|
-
|
|
1410
|
+
headers: { "App-ID": "global" }
|
|
1422
1411
|
})
|
|
1423
1412
|
);
|
|
1424
1413
|
}
|
|
@@ -1431,7 +1420,7 @@ function useUpdateRole() {
|
|
|
1431
1420
|
}) => request(url, {
|
|
1432
1421
|
method: "post",
|
|
1433
1422
|
body: arg,
|
|
1434
|
-
|
|
1423
|
+
headers: { "App-ID": "global" }
|
|
1435
1424
|
})
|
|
1436
1425
|
);
|
|
1437
1426
|
}
|
|
@@ -1443,7 +1432,7 @@ function useRemoveRole() {
|
|
|
1443
1432
|
}) => request(url, {
|
|
1444
1433
|
method: "post",
|
|
1445
1434
|
body: arg,
|
|
1446
|
-
|
|
1435
|
+
headers: { "App-ID": "global" }
|
|
1447
1436
|
})
|
|
1448
1437
|
);
|
|
1449
1438
|
}
|
|
@@ -1455,7 +1444,7 @@ function useCreateUser() {
|
|
|
1455
1444
|
}) => request(url, {
|
|
1456
1445
|
method: "post",
|
|
1457
1446
|
body: arg,
|
|
1458
|
-
|
|
1447
|
+
headers: { "App-ID": "global" }
|
|
1459
1448
|
})
|
|
1460
1449
|
);
|
|
1461
1450
|
}
|
|
@@ -1467,7 +1456,7 @@ function useUpdateUser() {
|
|
|
1467
1456
|
}) => request(url, {
|
|
1468
1457
|
method: "post",
|
|
1469
1458
|
body: arg,
|
|
1470
|
-
|
|
1459
|
+
headers: { "App-ID": "global" }
|
|
1471
1460
|
})
|
|
1472
1461
|
);
|
|
1473
1462
|
}
|
|
@@ -1479,7 +1468,7 @@ function useRemoveUser() {
|
|
|
1479
1468
|
}) => request(url, {
|
|
1480
1469
|
method: "post",
|
|
1481
1470
|
body: arg,
|
|
1482
|
-
|
|
1471
|
+
headers: { "App-ID": "global" }
|
|
1483
1472
|
})
|
|
1484
1473
|
);
|
|
1485
1474
|
}
|
|
@@ -2013,7 +2002,7 @@ var init_roleList = __esm({
|
|
|
2013
2002
|
});
|
|
2014
2003
|
};
|
|
2015
2004
|
RoleList = () => {
|
|
2016
|
-
const { accessible: viewable } = usePermission("200005",
|
|
2005
|
+
const { accessible: viewable } = usePermission("200005", { headers: { "App-ID": "global" } });
|
|
2017
2006
|
const { modal, message } = App.useApp();
|
|
2018
2007
|
const { t } = useTranslation();
|
|
2019
2008
|
const usePermissionApiV2 = useToolkitsContext((state) => state.usePermissionApiV2);
|
|
@@ -2024,7 +2013,7 @@ var init_roleList = __esm({
|
|
|
2024
2013
|
const handleUpdateBtnClick = async (record) => {
|
|
2025
2014
|
const { data: role } = await request(
|
|
2026
2015
|
`/api/usystem/role/info${usePermissionApiV2 ? "V2" : ""}?name=${record.name}`,
|
|
2027
|
-
{
|
|
2016
|
+
{ headers: { "App-ID": "global" } }
|
|
2028
2017
|
);
|
|
2029
2018
|
showUpdateModal({
|
|
2030
2019
|
initialValues: {
|
|
@@ -2358,7 +2347,9 @@ init_highlight();
|
|
|
2358
2347
|
// src/components/infiniteList/InfiniteList.tsx
|
|
2359
2348
|
init_permission();
|
|
2360
2349
|
init_request();
|
|
2350
|
+
init_contextProvider();
|
|
2361
2351
|
init_filterFormWrapper();
|
|
2352
|
+
init_layout();
|
|
2362
2353
|
init_locale();
|
|
2363
2354
|
var InfiniteList = (props) => {
|
|
2364
2355
|
const {
|
|
@@ -2386,6 +2377,19 @@ var InfiniteList = (props) => {
|
|
|
2386
2377
|
const queryString = qs.stringify(args);
|
|
2387
2378
|
return queryString ? `${action}?${qs.stringify(args)}` : action;
|
|
2388
2379
|
};
|
|
2380
|
+
const { game } = useGameStore();
|
|
2381
|
+
const usePermissionApiV2 = useToolkitsContext((state) => state.usePermissionApiV2);
|
|
2382
|
+
const _headers = useMemo(() => {
|
|
2383
|
+
const newHeaders = new Headers(typeof headers === "function" ? headers(form) : headers);
|
|
2384
|
+
if (usePermissionApiV2) {
|
|
2385
|
+
if (isGlobal) {
|
|
2386
|
+
newHeaders.set("App-ID", "global");
|
|
2387
|
+
} else if (game) {
|
|
2388
|
+
newHeaders.set("App-ID", String(game.id));
|
|
2389
|
+
}
|
|
2390
|
+
}
|
|
2391
|
+
return newHeaders;
|
|
2392
|
+
}, [usePermissionApiV2, isGlobal, game, headers]);
|
|
2389
2393
|
const {
|
|
2390
2394
|
data,
|
|
2391
2395
|
size,
|
|
@@ -2395,8 +2399,7 @@ var InfiniteList = (props) => {
|
|
|
2395
2399
|
getKey,
|
|
2396
2400
|
(arg) => {
|
|
2397
2401
|
return request(arg, {
|
|
2398
|
-
headers:
|
|
2399
|
-
isGlobal
|
|
2402
|
+
headers: _headers
|
|
2400
2403
|
}).then((response) => response.data);
|
|
2401
2404
|
},
|
|
2402
2405
|
{
|
|
@@ -2500,7 +2503,7 @@ init_permission();
|
|
|
2500
2503
|
init_locale();
|
|
2501
2504
|
var RequirePermission = (props) => {
|
|
2502
2505
|
const { code, isGlobal, children } = props;
|
|
2503
|
-
const { accessible, isValidating } = usePermission(code, isGlobal);
|
|
2506
|
+
const { accessible, isValidating } = usePermission(code, isGlobal ? { headers: { "App-ID": "global" } } : void 0);
|
|
2504
2507
|
const { t } = useTranslation();
|
|
2505
2508
|
if (isValidating) {
|
|
2506
2509
|
return /* @__PURE__ */ jsx(
|
|
@@ -2614,6 +2617,7 @@ var OperationLogList = () => {
|
|
|
2614
2617
|
return /* @__PURE__ */ jsx(Card, { title: "\u64CD\u4F5C\u65E5\u5FD7", children: /* @__PURE__ */ jsx(
|
|
2615
2618
|
QueryList_default,
|
|
2616
2619
|
{
|
|
2620
|
+
isGlobal: true,
|
|
2617
2621
|
rowKey: "id",
|
|
2618
2622
|
code: "300001",
|
|
2619
2623
|
columns,
|