@flow97/react-toolkit 0.0.2 → 0.0.4
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 +12 -0
- package/README.md +10 -10
- package/lib/index.d.ts +42 -37
- package/lib/index.js +3 -3
- package/lib/index.js.map +1 -1
- package/locale/hooks.js +259 -9
- package/locale/index.js +259 -9
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,17 @@
|
|
|
1
1
|
# react-toolkits
|
|
2
2
|
|
|
3
|
+
## 0.0.4
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- 2cab4f1: refactor: enhance KyMethods interface to support responseType for blob data
|
|
8
|
+
|
|
9
|
+
## 0.0.3
|
|
10
|
+
|
|
11
|
+
### Patch Changes
|
|
12
|
+
|
|
13
|
+
- df5b54f: refactor: rename ToolkitsProvider to ToolkitProvider and update related imports
|
|
14
|
+
|
|
3
15
|
## 0.0.2
|
|
4
16
|
|
|
5
17
|
### Patch Changes
|
package/README.md
CHANGED
|
@@ -37,7 +37,7 @@ import { QueryClient, QueryClientProvider } from '@tanstack/react-query'
|
|
|
37
37
|
import 'react-toolkits/style.css'
|
|
38
38
|
import { createRoot } from 'react-dom/client'
|
|
39
39
|
import { RouterProvider } from 'react-router'
|
|
40
|
-
import {
|
|
40
|
+
import { ToolkitProvider } from 'react-toolkits/components'
|
|
41
41
|
import { AuthMode } from 'react-toolkits/constants'
|
|
42
42
|
|
|
43
43
|
import router from './router'
|
|
@@ -61,16 +61,16 @@ const root = createRoot(document.getElementById('root') as HTMLElement)
|
|
|
61
61
|
|
|
62
62
|
root.render(
|
|
63
63
|
<QueryClientProvider client={queryClient}>
|
|
64
|
-
<
|
|
64
|
+
<ToolkitProvider collapsible gameApiV2 auth={{ mode: AuthMode.GROUP_BASED }} loginPath="/sign_in" mainPagePath="/">
|
|
65
65
|
<RouterProvider router={router} />
|
|
66
|
-
</
|
|
66
|
+
</ToolkitProvider>
|
|
67
67
|
</QueryClientProvider>,
|
|
68
68
|
)
|
|
69
69
|
```
|
|
70
70
|
|
|
71
|
-
**重要提示**:`QueryClientProvider` 必须包裹 `
|
|
71
|
+
**重要提示**:`QueryClientProvider` 必须包裹 `ToolkitProvider`,因为 `react-toolkits` 内部使用了 `@tanstack/react-query` 的 hooks(如 `useQueryClient`、`useQuery`、`useMutation`)。
|
|
72
72
|
|
|
73
|
-
### 配置项(`
|
|
73
|
+
### 配置项(`ToolkitProvider`)
|
|
74
74
|
|
|
75
75
|
- **loginPath**: 登录页路径(未鉴权时会跳转)
|
|
76
76
|
- **mainPagePath**: 登录后主页路径(鉴权通过时进入)
|
|
@@ -81,7 +81,7 @@ root.render(
|
|
|
81
81
|
|
|
82
82
|
## 子路径导出(推荐)
|
|
83
83
|
|
|
84
|
-
- `react-toolkits/components`:组件与 Hooks(如 `Layout`、`
|
|
84
|
+
- `react-toolkits/components`:组件与 Hooks(如 `Layout`、`ToolkitProvider`、`InfiniteList`)
|
|
85
85
|
- `react-toolkits/hooks`:表单弹层 Hooks(如 `useFormDrawer`、`useFormModal`)
|
|
86
86
|
- `react-toolkits/pages`:内置页面与路由片段(如 `permissionRoutes`、`menuRoutes`、`SignIn`)
|
|
87
87
|
- `react-toolkits/services`:请求相关 Hooks(如 `useAuth`、`useMenuList`、`useGames`)
|
|
@@ -324,13 +324,13 @@ export default function FetchWithKy() {
|
|
|
324
324
|
过去:
|
|
325
325
|
|
|
326
326
|
```ts
|
|
327
|
-
import {
|
|
327
|
+
import { ToolkitProvider, Layout, useFormDrawer } from '@flow97/react-toolkit'
|
|
328
328
|
```
|
|
329
329
|
|
|
330
330
|
现在(推荐):
|
|
331
331
|
|
|
332
332
|
```ts
|
|
333
|
-
import {
|
|
333
|
+
import { ToolkitProvider, Layout } from 'react-toolkits/components'
|
|
334
334
|
import { useFormDrawer, useFormModal } from 'react-toolkits/hooks'
|
|
335
335
|
import { permissionRoutes } from 'react-toolkits/pages'
|
|
336
336
|
import { useAuth } from 'react-toolkits/services'
|
|
@@ -341,14 +341,14 @@ import { useAuth } from 'react-toolkits/services'
|
|
|
341
341
|
### 权限版本兼容
|
|
342
342
|
|
|
343
343
|
- 历史上存在不同权限数据结构,`AuthMode` 用于适配后端变体
|
|
344
|
-
- 新项目建议使用 `V3`;旧项目如为 `V2`,只需在 `
|
|
344
|
+
- 新项目建议使用 `V3`;旧项目如为 `V2`,只需在 `ToolkitProvider` 中切换版本
|
|
345
345
|
|
|
346
346
|
## 常见问题(FAQ)
|
|
347
347
|
|
|
348
348
|
- 如何引入样式?
|
|
349
349
|
- 在应用入口一次性引入:`import 'react-toolkits/style.css'`
|
|
350
350
|
- Provider 放哪?
|
|
351
|
-
- 在应用根部使用 `
|
|
351
|
+
- 在应用根部使用 `ToolkitProvider`,传入登录路径、主页路径、权限版本等配置。
|
|
352
352
|
- 如何自定义菜单?
|
|
353
353
|
- 通过 `Layout` 的 `items` 或参考示例应用的 `menu-items.tsx`。
|
|
354
354
|
- 如何统一请求与拦截?
|
package/lib/index.d.ts
CHANGED
|
@@ -8,14 +8,14 @@ import { ItemType, SubMenuType, MenuItemGroupType, MenuItemType } from 'antd/es/
|
|
|
8
8
|
import { AnyObject } from 'antd/es/_util/type';
|
|
9
9
|
import { TableProps } from 'antd/es/table';
|
|
10
10
|
import * as zustand from 'zustand';
|
|
11
|
-
import { StateCreator } from 'zustand';
|
|
11
|
+
import { StoreApi, StateCreator } from 'zustand';
|
|
12
12
|
import * as _tanstack_react_query from '@tanstack/react-query';
|
|
13
13
|
import { StateStorage } from 'zustand/middleware';
|
|
14
14
|
|
|
15
15
|
/** 响应类型 */
|
|
16
16
|
type ResponseType = 'json' | 'blob' | 'text' | 'arrayBuffer' | 'formData';
|
|
17
17
|
/** 通用请求选项接口 */
|
|
18
|
-
interface RequestOptions extends Options {
|
|
18
|
+
interface RequestOptions extends Omit<Options, 'hooks'> {
|
|
19
19
|
/** 响应类型 */
|
|
20
20
|
responseType?: ResponseType;
|
|
21
21
|
/** 是否使用全局模式,为 true 时 app-id header 设置为 global */
|
|
@@ -620,7 +620,7 @@ interface QueryListRequestConfig extends CacheConfig {
|
|
|
620
620
|
body?: FormData | Record<string | number, any>;
|
|
621
621
|
searchParams?: Record<string | number, any>;
|
|
622
622
|
headers?: Record<string, string>;
|
|
623
|
-
/** 是否使用全局模式(覆盖
|
|
623
|
+
/** 是否使用全局模式(覆盖 ToolkitProvider 中的 isGlobalMode) */
|
|
624
624
|
isGlobalMode?: boolean;
|
|
625
625
|
}
|
|
626
626
|
/**
|
|
@@ -900,6 +900,16 @@ type Locale = {
|
|
|
900
900
|
};
|
|
901
901
|
};
|
|
902
902
|
|
|
903
|
+
/**
|
|
904
|
+
* JWT Token 解密后的用户信息
|
|
905
|
+
*/
|
|
906
|
+
interface UserInfo {
|
|
907
|
+
authorityId: string;
|
|
908
|
+
exp: number;
|
|
909
|
+
}
|
|
910
|
+
/**
|
|
911
|
+
* Context 配置接口
|
|
912
|
+
*/
|
|
903
913
|
interface ContextSlice {
|
|
904
914
|
/** 是否使用游戏 API V2 版本 */
|
|
905
915
|
useGameApiV2: boolean;
|
|
@@ -920,17 +930,30 @@ interface ContextSlice {
|
|
|
920
930
|
/** 认证模式 */
|
|
921
931
|
authMode: AuthMode;
|
|
922
932
|
}
|
|
923
|
-
|
|
933
|
+
/**
|
|
934
|
+
* Token 状态接口
|
|
935
|
+
*/
|
|
936
|
+
interface TokenSlice {
|
|
937
|
+
/** JWT Token */
|
|
938
|
+
token?: string;
|
|
939
|
+
user: UserInfo | null;
|
|
940
|
+
setToken: (token: string) => void;
|
|
941
|
+
clearToken: () => void;
|
|
942
|
+
}
|
|
943
|
+
/**
|
|
944
|
+
* Game 状态接口
|
|
945
|
+
*/
|
|
924
946
|
interface GameSlice {
|
|
925
947
|
appId?: string | number;
|
|
926
948
|
setAppId: (id?: string | number) => void;
|
|
927
949
|
}
|
|
928
|
-
|
|
950
|
+
/**
|
|
951
|
+
* Layout 状态接口
|
|
952
|
+
*/
|
|
929
953
|
interface LayoutSlice {
|
|
930
954
|
collapsed: boolean;
|
|
931
955
|
toggleCollapsed: () => void;
|
|
932
956
|
}
|
|
933
|
-
|
|
934
957
|
/**
|
|
935
958
|
* 导航菜单状态接口
|
|
936
959
|
*/
|
|
@@ -944,23 +967,7 @@ interface NavSlice {
|
|
|
944
967
|
/** 设置选中的菜单项 */
|
|
945
968
|
setSelectedKeys: (keys: string[]) => void;
|
|
946
969
|
}
|
|
947
|
-
|
|
948
|
-
/**
|
|
949
|
-
* JWT Token 解密后的用户信息
|
|
950
|
-
*/
|
|
951
|
-
interface UserInfo {
|
|
952
|
-
authorityId: string;
|
|
953
|
-
exp: number;
|
|
954
|
-
}
|
|
955
|
-
interface TokenSlice {
|
|
956
|
-
/** JWT Token */
|
|
957
|
-
token?: string;
|
|
958
|
-
user: UserInfo | null;
|
|
959
|
-
setToken: (token: string) => void;
|
|
960
|
-
clearToken: () => void;
|
|
961
|
-
}
|
|
962
|
-
|
|
963
|
-
type ToolkitsState = {
|
|
970
|
+
type ToolkitState = {
|
|
964
971
|
context: ContextSlice;
|
|
965
972
|
token: TokenSlice;
|
|
966
973
|
game: GameSlice;
|
|
@@ -968,24 +975,22 @@ type ToolkitsState = {
|
|
|
968
975
|
nav: NavSlice;
|
|
969
976
|
clear: () => void;
|
|
970
977
|
};
|
|
978
|
+
declare const toolkitStore: StoreApi<ToolkitState>;
|
|
971
979
|
|
|
972
|
-
declare function
|
|
973
|
-
declare function
|
|
974
|
-
type
|
|
980
|
+
declare function useToolkitStore(): ToolkitState;
|
|
981
|
+
declare function useToolkitStore<T>(selector: (state: ToolkitState) => T): T;
|
|
982
|
+
type ToolkitProviderProps = PropsWithChildren<DeepPartial<ContextSlice>>;
|
|
975
983
|
/**
|
|
976
|
-
*
|
|
984
|
+
* ToolkitProvider 组件(全局单例模式,不支持嵌套)
|
|
977
985
|
*
|
|
978
|
-
*
|
|
979
|
-
*
|
|
986
|
+
* - 使用全局单例的 ToolkitStore(store 在模块加载时已创建)
|
|
987
|
+
* - 最外层 Provider 的 props 会更新全局 store 的 context 配置
|
|
988
|
+
* - 内层嵌套的 Provider 将直接抛错,提示不支持嵌套使用
|
|
980
989
|
*
|
|
981
|
-
*
|
|
982
|
-
*
|
|
983
|
-
* @example
|
|
984
|
-
* 外层 Provider 和内层 Provider 嵌套使用示例:
|
|
985
|
-
* - 外层:loginPath="/login" apiBaseUrl="https://api.example.com"
|
|
986
|
-
* - 内层:apiBaseUrl="https://api-v2.example.com" (会覆盖外层的 apiBaseUrl)
|
|
990
|
+
* 使用约定:
|
|
991
|
+
* - 只在应用根部使用一次 ToolkitProvider
|
|
987
992
|
*/
|
|
988
|
-
declare const
|
|
993
|
+
declare const ToolkitProvider: FC<ToolkitProviderProps>;
|
|
989
994
|
|
|
990
995
|
declare const UserDropdown: FC;
|
|
991
996
|
|
|
@@ -1445,4 +1450,4 @@ declare function useAuth(code?: string | string[], config?: RequestOptions): {
|
|
|
1445
1450
|
declare function useMenuList(): _tanstack_react_query.UseQueryResult<MenuListItem[], Error>;
|
|
1446
1451
|
declare const useGames: () => _tanstack_react_query.UseQueryResult<Game[], Error>;
|
|
1447
1452
|
|
|
1448
|
-
export { APP_ID_HEADER, AuthButton, type AuthButtonProps, AuthMode, DynamicTags, type DynamicTagsProps, ExpandableParagraph, type ExpandableParagraphProps, FRONTEND_ROUTE_PREFIX, FilterFormWrapper, type FilterFormWrapperProps, type Game, type GameSelectConfig, type GameSelectProps, type HeaderExtra, type HeaderExtraConfig, Highlight, type HighlightProps, InfiniteList, type InfiniteListDataAdapter, type InfiniteListPayload, type InfiniteListProps, type InfiniteListRef, type InfiniteListRequestConfig, type InfiniteListRequestConfigType, type JsonResponse, KeepAlive, type KeepAliveCacheItem, KeepAliveOutlet, type KeepAliveOutletProps, type KeepAliveProps, KeepAliveProvider, type KeepAliveProviderProps, Layout, type LayoutProps, Logo, type LogoProps, type MenuListItem, type NavItem, type NavMenuItemGroupType, type NavMenuItemType, type NavSubMenuType, type NavigationConfig, NotFound, OperationLogList, type PageParam, type Permission, QueryList, QueryListAction, type QueryListPayload, type QueryListProps, type QueryListRef, type RecursivePartial, RequireAuth, type RequireAuthProps, RequireGame, type RouteMatchRule, SSO_URL, SelectAll, type SelectAllProps, type ShowFormOptions$1 as ShowFormDrawerOptions, type ShowFormOptions as ShowFormModalOptions, SignIn,
|
|
1453
|
+
export { APP_ID_HEADER, AuthButton, type AuthButtonProps, AuthMode, DynamicTags, type DynamicTagsProps, ExpandableParagraph, type ExpandableParagraphProps, FRONTEND_ROUTE_PREFIX, FilterFormWrapper, type FilterFormWrapperProps, type Game, type GameSelectConfig, type GameSelectProps, type HeaderExtra, type HeaderExtraConfig, Highlight, type HighlightProps, InfiniteList, type InfiniteListDataAdapter, type InfiniteListPayload, type InfiniteListProps, type InfiniteListRef, type InfiniteListRequestConfig, type InfiniteListRequestConfigType, type JsonResponse, KeepAlive, type KeepAliveCacheItem, KeepAliveOutlet, type KeepAliveOutletProps, type KeepAliveProps, KeepAliveProvider, type KeepAliveProviderProps, Layout, type LayoutProps, Logo, type LogoProps, type MenuListItem, type NavItem, type NavMenuItemGroupType, type NavMenuItemType, type NavSubMenuType, type NavigationConfig, NotFound, OperationLogList, type PageParam, type Permission, QueryList, QueryListAction, type QueryListPayload, type QueryListProps, type QueryListRef, type RecursivePartial, RequireAuth, type RequireAuthProps, RequireGame, type RouteMatchRule, SSO_URL, SelectAll, type SelectAllProps, type ShowFormOptions$1 as ShowFormDrawerOptions, type ShowFormOptions as ShowFormModalOptions, SignIn, ToolkitProvider, type ToolkitProviderProps, type UseDrawerOperation, type UseDrawerProps, type UseFormDrawerProps, type UseFormDrawerReturn, type UseFormModalProps, type UseFormModalReturn, type UseKeepAliveReturn, type UseModalOperation, type UseModalProps, UserDropdown, type VisibilityState, WILDCARD, createVisibilityStoreConfig, generateId, _default$1 as menuRoutes, mixedStorage, _default as permissionRoutes, toolkitStore, useAuth, useDrawer, useDrawerStore, useFormDrawer, useFormModal, useGames, useInfiniteListStore, useKeepAlive, useKeepAliveContext, useMenuList, useModal, useModalStore, useQueryListStore, useToolkitStore };
|