@peng_kai/kit 0.1.9 → 0.1.11

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.
Files changed (44) hide show
  1. package/admin/components/filter/src/FilterDrawer.vue +153 -153
  2. package/admin/components/filter/src/FilterParam.vue +78 -78
  3. package/admin/components/scroll-nav/index.ts +1 -1
  4. package/admin/components/scroll-nav/src/ScrollNav.vue +59 -59
  5. package/admin/components/text/index.ts +13 -13
  6. package/admin/components/text/src/Amount.vue +117 -117
  7. package/admin/components/text/src/Datetime.vue +48 -48
  8. package/admin/components/text/src/Duration.vue +26 -26
  9. package/admin/components/text/src/Hash.vue +51 -51
  10. package/admin/components/text/src/createTagGetter.ts +13 -13
  11. package/admin/hooks/useMenu.ts +128 -128
  12. package/admin/hooks/usePage.ts +141 -141
  13. package/admin/hooks/usePageTab.ts +35 -35
  14. package/admin/layout/large/Breadcrumb.vue +69 -69
  15. package/admin/layout/large/Content.vue +24 -24
  16. package/admin/layout/large/Menu.vue +69 -69
  17. package/admin/layout/large/PageTab.vue +71 -71
  18. package/admin/permission/index.ts +4 -4
  19. package/admin/permission/routerGuard.ts +43 -43
  20. package/admin/permission/usePermission.ts +52 -52
  21. package/admin/permission/vuePlugin.ts +30 -30
  22. package/admin/route-guards/index.ts +3 -3
  23. package/admin/route-guards/pageProgress.ts +27 -27
  24. package/admin/route-guards/pageTitle.ts +19 -19
  25. package/admin/styles/globalCover.scss +54 -54
  26. package/antd/components/InputNumberRange.vue +53 -53
  27. package/antd/directives/formLabelAlign.ts +36 -36
  28. package/antd/hooks/useAntdDrawer.ts +73 -73
  29. package/antd/hooks/useAntdTable.ts +115 -82
  30. package/package.json +55 -55
  31. package/pnpm-lock.yaml +5255 -0
  32. package/request/helpers.ts +49 -49
  33. package/request/interceptors/formatPaging.ts +3 -4
  34. package/request/interceptors/popupMessage.ts +5 -4
  35. package/request/interceptors/toLogin.ts +26 -15
  36. package/request/queryClient.ts +32 -8
  37. package/request/request.ts +0 -1
  38. package/request/type.d.ts +92 -92
  39. package/stylelint.config.cjs +7 -7
  40. package/tsconfig.json +50 -50
  41. package/utils/index.ts +2 -2
  42. package/vue/components/infinite-query/index.ts +1 -1
  43. package/vue/components/infinite-query/src/InfiniteQuery.vue +205 -205
  44. package/vue/components/infinite-query/src/useCreateTrigger.ts +39 -39
@@ -1,49 +1,49 @@
1
- import type { AxiosInstance } from 'axios';
2
-
3
- export { isTimeout, getServices, ApiCode, ApiError };
4
-
5
- enum ApiCode {
6
- NORMAL = 0, // 正常
7
- UNKNOWN = -1, // 未知错误
8
- TIMEOUT = -2, // 请求超时
9
- }
10
-
11
- function getServices() {
12
- const serversModule = getServices.modules;
13
- const servers: Record<string, { server: AxiosInstance } | undefined> = {};
14
-
15
- for (const [key, module] of Object.entries(serversModule)) {
16
- const name = key.match(/\/([0-9a-zA-Z]+)\.ts$/)?.[1];
17
-
18
- if (name)
19
- servers[`${name}.api`] = module as any;
20
- }
21
-
22
- return servers;
23
- }
24
- getServices.modules = {} as any;
25
-
26
- function isTimeout(error: any) {
27
- return error?.message?.toLowerCase().includes('timeout');
28
- }
29
-
30
- class ApiError<TResp = any> extends Error {
31
- public static is<ErrorResp = any>(error: any): error is ApiError<ErrorResp> {
32
- return !!error?.isApiError;
33
- }
34
-
35
- /**
36
- * 将HTTP status和Api code统一到一个code里
37
- */
38
- public code: number;
39
- public msg: string;
40
- public data: TResp;
41
- public isApiError = true;
42
-
43
- public constructor(info: { code: number, msg: string, data: TResp }) {
44
- super(info.msg);
45
- this.code = info.code;
46
- this.msg = info.msg;
47
- this.data = info.data;
48
- }
49
- }
1
+ import type { AxiosInstance } from 'axios';
2
+
3
+ export { isTimeout, getServices, ApiCode, ApiError };
4
+
5
+ enum ApiCode {
6
+ NORMAL = 0, // 正常
7
+ UNKNOWN = -1, // 未知错误
8
+ TIMEOUT = -2, // 请求超时
9
+ }
10
+
11
+ function getServices() {
12
+ const serversModule = getServices.modules;
13
+ const servers: Record<string, { server: AxiosInstance } | undefined> = {};
14
+
15
+ for (const [key, module] of Object.entries(serversModule)) {
16
+ const name = key.match(/\/([0-9a-zA-Z]+)\.ts$/)?.[1];
17
+
18
+ if (name)
19
+ servers[`${name}.api`] = module as any;
20
+ }
21
+
22
+ return servers;
23
+ }
24
+ getServices.modules = {} as any;
25
+
26
+ function isTimeout(error: any) {
27
+ return error?.message?.toLowerCase().includes('timeout');
28
+ }
29
+
30
+ class ApiError<TResp = any> extends Error {
31
+ public static is<ErrorResp = any>(error: any): error is ApiError<ErrorResp> {
32
+ return !!error?.isApiError;
33
+ }
34
+
35
+ /**
36
+ * 将HTTP status和Api code统一到一个code里
37
+ */
38
+ public code: number;
39
+ public msg: string;
40
+ public data: TResp;
41
+ public isApiError = true;
42
+
43
+ public constructor(info: { code: number, msg: string, data: TResp }) {
44
+ super(info.msg);
45
+ this.code = info.code;
46
+ this.msg = info.msg;
47
+ this.data = info.data;
48
+ }
49
+ }
@@ -12,10 +12,9 @@ export function formatPaging(): Parameters<AxiosInterceptorManager<any>['use']>
12
12
  return resp;
13
13
 
14
14
  if (result.pagination) {
15
- result.data = {
16
- list: result.data,
17
- pagination: result.pagination,
18
- };
15
+ const originData = result.data;
16
+ result.data = originData.list ? { ...originData } : { list: originData };
17
+ result.data.pagination = result.pagination;
19
18
 
20
19
  Reflect.deleteProperty(result, 'pagination');
21
20
  }
@@ -19,7 +19,8 @@ export function popupMessage(popup: (type: 'error' | 'success', message: string)
19
19
  if (typeof successMessageConfig !== 'string')
20
20
  successMsg = resp?.data?.msg;
21
21
 
22
- popup('success', successMsg);
22
+ if (typeof successMsg === 'string' && successMsg !== '')
23
+ popup('success', successMsg);
23
24
 
24
25
  return resp;
25
26
  },
@@ -32,7 +33,7 @@ export function popupMessage(popup: (type: 'error' | 'success', message: string)
32
33
  let errorMsg: boolean | string = errorMessageConfig;
33
34
 
34
35
  if (axios.isAxiosError(error)) {
35
- // 请求超时
36
+ // 请求超时
36
37
  if (isTimeout(error))
37
38
  errorMsg = 'Request Timeout';
38
39
  else if (typeof errorMessageConfig !== 'string')
@@ -42,10 +43,10 @@ export function popupMessage(popup: (type: 'error' | 'success', message: string)
42
43
  errorMsg = error.message;
43
44
  }
44
45
 
45
- if (typeof errorMsg === 'string')
46
+ if (typeof errorMsg === 'string' && errorMsg !== '')
46
47
  popup('error', errorMsg);
47
48
 
48
49
  throw error;
49
50
  },
50
51
  ];
51
- }
52
+ }
@@ -1,15 +1,26 @@
1
- import type { AxiosInterceptorManager } from 'axios';
2
-
3
- export function toLogin(authPath = `${window.location.origin}/auth/login`, code = 15001): Parameters<AxiosInterceptorManager<any>['use']> {
4
- return [
5
- undefined,
6
- (err) => {
7
- if (err.code !== code)
8
- throw err;
9
-
10
- const url = new URL(authPath);
11
- url.searchParams.set('redirect', window.location.href);
12
- window.location.href = url.toString();
13
- },
14
- ];
15
- }
1
+ import type { AxiosInterceptorManager } from 'axios';
2
+
3
+ const REDIRECT_KEY = 'redirect';
4
+
5
+ export function toLogin(authPath = `${window.location.origin}/auth/login`, code = 15001): Parameters<AxiosInterceptorManager<any>['use']> {
6
+ return [
7
+ undefined,
8
+ (err) => {
9
+ if (err.code !== code)
10
+ throw err;
11
+
12
+ const currentURL = new URL(window.location.href);
13
+ const targetURL = new URL(authPath);
14
+
15
+ if (currentURL.searchParams.has(REDIRECT_KEY))
16
+ targetURL.searchParams.set(REDIRECT_KEY, currentURL.searchParams.get(REDIRECT_KEY)!);
17
+ else
18
+ targetURL.searchParams.set(REDIRECT_KEY, window.location.href);
19
+
20
+ if (currentURL.toString() === targetURL.toString())
21
+ return;
22
+
23
+ window.location.href = targetURL.toString();
24
+ },
25
+ ];
26
+ }
@@ -1,24 +1,48 @@
1
- import type { QueryClientConfig } from '@tanstack/vue-query';
1
+ import type { QueryClientConfig, QueryObserverOptions } from '@tanstack/vue-query';
2
+ import { ApiCode } from './helpers';
2
3
 
3
4
  /** 不需要重试的 api code */
4
5
  export const ignoreRetryCodes = [
6
+ ApiCode.UNKNOWN,
5
7
  11000, // 操作失败
6
8
  11001, // 操作过于频繁
7
9
  11002, // 权限不足
8
10
  11003, // 缺少必要参数
9
11
  15001, // 未登录
12
+ 15003, // 用户不存在
13
+ /^3{2}$/, // HTTP status 3xx
14
+ /^4{2}$/, // HTTP status 4xx
15
+ /^5{2}$/, // HTTP status 5xx
10
16
  ];
11
17
 
18
+ /**
19
+ * 构建用于查询的重试函数。
20
+ * @param ignoreList 一个数组,包含要在重试期间忽略的错误代码的数字、字符串或正则表达式。
21
+ * @param additionPresetIgnore 一个布尔值,指示是否包括额外的预设忽略代码。默认为 true。
22
+ * @returns 根据失败计数和错误代码确定是否重试的重试函数。
23
+ */
24
+ export function buildRetryFn(ignoreList: Array<number | string | RegExp>, additionPresetIgnore = true): NonNullable<QueryObserverOptions['retry']> {
25
+ const _ignoreList = [...ignoreList, ...(additionPresetIgnore ? ignoreRetryCodes : [])];
26
+ return (failureCount, error: any) => {
27
+ if (error?.code === undefined)
28
+ return false;
29
+
30
+ const ignored = _ignoreList.some((code) => {
31
+ if (code instanceof RegExp)
32
+ return code.test(String(error?.code));
33
+
34
+ return code === error?.code;
35
+ });
36
+
37
+ return ignored ? false : failureCount < 2;
38
+ };
39
+ }
40
+
12
41
  export const presetOptions: QueryClientConfig = {
13
42
  defaultOptions: {
14
43
  queries: {
15
44
  refetchOnWindowFocus: false,
16
- retry(failureCount, error: any) {
17
- if (ignoreRetryCodes.includes(error?.code))
18
- return false;
19
-
20
- return failureCount < 3;
21
- },
45
+ retry: buildRetryFn(ignoreRetryCodes),
22
46
  getNextPageParam: (lastPage: any) => {
23
47
  const { pagination } = lastPage ?? {};
24
48
 
@@ -39,4 +63,4 @@ export const presetOptions: QueryClientConfig = {
39
63
  },
40
64
  },
41
65
  },
42
- };
66
+ };
@@ -1,5 +1,4 @@
1
1
  import type { AxiosInstance, AxiosRequestConfig, AxiosResponse } from 'axios';
2
- import { isSSR } from '../utils';
3
2
 
4
3
  export { createRequest };
5
4
 
package/request/type.d.ts CHANGED
@@ -1,92 +1,92 @@
1
- declare namespace Api {
2
- type Request = ((reqData: any, options?: Options) => Promise<any>) & {
3
- id: string
4
- setDefaultConfig: (config: Partial<import('axios').AxiosRequestConfig>) => Request
5
- };
6
- // type RequestPagination = (reqData: Partial<PageParam>, options?: Options) => Promise<PaginationData<any>>;
7
- interface PageParam {
8
- page: number
9
- page_size: number
10
- }
11
- interface PageInfo {
12
- has_more: boolean
13
- page: number
14
- page_size: number
15
- total: number
16
- }
17
- interface PageData<T = any> {
18
- list: T[] | null
19
- pagination: PaginationInfo
20
- [k in string]: any
21
- }
22
- interface Result<T = any | PageData<any>> {
23
- code: number
24
- msg: string
25
- data: T
26
- }
27
- type GetParam<A extends Request> = A extends (reqData: infer R) => any ? R : any;
28
- type GetData<A extends Request> = ReturnType<A> extends Promise<infer D> ? D : any;
29
- type GetDataItem<A extends Request> = NonNullable<GetData<A>> extends { list: infer L }
30
- ? NonNullable<L> extends Array<infer I>
31
- ? I
32
- : any
33
- : any;
34
- type GetDataField<R> = R extends { data: infer D } ? (D extends { list: any, pagination: any } ? D : D) : any;
35
-
36
- /**
37
- * 将api返回的分页数据转换成前端使用的分页数据格式,将分页数据格式统一
38
- *
39
- * ```
40
- * {
41
- * code: number,
42
- * msg: string,
43
- * data: {
44
- * list: [],
45
- * pagination: {},
46
- * ...
47
- * }
48
- * }
49
- * ```
50
- */
51
- type TransformPageResult<R> = R extends { pagination: infer P, data: infer D }
52
- ? D extends Record<string, any>
53
- ? D extends { list: any }
54
- ? {
55
- [Rk in Exclude<keyof R, 'data' | 'pagination'>]: R[Rk];
56
- } & {
57
- data: D & { pagination: P }
58
- }
59
- : {
60
- [Rk in Exclude<keyof R, 'data' | 'pagination'>]: R[Rk];
61
- } & {
62
- data: {
63
- list: D
64
- pagination: P
65
- }
66
- }
67
- : R
68
- : R;
69
- }
70
-
71
- // 测试用例 ----------------------------
72
- // type DDD1 = Api.TransformPageResult<{
73
- // code: number
74
- // msg: string
75
- // data: {
76
- // name: string
77
- // }[]
78
- // pagination: {
79
- // page: number
80
- // }
81
- // }>
82
- // type DDD2 = Api.TransformPageResult<{
83
- // code: number
84
- // msg: string
85
- // data: {
86
- // list: { name: string }[]
87
- // total: {}
88
- // }
89
- // pagination: {
90
- // page: number
91
- // }
92
- // }>
1
+ declare namespace Api {
2
+ type Request = ((reqData: any, options?: Options) => Promise<any>) & {
3
+ id: string
4
+ setDefaultConfig: (config: Partial<import('axios').AxiosRequestConfig>) => Request
5
+ };
6
+ // type RequestPagination = (reqData: Partial<PageParam>, options?: Options) => Promise<PaginationData<any>>;
7
+ interface PageParam {
8
+ page: number
9
+ page_size: number
10
+ }
11
+ interface PageInfo {
12
+ has_more: boolean
13
+ page: number
14
+ page_size: number
15
+ total: number
16
+ }
17
+ interface PageData<T = any> {
18
+ list: T[] | null
19
+ pagination: PaginationInfo
20
+ [k in string]: any
21
+ }
22
+ interface Result<T = any | PageData<any>> {
23
+ code: number
24
+ msg: string
25
+ data: T
26
+ }
27
+ type GetParam<A extends Request> = A extends (reqData: infer R) => any ? R : any;
28
+ type GetData<A extends Request> = ReturnType<A> extends Promise<infer D> ? D : any;
29
+ type GetDataItem<A extends Request> = NonNullable<GetData<A>> extends { list: infer L }
30
+ ? NonNullable<L> extends Array<infer I>
31
+ ? I
32
+ : any
33
+ : any;
34
+ type GetDataField<R> = R extends { data: infer D } ? (D extends { list: any, pagination: any } ? D : D) : any;
35
+
36
+ /**
37
+ * 将api返回的分页数据转换成前端使用的分页数据格式,将分页数据格式统一
38
+ *
39
+ * ```
40
+ * {
41
+ * code: number,
42
+ * msg: string,
43
+ * data: {
44
+ * list: [],
45
+ * pagination: {},
46
+ * ...
47
+ * }
48
+ * }
49
+ * ```
50
+ */
51
+ type TransformPageResult<R> = R extends { pagination: infer P, data: infer D }
52
+ ? D extends Record<string, any>
53
+ ? D extends { list: any }
54
+ ? {
55
+ [Rk in Exclude<keyof R, 'data' | 'pagination'>]: R[Rk];
56
+ } & {
57
+ data: D & { pagination: P }
58
+ }
59
+ : {
60
+ [Rk in Exclude<keyof R, 'data' | 'pagination'>]: R[Rk];
61
+ } & {
62
+ data: {
63
+ list: D
64
+ pagination: P
65
+ }
66
+ }
67
+ : R
68
+ : R;
69
+ }
70
+
71
+ // 测试用例 ----------------------------
72
+ // type DDD1 = Api.TransformPageResult<{
73
+ // code: number
74
+ // msg: string
75
+ // data: {
76
+ // name: string
77
+ // }[]
78
+ // pagination: {
79
+ // page: number
80
+ // }
81
+ // }>
82
+ // type DDD2 = Api.TransformPageResult<{
83
+ // code: number
84
+ // msg: string
85
+ // data: {
86
+ // list: { name: string }[]
87
+ // total: {}
88
+ // }
89
+ // pagination: {
90
+ // page: number
91
+ // }
92
+ // }>
@@ -1,7 +1,7 @@
1
- module.exports = {
2
- // root: true,
3
- extends: ['@peng_kai/lint/vue/stylelint_v2'],
4
- rules: {
5
- 'custom-property-pattern': '(antd-([a-z][a-zA-Z0-9]+)*)|(([a-z][a-z0-9]*)(-[a-z0-9]+)*)',
6
- },
7
- };
1
+ module.exports = {
2
+ // root: true,
3
+ extends: ['@peng_kai/lint/vue/stylelint_v2'],
4
+ rules: {
5
+ 'custom-property-pattern': '(antd-([a-z][a-zA-Z0-9]+)*)|(([a-z][a-z0-9]*)(-[a-z0-9]+)*)',
6
+ },
7
+ };
package/tsconfig.json CHANGED
@@ -1,50 +1,50 @@
1
- {
2
- "compilerOptions": {
3
- "target": "ES2020",
4
- "jsx": "preserve",
5
- "jsxFactory": "h",
6
- "jsxFragmentFactory": "Fragment",
7
- "lib": [
8
- "ESNext",
9
- "DOM",
10
- "DOM.Iterable"
11
- ],
12
- "useDefineForClassFields": true,
13
- "module": "ESNext",
14
-
15
- /* Bundler mode */
16
- "moduleResolution": "bundler",
17
- "resolveJsonModule": true,
18
- "allowImportingTsExtensions": true,
19
-
20
- /* Linting */
21
- "strict": true,
22
- "noFallthroughCasesInSwitch": true,
23
- "noImplicitAny": false,
24
- "noUnusedLocals": true,
25
- "noUnusedParameters": true,
26
- "noEmit": true,
27
- "allowSyntheticDefaultImports": true,
28
- "esModuleInterop": true,
29
- "isolatedModules": true,
30
- "skipLibCheck": true
31
- },
32
- "include": [
33
- "admin/**/*.ts",
34
- "admin/**/*.d.ts",
35
- "admin/**/*.tsx",
36
- "admin/**/*.vue",
37
- "antd/**/*.ts",
38
- "antd/**/*.d.ts",
39
- "antd/**/*.tsx",
40
- "antd/**/*.vue",
41
- "request/**/*.ts",
42
- "request/**/*.d.ts",
43
- "utils/**/*.ts",
44
- "utils/**/*.d.ts",
45
- "vue/**/*.ts",
46
- "vue/**/*.d.ts",
47
- "vue/**/*.tsx",
48
- "vue/**/*.vue"
49
- ]
50
- }
1
+ {
2
+ "compilerOptions": {
3
+ "target": "ES2020",
4
+ "jsx": "preserve",
5
+ "jsxFactory": "h",
6
+ "jsxFragmentFactory": "Fragment",
7
+ "lib": [
8
+ "ESNext",
9
+ "DOM",
10
+ "DOM.Iterable"
11
+ ],
12
+ "useDefineForClassFields": true,
13
+ "module": "ESNext",
14
+
15
+ /* Bundler mode */
16
+ "moduleResolution": "bundler",
17
+ "resolveJsonModule": true,
18
+ "allowImportingTsExtensions": true,
19
+
20
+ /* Linting */
21
+ "strict": true,
22
+ "noFallthroughCasesInSwitch": true,
23
+ "noImplicitAny": false,
24
+ "noUnusedLocals": true,
25
+ "noUnusedParameters": true,
26
+ "noEmit": true,
27
+ "allowSyntheticDefaultImports": true,
28
+ "esModuleInterop": true,
29
+ "isolatedModules": true,
30
+ "skipLibCheck": true
31
+ },
32
+ "include": [
33
+ "admin/**/*.ts",
34
+ "admin/**/*.d.ts",
35
+ "admin/**/*.tsx",
36
+ "admin/**/*.vue",
37
+ "antd/**/*.ts",
38
+ "antd/**/*.d.ts",
39
+ "antd/**/*.tsx",
40
+ "antd/**/*.vue",
41
+ "request/**/*.ts",
42
+ "request/**/*.d.ts",
43
+ "utils/**/*.ts",
44
+ "utils/**/*.d.ts",
45
+ "vue/**/*.ts",
46
+ "vue/**/*.d.ts",
47
+ "vue/**/*.tsx",
48
+ "vue/**/*.vue"
49
+ ]
50
+ }
package/utils/index.ts CHANGED
@@ -84,7 +84,7 @@ export function getScanBrowser(chain: string, hash: string, type: 'transaction'
84
84
  'POLYGON': () => `https://polygonscan.com/${evmType()}/${hash}`,
85
85
  'OKEXCHAIN': () => `https://www.okx.com/cn/explorer/oktc/${evmType()}/${hash}`,
86
86
  'OPBNB': () => `https://opbnbscan.com/${evmType()}/${hash}`,
87
- 'APOTS': () => {
87
+ 'APTOS': () => {
88
88
  const _type = (<TypeMap>{ transaction: 'txn', address: 'account' })[type] ?? type;
89
89
  return `https://explorer.aptoslabs.com/${_type}/${hash}`;
90
90
  },
@@ -98,7 +98,7 @@ export function getScanBrowser(chain: string, hash: string, type: 'transaction'
98
98
  },
99
99
  'ZKSYNC': () => `https://explorer.zksync.io/${evmType()}/${hash}`,
100
100
  'SOLANA': () => {
101
- const _type = (<TypeMap>{ address: 'account' })[type] ?? type;
101
+ const _type = (<TypeMap>{ address: 'account', transaction: 'tx' })[type] ?? type;
102
102
  return `https://solscan.io/${_type}/${hash}`;
103
103
  },
104
104
  }[_chain] ?? (() => '');
@@ -1 +1 @@
1
- export { default as InfiniteQuery } from './src/InfiniteQuery.vue';
1
+ export { default as InfiniteQuery } from './src/InfiniteQuery.vue';