react-toolkits 2.11.2 → 2.11.3
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 +25 -2
- package/lib/index.js +76 -78
- package/lib/index.js.map +1 -1
- package/locale/hooks.js +3 -4
- package/locale/hooks.js.map +1 -1
- package/locale/index.js +3 -4
- package/locale/index.js.map +1 -1
- package/package.json +3 -3
package/CHANGELOG.md
CHANGED
package/lib/index.d.ts
CHANGED
|
@@ -366,7 +366,7 @@ declare const createToolkitsStore: (initProps?: Partial<ContextSlice>) => Omit<z
|
|
|
366
366
|
};
|
|
367
367
|
|
|
368
368
|
type ToolkitsStore = ReturnType<typeof createToolkitsStore>;
|
|
369
|
-
declare function useToolkitsStore<T>(selector: (state: ToolkitsState
|
|
369
|
+
declare function useToolkitsStore<T>(selector: (state: ToolkitsState) => T): T;
|
|
370
370
|
type ToolkitsProviderProps = PropsWithChildren<Partial<ContextSlice>>;
|
|
371
371
|
declare let toolkitsStore: ToolkitsStore;
|
|
372
372
|
declare const ToolkitsProvider: FC<ToolkitsProviderProps>;
|
|
@@ -436,7 +436,30 @@ declare function usePermission(code?: string, config?: Omit<AxiosRequestConfig,
|
|
|
436
436
|
isLoading: boolean;
|
|
437
437
|
};
|
|
438
438
|
|
|
439
|
-
|
|
439
|
+
interface Permission {
|
|
440
|
+
label: string;
|
|
441
|
+
value: string;
|
|
442
|
+
route: string;
|
|
443
|
+
method?: string;
|
|
444
|
+
}
|
|
445
|
+
interface MenuListItem {
|
|
446
|
+
id: number;
|
|
447
|
+
category: string;
|
|
448
|
+
is_common: boolean;
|
|
449
|
+
is_model: boolean;
|
|
450
|
+
model_name: 'change' | 'recharge';
|
|
451
|
+
type: string;
|
|
452
|
+
permissions: Permission[];
|
|
453
|
+
front_route: string;
|
|
454
|
+
order: number;
|
|
455
|
+
}
|
|
456
|
+
|
|
457
|
+
declare function useMenuList(): swr.SWRResponse<MenuListItem[], any, any>;
|
|
458
|
+
|
|
459
|
+
declare const MenuItemList: {
|
|
460
|
+
(): react_jsx_runtime.JSX.Element;
|
|
461
|
+
useMenuList: typeof useMenuList;
|
|
462
|
+
};
|
|
440
463
|
|
|
441
464
|
interface NotFoundProps {
|
|
442
465
|
redirectUrl?: string;
|
package/lib/index.js
CHANGED
|
@@ -1,11 +1,10 @@
|
|
|
1
1
|
import axios, { AxiosHeaders } from 'axios';
|
|
2
2
|
import { jwtDecode } from 'jwt-decode';
|
|
3
|
-
import { create, createStore } from 'zustand';
|
|
3
|
+
import { create, useStore, createStore } from 'zustand';
|
|
4
4
|
import { persist, createJSONStorage } from 'zustand/middleware';
|
|
5
5
|
import * as Antd2 from 'antd';
|
|
6
6
|
import { Spin, Menu, Modal, Form, App, theme, Space, Input, Tag, Typography, Result, Table, Button, Empty, Dropdown, Divider, Card, Select, Alert, Row, Col, Breadcrumb, Skeleton, Descriptions, Switch, Popconfirm, Tooltip, Collapse, Checkbox } from 'antd';
|
|
7
7
|
import { memo, useMemo, useCallback, useEffect, lazy, useContext, useState, useRef, Fragment as Fragment$1, Suspense, createContext, forwardRef, useImperativeHandle, cloneElement } from 'react';
|
|
8
|
-
import { useStoreWithEqualityFn } from 'zustand/traditional';
|
|
9
8
|
import { jsx, jsxs, Fragment } from 'react/jsx-runtime';
|
|
10
9
|
import { has, template, get, isEqual } from 'lodash-es';
|
|
11
10
|
import { flushSync } from 'react-dom';
|
|
@@ -276,87 +275,85 @@ var init_axios = __esm({
|
|
|
276
275
|
Interceptor = ({ children }) => {
|
|
277
276
|
const state = useToolkitsStore((s) => s);
|
|
278
277
|
const { notification } = App.useApp();
|
|
279
|
-
|
|
278
|
+
if (requestInterceptorId) {
|
|
280
279
|
instance.interceptors.request.eject(requestInterceptorId);
|
|
280
|
+
}
|
|
281
|
+
if (responseInterceptorId) {
|
|
281
282
|
instance.interceptors.response.eject(responseInterceptorId);
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
283
|
+
}
|
|
284
|
+
const interceptors = state.interceptors;
|
|
285
|
+
if (interceptors?.request) {
|
|
286
|
+
requestInterceptorId = instance.interceptors.request.use(...interceptors.request);
|
|
287
|
+
} else {
|
|
288
|
+
requestInterceptorId = instance.interceptors.request.use((config) => {
|
|
289
|
+
const headers = new AxiosHeaders(config.headers);
|
|
290
|
+
config.responseType = config.responseType || "json";
|
|
291
|
+
if (state.token) {
|
|
292
|
+
headers.set("Authorization", `Bearer ${state.token}`);
|
|
293
|
+
}
|
|
294
|
+
if (!headers.has(APP_ID_HEADER) && state.usePermissionApiV2 && state.game) {
|
|
295
|
+
if (state.gameApiV2) {
|
|
296
|
+
headers.set(APP_ID_HEADER, state.game.game_id);
|
|
297
|
+
} else {
|
|
298
|
+
headers.set(APP_ID_HEADER, state.game.id);
|
|
291
299
|
}
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
300
|
+
}
|
|
301
|
+
headers.set("Accept", config.responseType === "blob" ? "application/octet-stream" : "application/json");
|
|
302
|
+
config.headers = headers;
|
|
303
|
+
return config;
|
|
304
|
+
});
|
|
305
|
+
}
|
|
306
|
+
if (interceptors?.response) {
|
|
307
|
+
responseInterceptorId = instance.interceptors.response.use(...interceptors.response);
|
|
308
|
+
} else {
|
|
309
|
+
responseInterceptorId = instance.interceptors.response.use(
|
|
310
|
+
(response) => {
|
|
311
|
+
const responseType = response.request.responseType || "json";
|
|
312
|
+
if (responseType === "json") {
|
|
313
|
+
const data = response.data;
|
|
314
|
+
if (data.code === 0 || data.code === 200 || data.status === 0 || data.errno === 0) {
|
|
315
|
+
return response;
|
|
295
316
|
} else {
|
|
296
|
-
|
|
317
|
+
notification.error({
|
|
318
|
+
message: "Request failed",
|
|
319
|
+
description: data.msg
|
|
320
|
+
});
|
|
321
|
+
throw new Error(data.msg);
|
|
297
322
|
}
|
|
298
323
|
}
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
} else {
|
|
307
|
-
responseInterceptorId = instance.interceptors.response.use(
|
|
308
|
-
(response) => {
|
|
309
|
-
const responseType = response.request.responseType || "json";
|
|
310
|
-
if (responseType === "json") {
|
|
311
|
-
const data = response.data;
|
|
312
|
-
if (data.code === 0 || data.code === 200 || data.status === 0 || data.errno === 0) {
|
|
313
|
-
return response;
|
|
314
|
-
} else {
|
|
315
|
-
notification.error({
|
|
316
|
-
message: "Request failed",
|
|
317
|
-
description: data.msg
|
|
318
|
-
});
|
|
319
|
-
throw new Error(data.msg);
|
|
320
|
-
}
|
|
324
|
+
return response;
|
|
325
|
+
},
|
|
326
|
+
(error) => {
|
|
327
|
+
if (axios.isAxiosError(error)) {
|
|
328
|
+
const response = error.response;
|
|
329
|
+
if (!response) {
|
|
330
|
+
throw error;
|
|
321
331
|
}
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
if (!response) {
|
|
328
|
-
throw error;
|
|
329
|
-
}
|
|
330
|
-
if (response.status === 401 || response.status === 412) {
|
|
331
|
-
state.clearToken?.();
|
|
332
|
-
if (state.signInPath) {
|
|
333
|
-
if (response.status === 412) ;
|
|
334
|
-
window.location.replace(state?.signInPath);
|
|
335
|
-
} else {
|
|
336
|
-
throw new Error("\u8BF7\u5728 ToolkitsProvider \u4E2D\u914D\u7F6E signInPath");
|
|
337
|
-
}
|
|
338
|
-
} else if (response.status === 403) {
|
|
339
|
-
notification.error({
|
|
340
|
-
message: "Forbidden",
|
|
341
|
-
description: "You do not have permission to access this resource."
|
|
342
|
-
});
|
|
332
|
+
if (response.status === 401 || response.status === 412) {
|
|
333
|
+
state.clearToken?.();
|
|
334
|
+
if (state.signInPath) {
|
|
335
|
+
if (response.status === 412) ;
|
|
336
|
+
window.location.replace(state?.signInPath);
|
|
343
337
|
} else {
|
|
344
|
-
|
|
345
|
-
message: "Request failed",
|
|
346
|
-
description: response.data.msg
|
|
347
|
-
});
|
|
348
|
-
throw new Error(response.data.msg);
|
|
338
|
+
throw new Error("\u8BF7\u5728 ToolkitsProvider \u4E2D\u914D\u7F6E signInPath");
|
|
349
339
|
}
|
|
340
|
+
} else if (response.status === 403) {
|
|
341
|
+
notification.error({
|
|
342
|
+
message: "Forbidden",
|
|
343
|
+
description: "You do not have permission to access this resource."
|
|
344
|
+
});
|
|
345
|
+
} else {
|
|
346
|
+
notification.error({
|
|
347
|
+
message: "Request failed",
|
|
348
|
+
description: response.data.msg
|
|
349
|
+
});
|
|
350
|
+
throw new Error(response.data.msg);
|
|
350
351
|
}
|
|
351
|
-
throw error;
|
|
352
352
|
}
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
instance.interceptors.response.eject(responseInterceptorId);
|
|
358
|
-
};
|
|
359
|
-
}, [state]);
|
|
353
|
+
throw error;
|
|
354
|
+
}
|
|
355
|
+
);
|
|
356
|
+
}
|
|
360
357
|
return children;
|
|
361
358
|
};
|
|
362
359
|
}
|
|
@@ -364,7 +361,7 @@ var init_axios = __esm({
|
|
|
364
361
|
function useToolkitsStore(selector) {
|
|
365
362
|
const store = useContext(ToolkitsContext);
|
|
366
363
|
if (!store) throw new Error("Missing ToolkitsProvider in the tree");
|
|
367
|
-
return
|
|
364
|
+
return useStore(store, selector);
|
|
368
365
|
}
|
|
369
366
|
var ToolkitsContext, toolkitsStore, ToolkitsProvider, Provider_default;
|
|
370
367
|
var init_Provider = __esm({
|
|
@@ -378,7 +375,7 @@ var init_Provider = __esm({
|
|
|
378
375
|
if (!storeRef.current) {
|
|
379
376
|
storeRef.current = createToolkitsStore(restProps);
|
|
380
377
|
}
|
|
381
|
-
return /* @__PURE__ */ jsx(
|
|
378
|
+
return /* @__PURE__ */ jsx(ToolkitsContext.Provider, { value: storeRef.current, children: /* @__PURE__ */ jsx(Interceptor, { children }) });
|
|
382
379
|
};
|
|
383
380
|
if (process.env.NODE_ENV !== "production") {
|
|
384
381
|
ToolkitsProvider.displayName = "ToolkitsProvider";
|
|
@@ -2419,23 +2416,23 @@ init_toolkitsProvider();
|
|
|
2419
2416
|
init_axios();
|
|
2420
2417
|
function useCreateMenu() {
|
|
2421
2418
|
return useSWRMutation2(
|
|
2422
|
-
"/api/usystem/
|
|
2419
|
+
"/api/usystem/menu/set",
|
|
2423
2420
|
(url4, { arg }) => instance.post(url4, { ...arg, id: 0 })
|
|
2424
2421
|
);
|
|
2425
2422
|
}
|
|
2426
2423
|
function useUpdateMenu() {
|
|
2427
|
-
return useSWRMutation2("/api/usystem/
|
|
2424
|
+
return useSWRMutation2("/api/usystem/menu/set", (url4, { arg }) => instance.post(url4, arg));
|
|
2428
2425
|
}
|
|
2429
2426
|
function useMenuList() {
|
|
2430
2427
|
const game = useToolkitsStore((state) => state.game);
|
|
2431
2428
|
return useSWRImmutable(
|
|
2432
|
-
["/api/usystem/
|
|
2429
|
+
["/api/usystem/menu/navbar", game],
|
|
2433
2430
|
([url4]) => instance(url4).then((response) => response.data.data)
|
|
2434
2431
|
);
|
|
2435
2432
|
}
|
|
2436
2433
|
function useRemoveMenu() {
|
|
2437
2434
|
return useSWRMutation2(
|
|
2438
|
-
"/api/usystem/
|
|
2435
|
+
"/api/usystem/menu/delete",
|
|
2439
2436
|
(url4, { arg }) => instance.post(url4, null, { params: { id: arg } })
|
|
2440
2437
|
);
|
|
2441
2438
|
}
|
|
@@ -2625,6 +2622,7 @@ var MenuItemList = () => {
|
|
|
2625
2622
|
updateModal
|
|
2626
2623
|
] });
|
|
2627
2624
|
};
|
|
2625
|
+
MenuItemList.useMenuList = useMenuList;
|
|
2628
2626
|
var menu_default = MenuItemList;
|
|
2629
2627
|
|
|
2630
2628
|
// src/pages/notFound/index.tsx
|