react-toolkits 2.9.12 → 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 +6 -0
- package/lib/index.d.ts +2 -3
- package/lib/index.js +48 -35
- package/lib/index.js.map +1 -1
- package/package.json +3 -3
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;
|
|
@@ -396,12 +395,12 @@ declare function useFormModal<Values extends AnyObject = AnyObject, ExtraValues
|
|
|
396
395
|
modal: react_jsx_runtime.JSX.Element;
|
|
397
396
|
};
|
|
398
397
|
|
|
399
|
-
declare function usePermissions(codes: string[],
|
|
398
|
+
declare function usePermissions(codes: string[], options?: Omit<RequestOptions, 'method' | 'body'>): {
|
|
400
399
|
data: Record<string, boolean> | undefined;
|
|
401
400
|
isValidating: boolean;
|
|
402
401
|
isLoading: boolean;
|
|
403
402
|
};
|
|
404
|
-
declare function usePermission(code: string | undefined,
|
|
403
|
+
declare function usePermission(code: string | undefined, options?: Omit<RequestOptions, 'method' | 'body'>): {
|
|
405
404
|
accessible: boolean;
|
|
406
405
|
isValidating: boolean;
|
|
407
406
|
isLoading: boolean;
|
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
|
}
|
|
@@ -827,7 +827,7 @@ var init_layout = __esm({
|
|
|
827
827
|
});
|
|
828
828
|
async function request(url, opts = {}) {
|
|
829
829
|
const _opts = Object.assign(opts, { responseType: opts.responseType ?? "json" });
|
|
830
|
-
const { body, params, responseType,
|
|
830
|
+
const { body, params, responseType, ...rest } = _opts;
|
|
831
831
|
if (!url) {
|
|
832
832
|
throw new RequestError({
|
|
833
833
|
status: 400,
|
|
@@ -849,14 +849,10 @@ async function request(url, opts = {}) {
|
|
|
849
849
|
if (token) {
|
|
850
850
|
headers.set("Authorization", `Bearer ${token}`);
|
|
851
851
|
}
|
|
852
|
-
if (contextStore.getState().usePermissionApiV2) {
|
|
853
|
-
|
|
854
|
-
|
|
855
|
-
|
|
856
|
-
const game = useGameStore.getState().game;
|
|
857
|
-
if (game) {
|
|
858
|
-
headers.set("App-ID", String(game.game_id ?? game.id));
|
|
859
|
-
}
|
|
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));
|
|
860
856
|
}
|
|
861
857
|
}
|
|
862
858
|
if (responseType === "blob") {
|
|
@@ -920,16 +916,16 @@ var init_request = __esm({
|
|
|
920
916
|
};
|
|
921
917
|
}
|
|
922
918
|
});
|
|
923
|
-
function usePermissions(codes,
|
|
919
|
+
function usePermissions(codes, options) {
|
|
924
920
|
const usePermissionApiV2 = useToolkitsContext((state) => state.usePermissionApiV2);
|
|
925
921
|
const { data, isValidating, isLoading } = useSWR3(
|
|
926
922
|
codes.length > 0 ? [usePermissionApiV2 ? "/api/usystem/user/checkV2" : "/api/usystem/user/check", codes] : null,
|
|
927
923
|
([url]) => request(url, {
|
|
924
|
+
...options,
|
|
928
925
|
method: "POST",
|
|
929
926
|
body: {
|
|
930
927
|
permissions: codes
|
|
931
|
-
}
|
|
932
|
-
isGlobal
|
|
928
|
+
}
|
|
933
929
|
}).then((response) => {
|
|
934
930
|
if (response.data?.has_all) {
|
|
935
931
|
return codes.reduce(
|
|
@@ -954,8 +950,8 @@ function usePermissions(codes, isGlobal) {
|
|
|
954
950
|
);
|
|
955
951
|
return { data, isValidating, isLoading };
|
|
956
952
|
}
|
|
957
|
-
function usePermission(code,
|
|
958
|
-
const { data, isValidating, isLoading } = usePermissions(code ? [code] : [],
|
|
953
|
+
function usePermission(code, options) {
|
|
954
|
+
const { data, isValidating, isLoading } = usePermissions(code ? [code] : [], options);
|
|
959
955
|
if (code === void 0) {
|
|
960
956
|
return {
|
|
961
957
|
accessible: true,
|
|
@@ -978,11 +974,11 @@ var init_permission = __esm({
|
|
|
978
974
|
var PermissionButton, PermissionButton_default;
|
|
979
975
|
var init_PermissionButton = __esm({
|
|
980
976
|
"src/components/permissionButton/PermissionButton.tsx"() {
|
|
981
|
-
init_locale();
|
|
982
977
|
init_permission();
|
|
978
|
+
init_locale();
|
|
983
979
|
PermissionButton = (props) => {
|
|
984
980
|
const { children, code, showLoading, isGlobal, disabled, ...restProps } = props;
|
|
985
|
-
const { data, isLoading } = usePermissions(Array.isArray(code) ? code : [code],
|
|
981
|
+
const { data, isLoading } = usePermissions(Array.isArray(code) ? code : [code], { headers: { "App-ID": "global" } });
|
|
986
982
|
const { t } = useTranslation();
|
|
987
983
|
if (isLoading) {
|
|
988
984
|
return /* @__PURE__ */ jsx(Button, { loading: showLoading, disabled: !showLoading, ...restProps, children });
|
|
@@ -1082,7 +1078,9 @@ var init_QueryList = __esm({
|
|
|
1082
1078
|
const { notification } = App.useApp();
|
|
1083
1079
|
const { t } = useTranslation();
|
|
1084
1080
|
const [_form] = Form.useForm(form);
|
|
1085
|
-
const { accessible, isLoading } = usePermission(code,
|
|
1081
|
+
const { accessible, isLoading } = usePermission(code, {
|
|
1082
|
+
headers: isGlobal ? { "App-ID": "global" } : void 0
|
|
1083
|
+
});
|
|
1086
1084
|
const action = useRef(3 /* Init */);
|
|
1087
1085
|
const { game } = useGameStore();
|
|
1088
1086
|
const usePermissionApiV2 = useToolkitsContext((state) => state.usePermissionApiV2);
|
|
@@ -1377,27 +1375,27 @@ var init_formModal = __esm({
|
|
|
1377
1375
|
function useAllPermissions() {
|
|
1378
1376
|
return useSWR3(
|
|
1379
1377
|
"/api/usystem/user/allPermssions",
|
|
1380
|
-
(url) => request(url, {
|
|
1378
|
+
(url) => request(url, { headers: { "App-ID": "global" } }).then((response) => response.data)
|
|
1381
1379
|
);
|
|
1382
1380
|
}
|
|
1383
1381
|
function useAllPermissionsV2() {
|
|
1384
1382
|
return useSWR3(
|
|
1385
1383
|
"/api/usystem/user/allPermissionsV2",
|
|
1386
|
-
(url) => request(url, {
|
|
1384
|
+
(url) => request(url, { headers: { "App-ID": "global" } }).then((response) => response.data)
|
|
1387
1385
|
);
|
|
1388
1386
|
}
|
|
1389
1387
|
function useAllRoles() {
|
|
1390
|
-
const { accessible } = usePermission("200005",
|
|
1388
|
+
const { accessible } = usePermission("200005", { headers: { "App-ID": "global" } });
|
|
1391
1389
|
return useSWR3(
|
|
1392
1390
|
accessible ? "/api/usystem/role/all" : null,
|
|
1393
|
-
(url) => request(url, {
|
|
1391
|
+
(url) => request(url, { headers: { "App-ID": "global" } }).then((response) => response.data)
|
|
1394
1392
|
);
|
|
1395
1393
|
}
|
|
1396
1394
|
function useRole(name) {
|
|
1397
1395
|
const usePermissionApiV2 = useToolkitsContext((state) => state.usePermissionApiV2);
|
|
1398
1396
|
return useSWR3(
|
|
1399
1397
|
`/api/usystem/role/${usePermissionApiV2 ? "infoV2" : "info"}?name=${name}`,
|
|
1400
|
-
(url) => request(url, {
|
|
1398
|
+
(url) => request(url, { headers: { "App-ID": "global" } }).then((response) => response.data)
|
|
1401
1399
|
);
|
|
1402
1400
|
}
|
|
1403
1401
|
function useCreateRole() {
|
|
@@ -1409,7 +1407,7 @@ function useCreateRole() {
|
|
|
1409
1407
|
}) => request(url, {
|
|
1410
1408
|
method: "post",
|
|
1411
1409
|
body: arg,
|
|
1412
|
-
|
|
1410
|
+
headers: { "App-ID": "global" }
|
|
1413
1411
|
})
|
|
1414
1412
|
);
|
|
1415
1413
|
}
|
|
@@ -1422,7 +1420,7 @@ function useUpdateRole() {
|
|
|
1422
1420
|
}) => request(url, {
|
|
1423
1421
|
method: "post",
|
|
1424
1422
|
body: arg,
|
|
1425
|
-
|
|
1423
|
+
headers: { "App-ID": "global" }
|
|
1426
1424
|
})
|
|
1427
1425
|
);
|
|
1428
1426
|
}
|
|
@@ -1434,7 +1432,7 @@ function useRemoveRole() {
|
|
|
1434
1432
|
}) => request(url, {
|
|
1435
1433
|
method: "post",
|
|
1436
1434
|
body: arg,
|
|
1437
|
-
|
|
1435
|
+
headers: { "App-ID": "global" }
|
|
1438
1436
|
})
|
|
1439
1437
|
);
|
|
1440
1438
|
}
|
|
@@ -1446,7 +1444,7 @@ function useCreateUser() {
|
|
|
1446
1444
|
}) => request(url, {
|
|
1447
1445
|
method: "post",
|
|
1448
1446
|
body: arg,
|
|
1449
|
-
|
|
1447
|
+
headers: { "App-ID": "global" }
|
|
1450
1448
|
})
|
|
1451
1449
|
);
|
|
1452
1450
|
}
|
|
@@ -1458,7 +1456,7 @@ function useUpdateUser() {
|
|
|
1458
1456
|
}) => request(url, {
|
|
1459
1457
|
method: "post",
|
|
1460
1458
|
body: arg,
|
|
1461
|
-
|
|
1459
|
+
headers: { "App-ID": "global" }
|
|
1462
1460
|
})
|
|
1463
1461
|
);
|
|
1464
1462
|
}
|
|
@@ -1470,7 +1468,7 @@ function useRemoveUser() {
|
|
|
1470
1468
|
}) => request(url, {
|
|
1471
1469
|
method: "post",
|
|
1472
1470
|
body: arg,
|
|
1473
|
-
|
|
1471
|
+
headers: { "App-ID": "global" }
|
|
1474
1472
|
})
|
|
1475
1473
|
);
|
|
1476
1474
|
}
|
|
@@ -2004,7 +2002,7 @@ var init_roleList = __esm({
|
|
|
2004
2002
|
});
|
|
2005
2003
|
};
|
|
2006
2004
|
RoleList = () => {
|
|
2007
|
-
const { accessible: viewable } = usePermission("200005",
|
|
2005
|
+
const { accessible: viewable } = usePermission("200005", { headers: { "App-ID": "global" } });
|
|
2008
2006
|
const { modal, message } = App.useApp();
|
|
2009
2007
|
const { t } = useTranslation();
|
|
2010
2008
|
const usePermissionApiV2 = useToolkitsContext((state) => state.usePermissionApiV2);
|
|
@@ -2015,7 +2013,7 @@ var init_roleList = __esm({
|
|
|
2015
2013
|
const handleUpdateBtnClick = async (record) => {
|
|
2016
2014
|
const { data: role } = await request(
|
|
2017
2015
|
`/api/usystem/role/info${usePermissionApiV2 ? "V2" : ""}?name=${record.name}`,
|
|
2018
|
-
{
|
|
2016
|
+
{ headers: { "App-ID": "global" } }
|
|
2019
2017
|
);
|
|
2020
2018
|
showUpdateModal({
|
|
2021
2019
|
initialValues: {
|
|
@@ -2349,7 +2347,9 @@ init_highlight();
|
|
|
2349
2347
|
// src/components/infiniteList/InfiniteList.tsx
|
|
2350
2348
|
init_permission();
|
|
2351
2349
|
init_request();
|
|
2350
|
+
init_contextProvider();
|
|
2352
2351
|
init_filterFormWrapper();
|
|
2352
|
+
init_layout();
|
|
2353
2353
|
init_locale();
|
|
2354
2354
|
var InfiniteList = (props) => {
|
|
2355
2355
|
const {
|
|
@@ -2377,6 +2377,19 @@ var InfiniteList = (props) => {
|
|
|
2377
2377
|
const queryString = qs.stringify(args);
|
|
2378
2378
|
return queryString ? `${action}?${qs.stringify(args)}` : action;
|
|
2379
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]);
|
|
2380
2393
|
const {
|
|
2381
2394
|
data,
|
|
2382
2395
|
size,
|
|
@@ -2386,8 +2399,7 @@ var InfiniteList = (props) => {
|
|
|
2386
2399
|
getKey,
|
|
2387
2400
|
(arg) => {
|
|
2388
2401
|
return request(arg, {
|
|
2389
|
-
headers:
|
|
2390
|
-
isGlobal
|
|
2402
|
+
headers: _headers
|
|
2391
2403
|
}).then((response) => response.data);
|
|
2392
2404
|
},
|
|
2393
2405
|
{
|
|
@@ -2491,7 +2503,7 @@ init_permission();
|
|
|
2491
2503
|
init_locale();
|
|
2492
2504
|
var RequirePermission = (props) => {
|
|
2493
2505
|
const { code, isGlobal, children } = props;
|
|
2494
|
-
const { accessible, isValidating } = usePermission(code, isGlobal);
|
|
2506
|
+
const { accessible, isValidating } = usePermission(code, isGlobal ? { headers: { "App-ID": "global" } } : void 0);
|
|
2495
2507
|
const { t } = useTranslation();
|
|
2496
2508
|
if (isValidating) {
|
|
2497
2509
|
return /* @__PURE__ */ jsx(
|
|
@@ -2605,6 +2617,7 @@ var OperationLogList = () => {
|
|
|
2605
2617
|
return /* @__PURE__ */ jsx(Card, { title: "\u64CD\u4F5C\u65E5\u5FD7", children: /* @__PURE__ */ jsx(
|
|
2606
2618
|
QueryList_default,
|
|
2607
2619
|
{
|
|
2620
|
+
isGlobal: true,
|
|
2608
2621
|
rowKey: "id",
|
|
2609
2622
|
code: "300001",
|
|
2610
2623
|
columns,
|