react-toolkits 2.11.0 → 2.11.2

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/lib/index.js CHANGED
@@ -1,9 +1,9 @@
1
- import axios2, { AxiosHeaders } from 'axios';
1
+ import axios, { AxiosHeaders } from 'axios';
2
2
  import { jwtDecode } from 'jwt-decode';
3
3
  import { create, createStore } from 'zustand';
4
4
  import { persist, createJSONStorage } from 'zustand/middleware';
5
5
  import * as Antd2 from 'antd';
6
- import { Spin, Menu, Modal, Form, theme, Space, Input, Tag, Typography, Result, Table, Button, Empty, Dropdown, Divider, Card, Select, Alert, App, Row, Col, Breadcrumb, Skeleton, Descriptions, Tooltip, notification, Collapse, Checkbox } from 'antd';
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
8
  import { useStoreWithEqualityFn } from 'zustand/traditional';
9
9
  import { jsx, jsxs, Fragment } from 'react/jsx-runtime';
@@ -12,7 +12,7 @@ import { flushSync } from 'react-dom';
12
12
  import { createRoot } from 'react-dom/client';
13
13
  import useSWR, { mutate, unstable_serialize } from 'swr';
14
14
  import useSWRImmutable from 'swr/immutable';
15
- import useSWRMutation from 'swr/mutation';
15
+ import useSWRMutation2 from 'swr/mutation';
16
16
  import { PlusOutlined, LogoutOutlined, UserOutlined, MenuUnfoldOutlined, MenuFoldOutlined, UserAddOutlined, UsergroupAddOutlined } from '@ant-design/icons';
17
17
  import { produce } from 'immer';
18
18
  import { useLocation, Routes, Route, Navigate, Link, useNavigate, useParams } from 'react-router-dom';
@@ -43,7 +43,7 @@ var init_storage = __esm({
43
43
  sessionStorage.setItem(name, value);
44
44
  localStorage.setItem(name, value);
45
45
  },
46
- removeItem: async (name) => {
46
+ removeItem(name) {
47
47
  sessionStorage.removeItem(name);
48
48
  localStorage.removeItem(name);
49
49
  }
@@ -177,10 +177,10 @@ var init_game = __esm({
177
177
  set({ isLoading: true });
178
178
  let games;
179
179
  if (apiV2) {
180
- const response = await axios2.get("/api/game/list");
180
+ const response = await axios.get("/api/game/list");
181
181
  games = response.data.data.list ?? [];
182
182
  } else {
183
- const response = await axios2.get("/api/usystem/game/all");
183
+ const response = await axios.get("/api/usystem/game/all");
184
184
  games = response.data.data ?? [];
185
185
  }
186
186
  set({ games });
@@ -204,7 +204,7 @@ var init_token = __esm({
204
204
  if (token) {
205
205
  try {
206
206
  return jwtDecode(token);
207
- } catch (_) {
207
+ } catch (error) {
208
208
  return null;
209
209
  }
210
210
  }
@@ -262,101 +262,103 @@ var init_constants = __esm({
262
262
  APP_ID_HEADER = "App-ID";
263
263
  }
264
264
  });
265
- var instance, requestInterceptorId, responseInterceptorId, registerInterceptors, axios_default;
265
+ var instance, requestInterceptorId, responseInterceptorId, Interceptor;
266
266
  var init_axios = __esm({
267
- "src/utils/axios.ts"() {
267
+ "src/utils/axios.tsx"() {
268
268
  init_toolkitsProvider();
269
269
  init_constants();
270
- instance = axios2.create({
270
+ instance = axios.create({
271
271
  baseURL: "/",
272
272
  headers: {
273
273
  "Content-Type": "application/json; charset=utf-8"
274
274
  }
275
275
  });
276
- registerInterceptors = () => {
277
- const state = toolkitsStore?.getState() ?? {};
278
- if (requestInterceptorId) {
276
+ Interceptor = ({ children }) => {
277
+ const state = useToolkitsStore((s) => s);
278
+ const { notification } = App.useApp();
279
+ useEffect(() => {
279
280
  instance.interceptors.request.eject(requestInterceptorId);
280
- }
281
- if (responseInterceptorId) {
282
281
  instance.interceptors.response.eject(responseInterceptorId);
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);
282
+ const interceptors = state.interceptors;
283
+ if (interceptors?.request) {
284
+ requestInterceptorId = instance.interceptors.request.use(...interceptors.request);
285
+ } else {
286
+ requestInterceptorId = instance.interceptors.request.use((config) => {
287
+ const headers = new AxiosHeaders(config.headers);
288
+ config.responseType = config.responseType || "json";
289
+ if (state.token) {
290
+ headers.set("Authorization", `Bearer ${state.token}`);
299
291
  }
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) {
315
- return response;
292
+ if (!headers.has(APP_ID_HEADER) && state.usePermissionApiV2 && state.game) {
293
+ if (state.gameApiV2) {
294
+ headers.set(APP_ID_HEADER, state.game.game_id);
316
295
  } else {
317
- notification.error({
318
- message: "Request failed",
319
- description: data.msg
320
- });
321
- throw new Error(data.msg);
296
+ headers.set(APP_ID_HEADER, state.game.id);
322
297
  }
323
298
  }
324
- return response;
325
- },
326
- (error) => {
327
- console.log(axios2.isAxiosError(error));
328
- if (axios2.isAxiosError(error)) {
329
- const response = error.response;
330
- if (!response) {
331
- throw error;
299
+ headers.set("Accept", config.responseType === "blob" ? "application/octet-stream" : "application/json");
300
+ config.headers = headers;
301
+ return config;
302
+ });
303
+ }
304
+ if (interceptors?.response) {
305
+ responseInterceptorId = instance.interceptors.response.use(...interceptors.response);
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
+ }
332
321
  }
333
- if (response.status === 401 || response.status === 412) {
334
- state?.clearToken();
335
- if (state.signInPath) {
336
- if (response.status === 412) ;
337
- window.location.replace(state?.signInPath);
322
+ return response;
323
+ },
324
+ (error) => {
325
+ if (axios.isAxiosError(error)) {
326
+ const response = error.response;
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
+ });
338
343
  } else {
339
- throw new Error("\u8BF7\u5728 ContextProvider \u4E2D\u914D\u7F6E signInPath");
344
+ notification.error({
345
+ message: "Request failed",
346
+ description: response.data.msg
347
+ });
348
+ throw new Error(response.data.msg);
340
349
  }
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
350
  }
351
+ throw error;
353
352
  }
354
- throw error;
355
- }
356
- );
357
- }
353
+ );
354
+ }
355
+ return () => {
356
+ instance.interceptors.request.eject(requestInterceptorId);
357
+ instance.interceptors.response.eject(responseInterceptorId);
358
+ };
359
+ }, [state]);
360
+ return children;
358
361
  };
359
- axios_default = instance;
360
362
  }
361
363
  });
362
364
  function useToolkitsStore(selector) {
@@ -376,9 +378,7 @@ var init_Provider = __esm({
376
378
  if (!storeRef.current) {
377
379
  storeRef.current = createToolkitsStore(restProps);
378
380
  }
379
- toolkitsStore = storeRef.current;
380
- registerInterceptors();
381
- return /* @__PURE__ */ jsx(ToolkitsContext.Provider, { value: storeRef.current, children });
381
+ return /* @__PURE__ */ jsx(App, { children: /* @__PURE__ */ jsx(ToolkitsContext.Provider, { value: storeRef.current, children: /* @__PURE__ */ jsx(App, { children: /* @__PURE__ */ jsx(Interceptor, { children }) }) }) });
382
382
  };
383
383
  if (process.env.NODE_ENV !== "production") {
384
384
  ToolkitsProvider.displayName = "ToolkitsProvider";
@@ -502,12 +502,12 @@ var init_axios2 = __esm({
502
502
  "src/hooks/axios.ts"() {
503
503
  init_axios();
504
504
  useSWRAxios = (key, swrConfig) => {
505
- return useSWR(key, (config) => axios_default.request(config).then((response) => response.data.data), swrConfig);
505
+ return useSWR(key, (config) => instance.request(config).then((response) => response.data.data), swrConfig);
506
506
  };
507
507
  useSWRImmutableAxios = (axiosConfig, swrConfig) => {
508
508
  return useSWRImmutable(
509
509
  axiosConfig,
510
- (config) => axios_default.request(config).then((response) => response.data.data),
510
+ (config) => instance.request(config).then((response) => response.data.data),
511
511
  swrConfig
512
512
  );
513
513
  };
@@ -517,8 +517,8 @@ var init_axios2 = __esm({
517
517
  // src/hooks/permission.ts
518
518
  function usePermissions(codes = [], config) {
519
519
  const usePermissionApiV2 = useToolkitsStore((state) => state.usePermissionApiV2);
520
- const url3 = usePermissionApiV2 ? "/api/usystem/user/checkV2" : "/api/usystem/user/check";
521
- const key = codes.length ? { ...config, method: "POST", url: url3, data: { permissions: codes } } : null;
520
+ const url4 = usePermissionApiV2 ? "/api/usystem/user/checkV2" : "/api/usystem/user/check";
521
+ const key = codes.length ? { ...config, method: "POST", url: url4, data: { permissions: codes } } : null;
522
522
  const { data, ...rest } = useSWRAxios(key);
523
523
  const newData = codes.reduce((acc, curr) => {
524
524
  acc[curr] = data?.has_all ? true : data?.[curr] ?? false;
@@ -630,7 +630,7 @@ var init_QueryList = __esm({
630
630
  ...props
631
631
  };
632
632
  const {
633
- url: url3,
633
+ url: url4,
634
634
  code,
635
635
  headers,
636
636
  onePage,
@@ -651,7 +651,7 @@ var init_QueryList = __esm({
651
651
  footer,
652
652
  ...tableProps
653
653
  } = internalProps;
654
- if (!url3) {
654
+ if (!url4) {
655
655
  throw new Error("url property is required");
656
656
  }
657
657
  const { t } = useTranslation();
@@ -664,7 +664,7 @@ var init_QueryList = __esm({
664
664
  const { accessible, isLoading } = usePermission(code, { headers: _headers });
665
665
  const [isValid, setIsValid] = useState(false);
666
666
  const { keyMap, getPayload, refetch } = useQueryListStore();
667
- const { page, size = defaultSize, formValue } = getPayload(url3);
667
+ const { page, size = defaultSize, formValue } = getPayload(url4);
668
668
  const payload = { page, size, formValue };
669
669
  const _body = typeof body === "function" ? body(payload) : method === "POST" && typeof body === "undefined" ? {
670
670
  ...formValue,
@@ -676,7 +676,7 @@ var init_QueryList = __esm({
676
676
  } : void 0;
677
677
  const shouldPoll = useRef(false);
678
678
  const requestConfig = {
679
- url: url3,
679
+ url: url4,
680
680
  method,
681
681
  data: _body,
682
682
  params: _params,
@@ -687,13 +687,13 @@ var init_QueryList = __esm({
687
687
  return null;
688
688
  }
689
689
  const serializedKey = unstable_serialize(requestConfig);
690
- keyMap.set(url3, serializedKey);
690
+ keyMap.set(url4, serializedKey);
691
691
  return serializedKey;
692
- }, [accessible, isValid, url3, requestConfig]);
692
+ }, [accessible, isValid, url4, requestConfig]);
693
693
  const { data, isValidating } = useSWR(
694
694
  key,
695
695
  async () => {
696
- const response = await axios_default.request(requestConfig);
696
+ const response = await instance.request(requestConfig);
697
697
  return response.data.data;
698
698
  },
699
699
  {
@@ -716,7 +716,7 @@ var init_QueryList = __esm({
716
716
  total,
717
717
  onChange: async (currentPage, currentSize) => {
718
718
  action.current = 2 /* Jump */;
719
- refetch(url3, {
719
+ refetch(url4, {
720
720
  page: currentPage,
721
721
  size: currentSize
722
722
  });
@@ -727,7 +727,7 @@ var init_QueryList = __esm({
727
727
  try {
728
728
  await _form.validateFields();
729
729
  setIsValid(true);
730
- refetch(url3, {
730
+ refetch(url4, {
731
731
  page: 1,
732
732
  formValue: _form.getFieldsValue()
733
733
  });
@@ -741,7 +741,7 @@ var init_QueryList = __esm({
741
741
  try {
742
742
  await _form.validateFields({ validateOnly: true });
743
743
  setIsValid(true);
744
- refetch(url3, {
744
+ refetch(url4, {
745
745
  page: 1,
746
746
  formValue: _form.getFieldsValue()
747
747
  });
@@ -757,7 +757,7 @@ var init_QueryList = __esm({
757
757
  try {
758
758
  _form.resetFields();
759
759
  const value = await _form.validateFields({ validateOnly: true });
760
- refetch(url3, {
760
+ refetch(url4, {
761
761
  page: 1,
762
762
  formValue: value
763
763
  });
@@ -766,7 +766,9 @@ var init_QueryList = __esm({
766
766
  setIsValid(false);
767
767
  }
768
768
  };
769
- init();
769
+ setTimeout(() => {
770
+ init();
771
+ }, 300);
770
772
  }, [accessible, form]);
771
773
  useImperativeHandle(ref, () => ({
772
774
  data,
@@ -857,6 +859,7 @@ function useModal(props) {
857
859
  try {
858
860
  setConfirmLoading(true);
859
861
  await onConfirm?.();
862
+ hide();
860
863
  } finally {
861
864
  setConfirmLoading(false);
862
865
  }
@@ -962,52 +965,52 @@ function useRole(name) {
962
965
  }
963
966
  function useCreateRole() {
964
967
  const usePermissionApiV2 = useToolkitsStore((state) => state.usePermissionApiV2);
965
- return useSWRMutation(
968
+ return useSWRMutation2(
966
969
  usePermissionApiV2 ? "/api/usystem/role/createV2" : "/api/usystem/role/create",
967
- (url3, {
970
+ (url4, {
968
971
  arg
969
- }) => axios_default.post(url3, arg, { headers: { [APP_ID_HEADER]: "global" } })
972
+ }) => instance.post(url4, arg, { headers: { [APP_ID_HEADER]: "global" } })
970
973
  );
971
974
  }
972
975
  function useUpdateRole() {
973
976
  const usePermissionApiV2 = useToolkitsStore((state) => state.usePermissionApiV2);
974
- return useSWRMutation(
977
+ return useSWRMutation2(
975
978
  usePermissionApiV2 ? "/api/usystem/role/updateV2" : "/api/usystem/role/update",
976
- (url3, {
979
+ (url4, {
977
980
  arg
978
- }) => axios_default.post(url3, arg, { headers: { [APP_ID_HEADER]: "global" } })
981
+ }) => instance.post(url4, arg, { headers: { [APP_ID_HEADER]: "global" } })
979
982
  );
980
983
  }
981
984
  function useRemoveRole() {
982
- return useSWRMutation(
985
+ return useSWRMutation2(
983
986
  "/api/usystem/role/delete",
984
- (url3, {
987
+ (url4, {
985
988
  arg
986
- }) => axios_default.post(url3, arg, { headers: { [APP_ID_HEADER]: "global" } })
989
+ }) => instance.post(url4, arg, { headers: { [APP_ID_HEADER]: "global" } })
987
990
  );
988
991
  }
989
992
  function useCreateUser() {
990
- return useSWRMutation(
993
+ return useSWRMutation2(
991
994
  "/api/usystem/user/create",
992
- (url3, {
995
+ (url4, {
993
996
  arg
994
- }) => axios_default.post(url3, arg, { headers: { [APP_ID_HEADER]: "global" } })
997
+ }) => instance.post(url4, arg, { headers: { [APP_ID_HEADER]: "global" } })
995
998
  );
996
999
  }
997
1000
  function useUpdateUser() {
998
- return useSWRMutation(
1001
+ return useSWRMutation2(
999
1002
  "/api/usystem/user/update",
1000
- (url3, {
1003
+ (url4, {
1001
1004
  arg
1002
- }) => axios_default.post(url3, arg, { headers: { [APP_ID_HEADER]: "global" } })
1005
+ }) => instance.post(url4, arg, { headers: { [APP_ID_HEADER]: "global" } })
1003
1006
  );
1004
1007
  }
1005
1008
  function useRemoveUser() {
1006
- return useSWRMutation(
1009
+ return useSWRMutation2(
1007
1010
  "/api/usystem/user/delete",
1008
- (url3, {
1011
+ (url4, {
1009
1012
  arg
1010
- }) => axios_default.post(url3, arg, { headers: { [APP_ID_HEADER]: "global" } })
1013
+ }) => instance.post(url4, arg, { headers: { [APP_ID_HEADER]: "global" } })
1011
1014
  );
1012
1015
  }
1013
1016
  var init_hooks2 = __esm({
@@ -1138,14 +1141,14 @@ var init_permissionListV1 = __esm({
1138
1141
  permissionListV1_default = PermissionListV1;
1139
1142
  }
1140
1143
  });
1141
- var Text3, Option2, PermissionListV2, permissionListV2_default;
1144
+ var Text3, Option3, PermissionListV2, permissionListV2_default;
1142
1145
  var init_permissionListV2 = __esm({
1143
1146
  "src/features/permission/components/permissionListV2/index.tsx"() {
1144
1147
  init_locale();
1145
1148
  init_hooks2();
1146
1149
  init_permissionCollapse();
1147
1150
  ({ Text: Text3 } = Typography);
1148
- ({ Option: Option2 } = Select);
1151
+ ({ Option: Option3 } = Select);
1149
1152
  PermissionListV2 = (props) => {
1150
1153
  const { expand = true, value, readonly, onChange } = props;
1151
1154
  const { data: { permission, game: games } = {}, isLoading, error } = useAllPermissionsV2();
@@ -1209,7 +1212,7 @@ var init_permissionListV2 = __esm({
1209
1212
  });
1210
1213
  },
1211
1214
  children: games?.map((game) => /* @__PURE__ */ jsx(
1212
- Option2,
1215
+ Option3,
1213
1216
  {
1214
1217
  value: game.id,
1215
1218
  disabled: gameList.some(({ gameId }) => gameId === String(game.id)),
@@ -1289,9 +1292,9 @@ var init_permission2 = __esm({
1289
1292
  var userList_exports = {};
1290
1293
  __export(userList_exports, {
1291
1294
  default: () => userList_default,
1292
- url: () => url
1295
+ url: () => url2
1293
1296
  });
1294
- var Option3, url, useModal2, UserList, userList_default;
1297
+ var Option4, url2, useModal2, UserList, userList_default;
1295
1298
  var init_userList = __esm({
1296
1299
  "src/pages/permission/userList/index.tsx"() {
1297
1300
  init_highlight();
@@ -1302,8 +1305,8 @@ var init_userList = __esm({
1302
1305
  init_constants();
1303
1306
  init_permission2();
1304
1307
  init_formModal();
1305
- ({ Option: Option3 } = Select);
1306
- url = "/api/usystem/user/list";
1308
+ ({ Option: Option4 } = Select);
1309
+ url2 = "/api/usystem/user/list";
1307
1310
  useModal2 = (isCreate) => {
1308
1311
  const { message } = App.useApp();
1309
1312
  const { t } = useTranslation();
@@ -1314,17 +1317,17 @@ var init_userList = __esm({
1314
1317
  const title = isCreate ? t("UserList.createTitle") : t("UserList.updateTitle");
1315
1318
  const content = /* @__PURE__ */ jsxs(Fragment, { children: [
1316
1319
  /* @__PURE__ */ jsx(Form.Item, { label: t("global.name"), name: "name", rules: [{ required: true }], children: /* @__PURE__ */ jsx(Input, { disabled: !isCreate }) }),
1317
- /* @__PURE__ */ jsx(Form.Item, { label: t("global.role"), name: "roles", children: /* @__PURE__ */ jsx(Select, { allowClear: true, mode: "multiple", loading: isLoading, children: (roles ?? []).map((role) => /* @__PURE__ */ jsx(Option3, { value: role.name, children: role.name }, role.id)) }) })
1320
+ /* @__PURE__ */ jsx(Form.Item, { label: t("global.role"), name: "roles", children: /* @__PURE__ */ jsx(Select, { allowClear: true, mode: "multiple", loading: isLoading, children: (roles ?? []).map((role) => /* @__PURE__ */ jsx(Option4, { value: role.name, children: role.name }, role.id)) }) })
1318
1321
  ] });
1319
1322
  const onConfirm = async (values, extraValues) => {
1320
1323
  if (isCreate) {
1321
1324
  await create5.trigger(values);
1322
- refetch(url, { page: 1 });
1325
+ refetch(url2, { page: 1 });
1323
1326
  message.success(t("UserList.createSuccessfully"));
1324
1327
  } else {
1325
1328
  await update.trigger(values);
1326
1329
  mutate2(
1327
- url,
1330
+ url2,
1328
1331
  (prev) => {
1329
1332
  return produce(prev, (draft) => {
1330
1333
  if (draft?.List) {
@@ -1424,7 +1427,7 @@ var init_userList = __esm({
1424
1427
  id: value.id,
1425
1428
  name: value.name
1426
1429
  });
1427
- mutate2(url, (prev) => {
1430
+ mutate2(url2, (prev) => {
1428
1431
  return produce(prev, (draft) => {
1429
1432
  const index = draft?.List?.findIndex((item) => item.id === value.id);
1430
1433
  if (index) {
@@ -1464,7 +1467,7 @@ var init_userList = __esm({
1464
1467
  QueryList_default,
1465
1468
  {
1466
1469
  code: "100001",
1467
- url,
1470
+ url: url2,
1468
1471
  rowKey: "id",
1469
1472
  columns,
1470
1473
  getTotal: (response) => response?.Total,
@@ -1487,7 +1490,7 @@ var roleList_exports = {};
1487
1490
  __export(roleList_exports, {
1488
1491
  default: () => roleList_default
1489
1492
  });
1490
- var url2, useModal3, RoleList, roleList_default;
1493
+ var url3, useModal3, RoleList, roleList_default;
1491
1494
  var init_roleList = __esm({
1492
1495
  "src/pages/permission/roleList/index.tsx"() {
1493
1496
  init_highlight();
@@ -1501,7 +1504,7 @@ var init_roleList = __esm({
1501
1504
  init_formModal();
1502
1505
  init_permission();
1503
1506
  init_axios();
1504
- url2 = "/api/usystem/role/list";
1507
+ url3 = "/api/usystem/role/list";
1505
1508
  useModal3 = (isCreate) => {
1506
1509
  const { message } = App.useApp();
1507
1510
  const { t } = useTranslation();
@@ -1522,7 +1525,7 @@ var init_roleList = __esm({
1522
1525
  name: `role_${values.name}`,
1523
1526
  permissions: values.permissions
1524
1527
  });
1525
- refetch(url2, { page: 1 });
1528
+ refetch(url3, { page: 1 });
1526
1529
  message.success(t("RoleList.createSuccessfully"));
1527
1530
  } else {
1528
1531
  await update.trigger({
@@ -1531,7 +1534,7 @@ var init_roleList = __esm({
1531
1534
  permissions: values.permissions
1532
1535
  });
1533
1536
  mutate2(
1534
- url2,
1537
+ url3,
1535
1538
  (prev) => produce(prev, (draft) => {
1536
1539
  const match = draft?.List?.find((item) => item.id === extraValues?.id);
1537
1540
  if (match) {
@@ -1561,7 +1564,7 @@ var init_roleList = __esm({
1561
1564
  const { show: showUpdateModal, modal: updateModal } = useModal3();
1562
1565
  const remove = useRemoveRole();
1563
1566
  const handleUpdateBtnClick = async (record) => {
1564
- const response = await axios_default.get(
1567
+ const response = await instance.get(
1565
1568
  `/api/usystem/role/info${usePermissionApiV2 ? "V2" : ""}?name=${record.name}`,
1566
1569
  {
1567
1570
  headers: { [APP_ID_HEADER]: "global" }
@@ -1636,7 +1639,7 @@ var init_roleList = __esm({
1636
1639
  id: record.id,
1637
1640
  name: record.name
1638
1641
  });
1639
- mutate2(url2, (prev) => {
1642
+ mutate2(url3, (prev) => {
1640
1643
  return produce(prev, (draft) => {
1641
1644
  const index = draft?.List?.findIndex((item) => item.id === record.id);
1642
1645
  if (index) {
@@ -1679,7 +1682,7 @@ var init_roleList = __esm({
1679
1682
  rowKey: "name",
1680
1683
  columns,
1681
1684
  code: "200001",
1682
- url: url2,
1685
+ url: url3,
1683
1686
  headers: { [APP_ID_HEADER]: "global" },
1684
1687
  getTotal: (response) => response?.Total,
1685
1688
  getDataSource: (response) => response?.List
@@ -1900,7 +1903,7 @@ init_axios();
1900
1903
  init_filterFormWrapper();
1901
1904
  init_locale();
1902
1905
  var InfiniteList = (props) => {
1903
- const { code, url: url3, extras, headers, getRowKey, getDataSource, hasMore, renderForm, transformArg, ...tableProps } = props;
1906
+ const { code, url: url4, extras, headers, getRowKey, getDataSource, hasMore, renderForm, transformArg, ...tableProps } = props;
1904
1907
  const { t } = useTranslation();
1905
1908
  const [form] = Form.useForm();
1906
1909
  const [isValid, setIsValid] = useState(false);
@@ -1910,7 +1913,7 @@ var InfiniteList = (props) => {
1910
1913
  const rowKey = pageIndex !== 0 ? getRowKey(previousPageData) : void 0;
1911
1914
  const args = transformArg(formValues, rowKey);
1912
1915
  const queryString = qs.stringify(args);
1913
- return queryString ? `${url3}?${qs.stringify(args)}` : url3;
1916
+ return queryString ? `${url4}?${qs.stringify(args)}` : url4;
1914
1917
  };
1915
1918
  const _headers = typeof headers === "function" ? headers(form) : headers;
1916
1919
  const { accessible, isLoading } = usePermission(code, {
@@ -1924,7 +1927,7 @@ var InfiniteList = (props) => {
1924
1927
  } = useSWRInfinite(
1925
1928
  getKey,
1926
1929
  async (arg) => {
1927
- const response = await axios_default({ url: arg, headers: _headers });
1930
+ const response = await instance({ url: arg, headers: _headers });
1928
1931
  return response.data.data;
1929
1932
  },
1930
1933
  {
@@ -1957,7 +1960,7 @@ var InfiniteList = (props) => {
1957
1960
  form.resetFields();
1958
1961
  await form.validateFields({ validateOnly: true });
1959
1962
  setSize(1);
1960
- } catch (_) {
1963
+ } catch (error) {
1961
1964
  setSize(0);
1962
1965
  }
1963
1966
  };
@@ -2405,6 +2408,225 @@ init_formModal();
2405
2408
  init_modal();
2406
2409
  init_permission();
2407
2410
 
2411
+ // src/pages/menu/index.tsx
2412
+ init_highlight();
2413
+ init_locale();
2414
+ init_queryList();
2415
+ init_formModal();
2416
+
2417
+ // src/pages/menu/hooks.ts
2418
+ init_toolkitsProvider();
2419
+ init_axios();
2420
+ function useCreateMenu() {
2421
+ return useSWRMutation2(
2422
+ "/api/usystem/resource/set",
2423
+ (url4, { arg }) => instance.post(url4, { ...arg, id: 0 })
2424
+ );
2425
+ }
2426
+ function useUpdateMenu() {
2427
+ return useSWRMutation2("/api/usystem/resource/set", (url4, { arg }) => instance.post(url4, arg));
2428
+ }
2429
+ function useMenuList() {
2430
+ const game = useToolkitsStore((state) => state.game);
2431
+ return useSWRImmutable(
2432
+ ["/api/usystem/resource/navbar", game],
2433
+ ([url4]) => instance(url4).then((response) => response.data.data)
2434
+ );
2435
+ }
2436
+ function useRemoveMenu() {
2437
+ return useSWRMutation2(
2438
+ "/api/usystem/resource/delete",
2439
+ (url4, { arg }) => instance.post(url4, null, { params: { id: arg } })
2440
+ );
2441
+ }
2442
+ var { Paragraph } = Typography;
2443
+ var { TextArea } = Input;
2444
+ var { Option } = Select;
2445
+ var url = "/api/usystem/resource/list";
2446
+ var useMenuModal = (isCreate) => {
2447
+ const { message } = App.useApp();
2448
+ const create5 = useCreateMenu();
2449
+ const update = useUpdateMenu();
2450
+ const { refetch } = useQueryListStore();
2451
+ const { mutate: mutate2 } = useMenuList();
2452
+ const formProps = {
2453
+ labelCol: { flex: "120px" },
2454
+ initialValues: {
2455
+ model_name: "change",
2456
+ is_common: false,
2457
+ is_model: false
2458
+ }
2459
+ };
2460
+ const content = /* @__PURE__ */ jsxs(Fragment, { children: [
2461
+ /* @__PURE__ */ jsx(Form.Item, { label: "\u83DC\u5355\u540D\u79F0", name: "category", rules: [{ required: true }], children: /* @__PURE__ */ jsx(Input, {}) }),
2462
+ /* @__PURE__ */ jsx(Form.Item, { label: "\u524D\u7AEF\u8DEF\u7531", name: "front_route", rules: [{ required: true }], children: /* @__PURE__ */ jsx(Input, {}) }),
2463
+ /* @__PURE__ */ jsx(Form.Item, { label: "Model", name: "model_name", children: /* @__PURE__ */ jsxs(Select, { allowClear: true, children: [
2464
+ /* @__PURE__ */ jsx(Option, { value: "change", children: "Change" }),
2465
+ /* @__PURE__ */ jsx(Option, { value: "recharge", children: "Recharge" })
2466
+ ] }) }),
2467
+ /* @__PURE__ */ jsx(Form.Item, { label: "Is Common", name: "is_common", rules: [{ required: true }], valuePropName: "checked", children: /* @__PURE__ */ jsx(Switch, {}) }),
2468
+ /* @__PURE__ */ jsx(Form.Item, { label: "Is Model", name: "is_model", rules: [{ required: true }], valuePropName: "checked", children: /* @__PURE__ */ jsx(Switch, {}) }),
2469
+ /* @__PURE__ */ jsx(Form.Item, { label: "\u63A5\u53E3\u89C4\u5219", name: "permissions", rules: [{ required: true }], children: /* @__PURE__ */ jsx(TextArea, { rows: 8 }) })
2470
+ ] });
2471
+ const onConfirm = async (value, extraValue) => {
2472
+ const { permissions, ...rest } = value;
2473
+ if (isCreate) {
2474
+ await create5.trigger({ ...rest, permissions: JSON.parse(permissions) });
2475
+ message.success("\u521B\u5EFA\u6210\u529F");
2476
+ refetch(url, { page: 1 });
2477
+ } else {
2478
+ await update.trigger({
2479
+ ...rest,
2480
+ permissions: JSON.parse(permissions),
2481
+ id: extraValue.id
2482
+ });
2483
+ message.success("\u66F4\u65B0\u6210\u529F");
2484
+ refetch(url);
2485
+ }
2486
+ mutate2();
2487
+ };
2488
+ return useFormModal({
2489
+ title: isCreate ? "\u521B\u5EFA\u83DC\u5355" : "\u7F16\u8F91\u83DC\u5355",
2490
+ width: 600,
2491
+ formProps,
2492
+ content,
2493
+ onConfirm
2494
+ });
2495
+ };
2496
+ var MenuItemList = () => {
2497
+ const { t } = useTranslation();
2498
+ const { message } = App.useApp();
2499
+ const { show: showCreateModal, modal: createModal } = useMenuModal(true);
2500
+ const { show: showUpdateModal, modal: updateModal } = useMenuModal();
2501
+ const remove = useRemoveMenu();
2502
+ const { refetch } = useQueryListStore();
2503
+ const { mutate: mutate2 } = useMenuList();
2504
+ const columns = [
2505
+ {
2506
+ title: "\u83DC\u5355\u540D\u79F0",
2507
+ dataIndex: "category",
2508
+ key: "category"
2509
+ },
2510
+ {
2511
+ title: "\u524D\u7AEF\u8DEF\u7531",
2512
+ dataIndex: "front_route"
2513
+ },
2514
+ {
2515
+ title: "Is Common",
2516
+ dataIndex: "is_common",
2517
+ key: "is_common",
2518
+ render: (value) => value ? "\u662F" : "\u5426"
2519
+ },
2520
+ {
2521
+ title: "Is Model",
2522
+ dataIndex: "is_model",
2523
+ key: "is_model",
2524
+ render: (value) => value ? "\u662F" : "\u5426"
2525
+ },
2526
+ {
2527
+ title: "Model",
2528
+ dataIndex: "model_name",
2529
+ key: "model_name"
2530
+ },
2531
+ {
2532
+ title: "\u7C7B\u578B",
2533
+ dataIndex: "type",
2534
+ key: "type"
2535
+ },
2536
+ {
2537
+ title: "\u63A5\u53E3\u89C4\u5219",
2538
+ dataIndex: "permissions",
2539
+ key: "permissions",
2540
+ render(value) {
2541
+ return /* @__PURE__ */ jsx(Paragraph, { children: /* @__PURE__ */ jsx("pre", { className: "max-h-40 overflow-auto", children: JSON.stringify(value, null, 2) }) });
2542
+ }
2543
+ },
2544
+ {
2545
+ title: "\u64CD\u4F5C",
2546
+ key: "action",
2547
+ width: 150,
2548
+ align: "center",
2549
+ render(_, record) {
2550
+ return /* @__PURE__ */ jsxs(Space, { size: "small", children: [
2551
+ /* @__PURE__ */ jsx(
2552
+ Button,
2553
+ {
2554
+ type: "link",
2555
+ size: "small",
2556
+ onClick: () => {
2557
+ const { id: id2, ...rest } = record;
2558
+ showUpdateModal({
2559
+ initialValues: {
2560
+ ...rest,
2561
+ front_route: record.front_route,
2562
+ permissions: JSON.stringify(record.permissions, null, 2)
2563
+ },
2564
+ extraValues: {
2565
+ id: id2
2566
+ }
2567
+ });
2568
+ },
2569
+ children: t("global.update")
2570
+ }
2571
+ ),
2572
+ /* @__PURE__ */ jsx(
2573
+ Popconfirm,
2574
+ {
2575
+ title: "\u5220\u9664\u83DC\u5355",
2576
+ placement: "topRight",
2577
+ description: /* @__PURE__ */ jsxs(Highlight_default, { texts: [record.category], children: [
2578
+ "\u786E\u5B9A\u8981\u5220\u9664\u83DC\u5355 ",
2579
+ record.category,
2580
+ " \u5417\uFF1F"
2581
+ ] }),
2582
+ onConfirm: async () => {
2583
+ await remove.trigger(record.id);
2584
+ refetch(url);
2585
+ mutate2();
2586
+ message.success("\u5220\u9664\u6210\u529F");
2587
+ },
2588
+ children: /* @__PURE__ */ jsx(Button, { danger: true, type: "link", size: "small", children: t("global.delete") })
2589
+ }
2590
+ )
2591
+ ] });
2592
+ }
2593
+ }
2594
+ ];
2595
+ return /* @__PURE__ */ jsxs(Fragment, { children: [
2596
+ /* @__PURE__ */ jsx(
2597
+ Card,
2598
+ {
2599
+ title: "\u83DC\u5355",
2600
+ extra: /* @__PURE__ */ jsx(
2601
+ Button,
2602
+ {
2603
+ type: "primary",
2604
+ onClick: () => {
2605
+ showCreateModal();
2606
+ },
2607
+ children: "\u521B\u5EFA\u83DC\u5355"
2608
+ }
2609
+ ),
2610
+ children: /* @__PURE__ */ jsx(
2611
+ QueryList_default,
2612
+ {
2613
+ isGlobal: true,
2614
+ onePage: true,
2615
+ code: "9900001",
2616
+ rowKey: "id",
2617
+ url,
2618
+ columns,
2619
+ getDataSource: (response) => response
2620
+ }
2621
+ )
2622
+ }
2623
+ ),
2624
+ createModal,
2625
+ updateModal
2626
+ ] });
2627
+ };
2628
+ var menu_default = MenuItemList;
2629
+
2408
2630
  // src/pages/notFound/index.tsx
2409
2631
  init_locale();
2410
2632
  var NotFound = (props) => {
@@ -2434,7 +2656,7 @@ var notFound_default = NotFound;
2434
2656
  init_locale();
2435
2657
  init_queryList();
2436
2658
  init_constants();
2437
- var { Option } = Select;
2659
+ var { Option: Option2 } = Select;
2438
2660
  var OperationLogList = () => {
2439
2661
  const { t } = useTranslation();
2440
2662
  const columns = [
@@ -2503,8 +2725,8 @@ var OperationLogList = () => {
2503
2725
  /* @__PURE__ */ jsx(Form.Item, { label: t("global.username"), name: "uname", children: /* @__PURE__ */ jsx(Input, { allowClear: true }) }),
2504
2726
  /* @__PURE__ */ jsx(Form.Item, { label: t("global.route"), name: "route", children: /* @__PURE__ */ jsx(Input, { allowClear: true }) }),
2505
2727
  /* @__PURE__ */ jsx(Form.Item, { label: t("global.method"), name: "method", children: /* @__PURE__ */ jsxs(Select, { allowClear: true, style: { width: "100px" }, children: [
2506
- /* @__PURE__ */ jsx(Option, { value: "get", children: "GET" }),
2507
- /* @__PURE__ */ jsx(Option, { value: "post", children: "POST" })
2728
+ /* @__PURE__ */ jsx(Option2, { value: "get", children: "GET" }),
2729
+ /* @__PURE__ */ jsx(Option2, { value: "post", children: "POST" })
2508
2730
  ] }) }),
2509
2731
  /* @__PURE__ */ jsx(Form.Item, { label: t("global.label"), name: "label", children: /* @__PURE__ */ jsx(Input, { allowClear: true }) })
2510
2732
  ] })
@@ -2592,8 +2814,9 @@ var SignIn = (props) => {
2592
2814
  var signIn_default = SignIn;
2593
2815
 
2594
2816
  // src/index.ts
2817
+ init_axios();
2595
2818
  init_storage();
2596
2819
 
2597
- export { APP_ID_HEADER, DynamicTags_default as DynamicTags, ExpandableParagraph_default as ExpandableParagraph, FilterFormWrapper_default as FilterFormWrapper, Highlight_default as Highlight, InfiniteList_default as InfiniteList, Layout_default as Layout, NavMenu_default as NavMenu, notFound_default as NotFound, operationLogList_default as OperationLogList, PermissionButton_default as PermissionButton, QueryList_default as QueryList, QueryListAction, RequireGame_default as RequireGame, RequirePermission_default as RequirePermission, SSO_URL, signIn_default as SignIn, Provider_default as ToolkitsProvider, UserWidget_default as UserWidget, mixedStorage, permission_default as permissionRoutes, toolkitsStore, useFormModal, useLayoutStore, useModal, useModalStore, usePermission, usePermissions, useQueryListStore, useToolkitsStore };
2820
+ export { APP_ID_HEADER, DynamicTags_default as DynamicTags, ExpandableParagraph_default as ExpandableParagraph, FilterFormWrapper_default as FilterFormWrapper, Highlight_default as Highlight, InfiniteList_default as InfiniteList, Interceptor, Layout_default as Layout, menu_default as MenuItemList, NavMenu_default as NavMenu, notFound_default as NotFound, operationLogList_default as OperationLogList, PermissionButton_default as PermissionButton, QueryList_default as QueryList, QueryListAction, RequireGame_default as RequireGame, RequirePermission_default as RequirePermission, SSO_URL, signIn_default as SignIn, Provider_default as ToolkitsProvider, UserWidget_default as UserWidget, instance, mixedStorage, permission_default as permissionRoutes, toolkitsStore, useFormModal, useLayoutStore, useModal, useModalStore, usePermission, usePermissions, useQueryListStore, useToolkitsStore };
2598
2821
  //# sourceMappingURL=index.js.map
2599
2822
  //# sourceMappingURL=index.js.map