@peng_kai/kit 0.0.14 → 0.0.16

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 (91) hide show
  1. package/.vscode/settings.json +41 -0
  2. package/admin/components/filter/index.ts +5 -0
  3. package/admin/{filter → components/filter/src}/FilterDrawer.vue +99 -96
  4. package/admin/{filter → components/filter/src}/FilterParam.vue +76 -76
  5. package/admin/{filter → components/filter/src}/FilterReset.vue +7 -4
  6. package/admin/{filter → components/filter/src}/useFilterParams.ts +9 -9
  7. package/admin/{filter → components/filter/src}/useFilterQuery.ts +11 -11
  8. package/admin/components/scroll-nav/index.ts +1 -1
  9. package/admin/components/scroll-nav/src/ScrollNav.vue +59 -59
  10. package/admin/components/text/index.ts +13 -13
  11. package/admin/components/text/src/Amount.vue +117 -114
  12. package/admin/components/text/src/Datetime.vue +44 -44
  13. package/admin/components/text/src/Duration.vue +26 -26
  14. package/admin/components/text/src/Hash.vue +42 -40
  15. package/admin/components/text/src/createTagGetter.ts +13 -13
  16. package/admin/defines/index.ts +4 -5
  17. package/admin/defines/page/definePage.ts +12 -0
  18. package/admin/defines/page/index.ts +1 -0
  19. package/admin/defines/route/defineRoute.ts +14 -0
  20. package/admin/defines/route/getRoutes.ts +84 -0
  21. package/admin/defines/route/helpers.ts +49 -0
  22. package/admin/defines/route/index.ts +73 -0
  23. package/admin/defines/route-guard/defineRouteGuard.ts +18 -0
  24. package/admin/defines/route-guard/getRouteGuards.ts +40 -0
  25. package/admin/defines/route-guard/index.ts +2 -0
  26. package/admin/defines/startup/defineStartup.ts +11 -0
  27. package/admin/defines/startup/getStartups.ts +30 -0
  28. package/admin/defines/startup/index.ts +2 -0
  29. package/admin/hooks/index.ts +5 -6
  30. package/admin/hooks/useMenu.ts +128 -128
  31. package/admin/hooks/usePage.ts +141 -139
  32. package/admin/hooks/usePageTab.ts +35 -35
  33. package/admin/layout/large/Breadcrumb.vue +69 -70
  34. package/admin/layout/large/Content.vue +24 -24
  35. package/admin/layout/large/Menu.vue +69 -68
  36. package/admin/layout/large/PageTab.vue +71 -71
  37. package/admin/layout/large/index.ts +4 -4
  38. package/admin/permission/index.ts +4 -0
  39. package/admin/permission/routerGuard.ts +43 -0
  40. package/admin/permission/usePermission.ts +52 -0
  41. package/admin/permission/vuePlugin.ts +30 -0
  42. package/admin/route-guards/index.ts +2 -0
  43. package/admin/route-guards/pageProgress.ts +16 -0
  44. package/admin/route-guards/pageTitle.ts +24 -0
  45. package/admin/styles/globalCover.scss +43 -43
  46. package/admin/types/assist.ts +10 -0
  47. package/admin/unocss/index.ts +1 -1
  48. package/antd/components/InputNumberRange.vue +53 -47
  49. package/antd/directives/formLabelAlign.ts +36 -31
  50. package/antd/hooks/createAntdModal.ts +29 -29
  51. package/antd/hooks/useAntdDrawer.ts +73 -73
  52. package/antd/hooks/useAntdForm.helpers.ts +18 -18
  53. package/antd/hooks/useAntdForm.ts +38 -37
  54. package/antd/hooks/useAntdModal.ts +25 -25
  55. package/antd/hooks/useAntdTable.ts +70 -70
  56. package/antd/hooks/useAntdTheme.ts +86 -0
  57. package/antd/index.ts +8 -7
  58. package/eslint.config.js +50 -0
  59. package/kitDependencies.ts +21 -7
  60. package/package.json +46 -40
  61. package/pnpm-lock.yaml +2689 -0
  62. package/request/helpers.ts +49 -32
  63. package/request/index.ts +2 -2
  64. package/request/interceptors/checkCode.ts +8 -8
  65. package/request/interceptors/filterEmptyValue.ts +9 -9
  66. package/request/interceptors/formatPaging.ts +12 -12
  67. package/request/interceptors/index.ts +7 -6
  68. package/request/interceptors/popupMessage.ts +35 -35
  69. package/request/interceptors/returnResultType.ts +19 -19
  70. package/request/interceptors/toLogin.ts +13 -0
  71. package/request/interceptors/unitizeAxiosError.ts +7 -7
  72. package/request/queryClient.ts +42 -0
  73. package/request/request.ts +21 -21
  74. package/request/type.d.ts +89 -89
  75. package/tsconfig.json +47 -18
  76. package/utils/index.ts +67 -29
  77. package/vue/components/index.ts +1 -0
  78. package/{components → vue/components}/infinite-query/index.ts +1 -1
  79. package/{components → vue/components}/infinite-query/src/InfiniteQuery.vue +147 -147
  80. package/{components → vue/components}/infinite-query/src/useCreateTrigger.ts +35 -35
  81. package/vue/hooks/useComponentRef.ts +12 -12
  82. package/vue/hooks/useIsMounted.ts +4 -4
  83. package/vue/hooks/useTeleportTarget.ts +7 -7
  84. package/vue/index.ts +4 -3
  85. package/admin/defines/definePage.ts +0 -14
  86. package/admin/defines/defineRoute.helpers.ts +0 -30
  87. package/admin/defines/defineRoute.ts +0 -161
  88. package/admin/defines/defineRouteGuard.ts +0 -56
  89. package/admin/defines/defineStartup.ts +0 -41
  90. package/admin/filter/index.ts +0 -5
  91. package/admin/hooks/usePermission.ts +0 -5
package/request/type.d.ts CHANGED
@@ -1,89 +1,89 @@
1
- declare namespace Api {
2
- type Request = ((reqData: any, options?: Options) => Promise<any>) & { id: string }
3
- // type RequestPagination = (reqData: Partial<PageParam>, options?: Options) => Promise<PaginationData<any>>;
4
- interface PageParam {
5
- page: number
6
- page_size: number
7
- }
8
- interface PageInfo {
9
- has_more: boolean
10
- page: number
11
- page_size: number
12
- total: number
13
- }
14
- interface PageData<T = any> {
15
- list: T[] | null
16
- pagination: PaginationInfo
17
- [k in string]: any
18
- }
19
- interface Result<T = any | PageData<any>> {
20
- code: number
21
- msg: string
22
- data: T
23
- }
24
- type GetParam<A extends Request> = A extends (reqData: infer R) => any ? R : any
25
- type GetData<A extends Request> = ReturnType<A> extends Promise<infer D> ? D : any
26
- type GetDataItem<A extends Request> = NonNullable<GetData<A>> extends { list: infer L }
27
- ? NonNullable<L> extends Array<infer I>
28
- ? I
29
- : any
30
- : any
31
- type GetDataField<R> = R extends { data: infer D } ? (D extends { list: any; pagination: any } ? D : D) : any
32
-
33
- /**
34
- * 将api返回的分页数据转换成前端使用的分页数据格式,将分页数据格式统一
35
- *
36
- * ```
37
- * {
38
- * code: number,
39
- * msg: string,
40
- * data: {
41
- * list: [],
42
- * pagination: {},
43
- * ...
44
- * }
45
- * }
46
- * ```
47
- */
48
- type TransformPageResult<R> = R extends { pagination: infer P; data: infer D }
49
- ? D extends Record<string, any>
50
- ? D extends { list: any }
51
- ? {
52
- [Rk in Exclude<keyof R, 'data' | 'pagination'>]: R[Rk];
53
- } & {
54
- data: D & { pagination: P }
55
- }
56
- : {
57
- [Rk in Exclude<keyof R, 'data' | 'pagination'>]: R[Rk];
58
- } & {
59
- data: {
60
- list: D
61
- pagination: P
62
- }
63
- }
64
- : R
65
- : R
66
- }
67
-
68
- // 测试用例 ----------------------------
69
- // type DDD1 = Api.TransformPageResult<{
70
- // code: number
71
- // msg: string
72
- // data: {
73
- // name: string
74
- // }[]
75
- // pagination: {
76
- // page: number
77
- // }
78
- // }>
79
- // type DDD2 = Api.TransformPageResult<{
80
- // code: number
81
- // msg: string
82
- // data: {
83
- // list: { name: string }[]
84
- // total: {}
85
- // }
86
- // pagination: {
87
- // page: number
88
- // }
89
- // }>
1
+ declare namespace Api {
2
+ type Request = ((reqData: any, options?: Options) => Promise<any>) & { id: string };
3
+ // type RequestPagination = (reqData: Partial<PageParam>, options?: Options) => Promise<PaginationData<any>>;
4
+ interface PageParam {
5
+ page: number
6
+ page_size: number
7
+ }
8
+ interface PageInfo {
9
+ has_more: boolean
10
+ page: number
11
+ page_size: number
12
+ total: number
13
+ }
14
+ interface PageData<T = any> {
15
+ list: T[] | null
16
+ pagination: PaginationInfo
17
+ [k in string]: any
18
+ }
19
+ interface Result<T = any | PageData<any>> {
20
+ code: number
21
+ msg: string
22
+ data: T
23
+ }
24
+ type GetParam<A extends Request> = A extends (reqData: infer R) => any ? R : any;
25
+ type GetData<A extends Request> = ReturnType<A> extends Promise<infer D> ? D : any;
26
+ type GetDataItem<A extends Request> = NonNullable<GetData<A>> extends { list: infer L }
27
+ ? NonNullable<L> extends Array<infer I>
28
+ ? I
29
+ : any
30
+ : any;
31
+ type GetDataField<R> = R extends { data: infer D } ? (D extends { list: any, pagination: any } ? D : D) : any;
32
+
33
+ /**
34
+ * 将api返回的分页数据转换成前端使用的分页数据格式,将分页数据格式统一
35
+ *
36
+ * ```
37
+ * {
38
+ * code: number,
39
+ * msg: string,
40
+ * data: {
41
+ * list: [],
42
+ * pagination: {},
43
+ * ...
44
+ * }
45
+ * }
46
+ * ```
47
+ */
48
+ type TransformPageResult<R> = R extends { pagination: infer P, data: infer D }
49
+ ? D extends Record<string, any>
50
+ ? D extends { list: any }
51
+ ? {
52
+ [Rk in Exclude<keyof R, 'data' | 'pagination'>]: R[Rk];
53
+ } & {
54
+ data: D & { pagination: P }
55
+ }
56
+ : {
57
+ [Rk in Exclude<keyof R, 'data' | 'pagination'>]: R[Rk];
58
+ } & {
59
+ data: {
60
+ list: D
61
+ pagination: P
62
+ }
63
+ }
64
+ : R
65
+ : R;
66
+ }
67
+
68
+ // 测试用例 ----------------------------
69
+ // type DDD1 = Api.TransformPageResult<{
70
+ // code: number
71
+ // msg: string
72
+ // data: {
73
+ // name: string
74
+ // }[]
75
+ // pagination: {
76
+ // page: number
77
+ // }
78
+ // }>
79
+ // type DDD2 = Api.TransformPageResult<{
80
+ // code: number
81
+ // msg: string
82
+ // data: {
83
+ // list: { name: string }[]
84
+ // total: {}
85
+ // }
86
+ // pagination: {
87
+ // page: number
88
+ // }
89
+ // }>
package/tsconfig.json CHANGED
@@ -1,18 +1,47 @@
1
- {
2
- "compilerOptions": {
3
- "target": "es2019",
4
- "module": "esnext",
5
- "lib": [
6
- "esnext",
7
- "dom"
8
- ],
9
- "moduleResolution": "node",
10
- "esModuleInterop": true,
11
- "strict": true,
12
- "strictNullChecks": true,
13
- "resolveJsonModule": true,
14
- "skipDefaultLibCheck": true,
15
- "skipLibCheck": true,
16
- "jsx": "preserve",
17
- },
18
- }
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
+ "noUnusedLocals": true,
24
+ "noUnusedParameters": true,
25
+ "noEmit": true,
26
+ "isolatedModules": true,
27
+ "skipLibCheck": true
28
+ },
29
+ "include": [
30
+ "admin/**/*.ts",
31
+ "admin/**/*.d.ts",
32
+ "admin/**/*.tsx",
33
+ "admin/**/*.vue",
34
+ "antd/**/*.ts",
35
+ "antd/**/*.d.ts",
36
+ "antd/**/*.tsx",
37
+ "antd/**/*.vue",
38
+ "request/**/*.ts",
39
+ "request/**/*.d.ts",
40
+ "utils/**/*.ts",
41
+ "utils/**/*.d.ts",
42
+ "vue/**/*.ts",
43
+ "vue/**/*.d.ts",
44
+ "vue/**/*.tsx",
45
+ "vue/**/*.vue"
46
+ ]
47
+ }
package/utils/index.ts CHANGED
@@ -1,17 +1,17 @@
1
1
  export const ENV = {
2
2
  get isDev() {
3
- return (import.meta as any).env.DEV
3
+ return (import.meta as any).env.DEV;
4
4
  },
5
5
  get isProd() {
6
- return (import.meta as any).env.PROD
6
+ return (import.meta as any).env.PROD;
7
7
  },
8
8
  get isStaging() {
9
- return (import.meta as any).env.MODE === 'staging'
9
+ return (import.meta as any).env.MODE === 'staging';
10
10
  },
11
11
  get isTest() {
12
- return this.isDev || this.isStaging
12
+ return this.isDev || this.isStaging;
13
13
  },
14
- }
14
+ };
15
15
 
16
16
  /**
17
17
  * 睡眠
@@ -19,8 +19,15 @@ export const ENV = {
19
19
  */
20
20
  export function sleep(dur: number) {
21
21
  return new Promise((resolve) => {
22
- setTimeout(resolve, dur)
23
- })
22
+ setTimeout(resolve, dur);
23
+ });
24
+ }
25
+
26
+ /**
27
+ * 是否有授权 Token
28
+ */
29
+ export function hasToken() {
30
+ return document.cookie.includes('has_token=1');
24
31
  }
25
32
 
26
33
  /**
@@ -31,17 +38,16 @@ export function sleep(dur: number) {
31
38
  */
32
39
  export function desensitize(str: string | undefined | null, startChars = 4, endChars?: number) {
33
40
  if (!str)
34
- return ''
41
+ return '';
35
42
 
36
- // eslint-disable-next-line no-param-reassign
37
- endChars ??= startChars
43
+ endChars ??= startChars;
38
44
 
39
45
  if (startChars + endChars >= str.length)
40
- return str
46
+ return str;
41
47
 
42
- const truncatedStr = `${str.substring(0, startChars)}...${str.substring(str.length - endChars)}`
48
+ const truncatedStr = `${str.substring(0, startChars)}...${str.substring(str.length - endChars)}`;
43
49
 
44
- return truncatedStr
50
+ return truncatedStr;
45
51
  }
46
52
 
47
53
  /**
@@ -51,23 +57,37 @@ export function desensitize(str: string | undefined | null, startChars = 4, endC
51
57
  * @param type 哈希类型
52
58
  */
53
59
  export function getScanBrowser(chain: string, hash: string, type: 'transaction' | 'address' = 'transaction') {
54
- const _chain = chain.toUpperCase()
55
- const evmType = type === 'transaction' ? 'tx' : type
60
+ type TypeMap = Partial<Record<typeof type, string>>;
56
61
 
57
- const url = {
58
- TRON: `https://tronscan.org/#/${type}/${hash}`,
59
- ETH: `https://etherscan.io/${evmType}/${hash}`,
60
- ETHEREUM: `https://etherscan.io/${evmType}/${hash}`,
61
- BSC: `https://bscscan.com/${evmType}/${hash}`,
62
- BINANCE: `https://bscscan.com/${evmType}/${hash}`,
63
- BASE: `https://basescan.org/${type}/${hash}`,
64
- HECO: `https://hecoscan.io/#/${type}/${hash}`,
65
- POLYGON: `https://polygonscan.com/${type}/${hash}`,
66
- OKEXCHAIN: `https://www.okx.com/cn/explorer/oktc/${type}/${hash}`,
67
- OPBNB: `https://opbnbscan.com/${type}/${hash}`,
68
- }[_chain] ?? ''
62
+ const _chain = chain.toUpperCase();
63
+ const evmType = () => type === 'transaction' ? 'tx' : type;
64
+ const urlFn = {
65
+ TRON: () => `https://tronscan.org/#/${type}/${hash}`,
66
+ ETH: () => `https://etherscan.io/${evmType()}/${hash}`,
67
+ ETHEREUM: () => `https://etherscan.io/${evmType()}/${hash}`,
68
+ BSC: () => `https://bscscan.com/${evmType()}/${hash}`,
69
+ BINANCE: () => `https://bscscan.com/${evmType()}/${hash}`,
70
+ BASE: () => `https://basescan.org/${evmType()}/${hash}`,
71
+ HECO: () => `https://hecoscan.io/#/${evmType}/${hash}`,
72
+ POLYGON: () => `https://polygonscan.com/${evmType()}/${hash}`,
73
+ OKEXCHAIN: () => `https://www.okx.com/cn/explorer/oktc/${evmType()}/${hash}`,
74
+ OPBNB: () => `https://opbnbscan.com/${evmType()}/${hash}`,
75
+ APOTS: () => {
76
+ const _type = (<TypeMap>{ transaction: 'txn', address: 'account' })[type] ?? type;
77
+ return `https://explorer.aptoslabs.com/${_type}/${hash}`;
78
+ },
79
+ ARBITRUM: () => `https://arbiscan.io/${evmType()}/${hash}`,
80
+ AVALANCHE: () => `https://subnets.avax.network/c-chain/${evmType()}/${hash}`,
81
+ FANTOM: () => `https://ftmscan.com/${evmType()}/${hash}`,
82
+ OPTIMISM: () => `https://optimistic.etherscan.io/${evmType()}/${hash}`,
83
+ SUI: () => {
84
+ const _type = (<TypeMap>{ transaction: 'txblock' })[type] ?? type;
85
+ return `https://suiexplorer.com/${_type}/${hash}`;
86
+ },
87
+ ZKSYNC: () => `https://explorer.zksync.io/${evmType()}/${hash}`,
88
+ }[_chain] ?? (() => '');
69
89
 
70
- return url
90
+ return urlFn();
71
91
  }
72
92
 
73
93
  /**
@@ -75,5 +95,23 @@ export function getScanBrowser(chain: string, hash: string, type: 'transaction'
75
95
  * @param link 链接
76
96
  */
77
97
  export function getTelegramBrowser(link: string) {
78
- return `https://t.me/${link}`
98
+ return `https://t.me/${link}`;
99
+ }
100
+
101
+ /**
102
+ * 删除当前页面 URL 中的指定查询参数
103
+ * @param key 查询参数的 Key
104
+ */
105
+ export function removeUrlSearchParam(key: string) {
106
+ const url = new URL(window.location.href);
107
+ url.searchParams.delete(key);
108
+ window.history.replaceState({}, '', url);
109
+ }
110
+
111
+ export function createSelfKeyProxy<T extends object>() {
112
+ return new Proxy({} as T, {
113
+ get(_, p) {
114
+ return p;
115
+ },
116
+ });
79
117
  }
@@ -0,0 +1 @@
1
+ export { InfiniteQuery } from './infinite-query';
@@ -1 +1 @@
1
- export { default as InfiniteQuery } from './src/InfiniteQuery.vue'
1
+ export { default as InfiniteQuery } from './src/InfiniteQuery.vue';