react-toolkits 2.13.6 → 2.13.7
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 +5 -3
- package/lib/index.js +101 -89
- package/lib/index.js.map +1 -1
- package/package.json +3 -3
package/CHANGELOG.md
CHANGED
package/lib/index.d.ts
CHANGED
|
@@ -4,7 +4,7 @@ import { ParagraphProps } from 'antd/es/typography/Paragraph';
|
|
|
4
4
|
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
5
5
|
import { FormInstance, MenuProps, ModalProps, FormProps, ButtonProps } from 'antd';
|
|
6
6
|
import { TableProps } from 'antd/es/table';
|
|
7
|
-
import { AxiosHeaderValue, AxiosInstance, InternalAxiosRequestConfig, AxiosResponse, AxiosInterceptorOptions } from 'axios';
|
|
7
|
+
import { AxiosHeaderValue, AxiosRequestConfig, AxiosInstance, InternalAxiosRequestConfig, AxiosResponse, AxiosInterceptorOptions } from 'axios';
|
|
8
8
|
import * as swr from 'swr';
|
|
9
9
|
import { MutatorCallback, MutatorOptions } from 'swr';
|
|
10
10
|
import { ItemType, SubMenuType, MenuItemGroupType, MenuItemType } from 'antd/es/menu/interface';
|
|
@@ -188,6 +188,7 @@ declare const useModalStore: zustand.UseBoundStore<zustand.StoreApi<ModalState>>
|
|
|
188
188
|
interface PermissionButtonProps extends ButtonProps {
|
|
189
189
|
code?: string | string[];
|
|
190
190
|
showLoading?: boolean;
|
|
191
|
+
config?: AxiosRequestConfig;
|
|
191
192
|
}
|
|
192
193
|
declare const PermissionButton: FC<PropsWithChildren<PermissionButtonProps>>;
|
|
193
194
|
|
|
@@ -255,6 +256,7 @@ declare const RequireGame: FC<PropsWithChildren>;
|
|
|
255
256
|
|
|
256
257
|
interface RequirePermissionProps {
|
|
257
258
|
code: string;
|
|
259
|
+
config?: AxiosRequestConfig;
|
|
258
260
|
}
|
|
259
261
|
declare const RequirePermission: FC<PropsWithChildren<RequirePermissionProps>>;
|
|
260
262
|
|
|
@@ -437,7 +439,7 @@ interface MenuListItem {
|
|
|
437
439
|
ext: string;
|
|
438
440
|
}
|
|
439
441
|
|
|
440
|
-
declare const usePermissions: (codes?: string[]) => {
|
|
442
|
+
declare const usePermissions: (codes?: string[], config?: AxiosRequestConfig) => {
|
|
441
443
|
data: Record<string, boolean>;
|
|
442
444
|
error: any;
|
|
443
445
|
mutate: swr.KeyedMutator<{
|
|
@@ -446,7 +448,7 @@ declare const usePermissions: (codes?: string[]) => {
|
|
|
446
448
|
isValidating: boolean;
|
|
447
449
|
isLoading: boolean;
|
|
448
450
|
};
|
|
449
|
-
declare const usePermission: (code?: string) => {
|
|
451
|
+
declare const usePermission: (code?: string, config?: AxiosRequestConfig) => {
|
|
450
452
|
accessible: boolean;
|
|
451
453
|
isValidating: boolean;
|
|
452
454
|
isLoading: boolean;
|
package/lib/index.js
CHANGED
|
@@ -19,7 +19,6 @@ import { produce } from 'immer';
|
|
|
19
19
|
import qs from 'query-string';
|
|
20
20
|
import useSWRInfinite from 'swr/infinite';
|
|
21
21
|
import dayjs from 'dayjs';
|
|
22
|
-
import useSWRImmutable from 'swr/immutable';
|
|
23
22
|
|
|
24
23
|
var __defProp = Object.defineProperty;
|
|
25
24
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
@@ -282,85 +281,85 @@ var init_Interceptors = __esm({
|
|
|
282
281
|
getGameId,
|
|
283
282
|
permissionVersion
|
|
284
283
|
} = useToolkitsStore((s) => s);
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
if (!headers.has(APP_ID_HEADER) && permissionVersion !== "v1" /* V1 */) {
|
|
297
|
-
const gameId = getGameId();
|
|
298
|
-
if (isGlobal || !gameId) {
|
|
299
|
-
headers.set(APP_ID_HEADER, "global");
|
|
300
|
-
} else {
|
|
301
|
-
headers.set(APP_ID_HEADER, gameId);
|
|
284
|
+
useEffect(() => {
|
|
285
|
+
let requestInterceptorId;
|
|
286
|
+
let responseInterceptorId;
|
|
287
|
+
if (interceptors?.request) {
|
|
288
|
+
requestInterceptorId = axios2.interceptors.request.use(...interceptors.request);
|
|
289
|
+
} else {
|
|
290
|
+
requestInterceptorId = axios2.interceptors.request.use((config) => {
|
|
291
|
+
const headers = new AxiosHeaders(config.headers);
|
|
292
|
+
config.responseType = config.responseType || "json";
|
|
293
|
+
if (token) {
|
|
294
|
+
headers.setAuthorization(`Bearer ${token}`);
|
|
302
295
|
}
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
});
|
|
308
|
-
}
|
|
309
|
-
if (interceptors?.response) {
|
|
310
|
-
responseInterceptorId = axios2.interceptors.response.use(...interceptors.response);
|
|
311
|
-
} else {
|
|
312
|
-
responseInterceptorId = axios2.interceptors.response.use(
|
|
313
|
-
(response) => {
|
|
314
|
-
const responseType = response.request.responseType || "json";
|
|
315
|
-
if (responseType === "json") {
|
|
316
|
-
const data = response.data;
|
|
317
|
-
if (data.code === 0 || data.code === 200 || data.status === 0 || data.errno === 0) {
|
|
318
|
-
return response;
|
|
296
|
+
if (!headers.has(APP_ID_HEADER) && permissionVersion !== "v1" /* V1 */) {
|
|
297
|
+
const gameId = getGameId();
|
|
298
|
+
if (isGlobal || !gameId) {
|
|
299
|
+
headers.set(APP_ID_HEADER, "global");
|
|
319
300
|
} else {
|
|
320
|
-
|
|
321
|
-
message: "Request failed",
|
|
322
|
-
description: data.msg
|
|
323
|
-
});
|
|
324
|
-
throw new Error(data.msg);
|
|
301
|
+
headers.set(APP_ID_HEADER, gameId);
|
|
325
302
|
}
|
|
326
303
|
}
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
304
|
+
headers.set("Accept", config.responseType === "blob" ? "application/octet-stream" : "application/json");
|
|
305
|
+
config.headers = headers;
|
|
306
|
+
return config;
|
|
307
|
+
});
|
|
308
|
+
}
|
|
309
|
+
if (interceptors?.response) {
|
|
310
|
+
responseInterceptorId = axios2.interceptors.response.use(...interceptors.response);
|
|
311
|
+
} else {
|
|
312
|
+
responseInterceptorId = axios2.interceptors.response.use(
|
|
313
|
+
(response) => {
|
|
314
|
+
const responseType = response.request.responseType || "json";
|
|
315
|
+
if (responseType === "json") {
|
|
316
|
+
const data = response.data;
|
|
317
|
+
if (data.code === 0 || data.code === 200 || data.status === 0 || data.errno === 0) {
|
|
318
|
+
return response;
|
|
319
|
+
} else {
|
|
320
|
+
notification.error({
|
|
321
|
+
message: "Request failed",
|
|
322
|
+
description: data.msg
|
|
323
|
+
});
|
|
324
|
+
throw new Error(data.msg);
|
|
325
|
+
}
|
|
334
326
|
}
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
327
|
+
return response;
|
|
328
|
+
},
|
|
329
|
+
(error) => {
|
|
330
|
+
if (isAxiosError(error)) {
|
|
331
|
+
const response = error.response;
|
|
332
|
+
if (!response) {
|
|
333
|
+
throw error;
|
|
334
|
+
}
|
|
335
|
+
if (response.status === 401 || response.status === 412) {
|
|
336
|
+
clearToken();
|
|
337
|
+
if (response.status === 412) {
|
|
338
|
+
setUnregistered();
|
|
339
|
+
}
|
|
340
|
+
window.location.replace(signInPath);
|
|
341
|
+
} else if (response.status === 403) {
|
|
342
|
+
notification.error({
|
|
343
|
+
message: "Forbidden",
|
|
344
|
+
description: "You do not have permission to access this resource."
|
|
345
|
+
});
|
|
346
|
+
} else {
|
|
347
|
+
notification.error({
|
|
348
|
+
message: "Request failed",
|
|
349
|
+
description: response.data.msg
|
|
350
|
+
});
|
|
351
|
+
throw new Error(response.data.msg);
|
|
339
352
|
}
|
|
340
|
-
window.location.replace(signInPath);
|
|
341
|
-
} else if (response.status === 403) {
|
|
342
|
-
notification.error({
|
|
343
|
-
message: "Forbidden",
|
|
344
|
-
description: "You do not have permission to access this resource."
|
|
345
|
-
});
|
|
346
|
-
} else {
|
|
347
|
-
notification.error({
|
|
348
|
-
message: "Request failed",
|
|
349
|
-
description: response.data.msg
|
|
350
|
-
});
|
|
351
|
-
throw new Error(response.data.msg);
|
|
352
353
|
}
|
|
354
|
+
throw error;
|
|
353
355
|
}
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
);
|
|
357
|
-
}
|
|
358
|
-
useEffect(() => {
|
|
356
|
+
);
|
|
357
|
+
}
|
|
359
358
|
return () => {
|
|
360
359
|
axios2.interceptors.request.eject(requestInterceptorId);
|
|
361
360
|
axios2.interceptors.response.eject(responseInterceptorId);
|
|
362
361
|
};
|
|
363
|
-
}, []);
|
|
362
|
+
}, [axios2, interceptors, token, isGlobal, signInPath, clearToken, setUnregistered, getGameId, permissionVersion]);
|
|
364
363
|
return children;
|
|
365
364
|
};
|
|
366
365
|
Interceptors_default = Interceptors;
|
|
@@ -522,25 +521,28 @@ var init_highlight = __esm({
|
|
|
522
521
|
}
|
|
523
522
|
});
|
|
524
523
|
function useMenuList() {
|
|
525
|
-
const { getGameId, signInPath, axios: axios2 } = useToolkitsStore((s) => s);
|
|
524
|
+
const { getGameId, signInPath, axios: axios2, token } = useToolkitsStore((s) => s);
|
|
526
525
|
const gameId = getGameId();
|
|
527
526
|
return useSWR5(
|
|
528
527
|
window.location.pathname !== signInPath ? ["/api/usystem/menu/navbar", gameId] : null,
|
|
529
|
-
([url4]) => axios2(url4
|
|
528
|
+
([url4]) => axios2(url4, {
|
|
529
|
+
headers: { Authorization: `Bearer ${token}`, [APP_ID_HEADER]: gameId }
|
|
530
|
+
}).then((response) => response.data.data)
|
|
530
531
|
);
|
|
531
532
|
}
|
|
532
533
|
var usePermissions, usePermission;
|
|
533
534
|
var init_hooks2 = __esm({
|
|
534
535
|
"src/hooks/index.ts"() {
|
|
535
536
|
init_toolkitsProvider();
|
|
536
|
-
|
|
537
|
+
init_constants();
|
|
538
|
+
usePermissions = (codes = [], config) => {
|
|
537
539
|
const { axios: axios2, permissionVersion } = useToolkitsStore((s) => s);
|
|
538
540
|
const { data, ...rest } = useSWR5(
|
|
539
541
|
codes.length ? [
|
|
540
542
|
permissionVersion !== "v1" /* V1 */ ? "/api/usystem/user/checkV2" : "/api/usystem/user/check",
|
|
541
543
|
{ permissions: codes }
|
|
542
544
|
] : null,
|
|
543
|
-
([url4, body]) => axios2.post(url4, body).then((response) => response.data.data)
|
|
545
|
+
([url4, body]) => axios2.post(url4, body, config).then((response) => response.data.data)
|
|
544
546
|
);
|
|
545
547
|
const newData = codes.reduce((acc, curr) => {
|
|
546
548
|
acc[curr] = data?.has_all ? true : data?.[curr] ?? false;
|
|
@@ -548,8 +550,8 @@ var init_hooks2 = __esm({
|
|
|
548
550
|
}, {});
|
|
549
551
|
return { ...rest, data: newData };
|
|
550
552
|
};
|
|
551
|
-
usePermission = (code) => {
|
|
552
|
-
const { data, isValidating, isLoading } = usePermissions(code ? [code] : void 0);
|
|
553
|
+
usePermission = (code, config) => {
|
|
554
|
+
const { data, isValidating, isLoading } = usePermissions(code ? [code] : void 0, config);
|
|
553
555
|
return {
|
|
554
556
|
accessible: code ? data?.[code] : true,
|
|
555
557
|
isValidating,
|
|
@@ -564,9 +566,9 @@ var init_hooks3 = __esm({
|
|
|
564
566
|
init_constants();
|
|
565
567
|
init_toolkitsProvider();
|
|
566
568
|
useGames = () => {
|
|
567
|
-
const { axios: axios2, gameApiV2 } = useToolkitsStore((s) => s);
|
|
569
|
+
const { axios: axios2, gameApiV2, token } = useToolkitsStore((s) => s);
|
|
568
570
|
return useSWR5("/api/game/list", async () => {
|
|
569
|
-
const headers = new AxiosHeaders({ [APP_ID_HEADER]: "global" });
|
|
571
|
+
const headers = new AxiosHeaders({ [APP_ID_HEADER]: "global", Authorization: `Bearer ${token}` });
|
|
570
572
|
const games = gameApiV2 ? await axios2({
|
|
571
573
|
url: "/api/game/list",
|
|
572
574
|
headers
|
|
@@ -835,15 +837,26 @@ var init_GameSelect = __esm({
|
|
|
835
837
|
const { t } = useTranslation();
|
|
836
838
|
const { gameApiV2, setGame, getGameId } = useToolkitsStore((s) => s);
|
|
837
839
|
const { data, isLoading } = useGames();
|
|
840
|
+
const defaultValue = getGameId();
|
|
841
|
+
const [internalValue, setInternalValue] = useState(defaultValue);
|
|
838
842
|
const options = data?.filter((item) => filter?.(item) ?? true)?.map((item) => ({
|
|
839
843
|
label: item.name,
|
|
840
844
|
value: gameApiV2 ? item.game_id : item.id
|
|
841
845
|
}));
|
|
842
|
-
const
|
|
843
|
-
|
|
846
|
+
const findGame = (value) => data?.find((item) => String(gameApiV2 ? item.game_id : item.id) === String(value));
|
|
847
|
+
const onChange = async (value) => {
|
|
848
|
+
const game = findGame(value);
|
|
844
849
|
setGame(game);
|
|
850
|
+
setInternalValue(value);
|
|
845
851
|
};
|
|
846
|
-
|
|
852
|
+
useEffect(() => {
|
|
853
|
+
if (data?.every((item) => String(gameApiV2 ? item.game_id : item.id) !== defaultValue)) {
|
|
854
|
+
const gameId = gameApiV2 ? data?.[0]?.game_id : data?.[0]?.id;
|
|
855
|
+
setInternalValue(gameId);
|
|
856
|
+
const game = findGame(gameId);
|
|
857
|
+
setGame(game);
|
|
858
|
+
}
|
|
859
|
+
}, [data]);
|
|
847
860
|
return /* @__PURE__ */ jsxs(Space, { children: [
|
|
848
861
|
/* @__PURE__ */ jsx(Text, { children: t("GameSelect.label") }),
|
|
849
862
|
/* @__PURE__ */ jsx(
|
|
@@ -851,7 +864,7 @@ var init_GameSelect = __esm({
|
|
|
851
864
|
{
|
|
852
865
|
showSearch: true,
|
|
853
866
|
optionFilterProp: "label",
|
|
854
|
-
value,
|
|
867
|
+
value: internalValue,
|
|
855
868
|
placeholder: t("GameSelect.placeholder"),
|
|
856
869
|
loading: isLoading,
|
|
857
870
|
style: { width: "200px" },
|
|
@@ -1136,9 +1149,9 @@ var init_PermissionButton = __esm({
|
|
|
1136
1149
|
init_hooks2();
|
|
1137
1150
|
init_locale();
|
|
1138
1151
|
PermissionButton = (props) => {
|
|
1139
|
-
const { children, code, showLoading, disabled, ...restProps } = props;
|
|
1152
|
+
const { children, code, showLoading, disabled, config, ...restProps } = props;
|
|
1140
1153
|
const codes = code ? Array.isArray(code) ? code : [code] : [];
|
|
1141
|
-
const { data, isLoading } = usePermissions(codes);
|
|
1154
|
+
const { data, isLoading } = usePermissions(codes, config);
|
|
1142
1155
|
const { t } = useTranslation();
|
|
1143
1156
|
if (isLoading) {
|
|
1144
1157
|
return /* @__PURE__ */ jsx(Button, { loading: showLoading, disabled: !showLoading, ...restProps, children });
|
|
@@ -1800,9 +1813,8 @@ function useAllPermissionsV2() {
|
|
|
1800
1813
|
}
|
|
1801
1814
|
function useAllRoles() {
|
|
1802
1815
|
const { axios: axios2 } = useToolkitsStore((s) => s);
|
|
1803
|
-
const { accessible } = usePermission("200005");
|
|
1804
1816
|
return useSWR5(
|
|
1805
|
-
|
|
1817
|
+
"/api/usystem/role/all",
|
|
1806
1818
|
(url4) => axios2.get(url4).then((response) => response.data.data)
|
|
1807
1819
|
);
|
|
1808
1820
|
}
|
|
@@ -1875,7 +1887,6 @@ var init_hooks5 = __esm({
|
|
|
1875
1887
|
init_modal2();
|
|
1876
1888
|
init_toolkitsProvider();
|
|
1877
1889
|
init_constants();
|
|
1878
|
-
init_hooks2();
|
|
1879
1890
|
init_components();
|
|
1880
1891
|
({ Text: Text2 } = Typography);
|
|
1881
1892
|
useCreateRoleModal = ({ onSuccess } = {}) => {
|
|
@@ -3273,8 +3284,8 @@ init_requireGame();
|
|
|
3273
3284
|
init_hooks2();
|
|
3274
3285
|
init_locale();
|
|
3275
3286
|
var RequirePermission = (props) => {
|
|
3276
|
-
const { code, children } = props;
|
|
3277
|
-
const { accessible, isValidating } = usePermission(code);
|
|
3287
|
+
const { code, config, children } = props;
|
|
3288
|
+
const { accessible, isValidating } = usePermission(code, config);
|
|
3278
3289
|
const { t } = useTranslation();
|
|
3279
3290
|
if (isValidating) {
|
|
3280
3291
|
return /* @__PURE__ */ jsx(
|
|
@@ -3440,10 +3451,11 @@ var SignIn = (props) => {
|
|
|
3440
3451
|
const { title, successRedirectUrl, extra } = props;
|
|
3441
3452
|
const unregistered = useToolkitsStore((s) => s.unregistered);
|
|
3442
3453
|
const queryParams = new URLSearchParams(window.location.search);
|
|
3443
|
-
const { token, setToken } = useToolkitsStore((state) => state);
|
|
3454
|
+
const { token, setToken, axios: axios2 } = useToolkitsStore((state) => state);
|
|
3444
3455
|
const { t } = useTranslation();
|
|
3445
|
-
const { isLoading } =
|
|
3456
|
+
const { isLoading } = useSWR5(
|
|
3446
3457
|
queryParams.has("ticket") ? `/api/usystem/user/login?ticket=${queryParams.get("ticket")}` : null,
|
|
3458
|
+
(url4) => axios2.get(url4).then((res) => res.data.data),
|
|
3447
3459
|
{
|
|
3448
3460
|
onSuccess: (data) => {
|
|
3449
3461
|
if (data) {
|