react-toolkits 2.13.6 → 2.13.8

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 CHANGED
@@ -1,5 +1,17 @@
1
1
  # react-toolkits
2
2
 
3
+ ## 2.13.8
4
+
5
+ ### Patch Changes
6
+
7
+ - 3d60f77: fix: missing token
8
+
9
+ ## 2.13.7
10
+
11
+ ### Patch Changes
12
+
13
+ - fd68eee: fix: some issues
14
+
3
15
  ## 2.13.6
4
16
 
5
17
  ### Patch Changes
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;
@@ -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).then((response) => response.data.data)
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
- usePermissions = (codes = []) => {
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 onChange = async (value2) => {
843
- const game = data?.find((item) => String(gameApiV2 ? item.game_id : item.id) === String(value2));
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
- const value = getGameId();
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
- accessible ? "/api/usystem/role/all" : null,
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 } = useSWRImmutable(
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) {