@peng_kai/kit 0.0.9 → 0.0.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 (38) hide show
  1. package/admin/components/scroll-nav/src/ScrollNav.vue +59 -59
  2. package/admin/components/text/index.ts +13 -13
  3. package/admin/components/text/src/Amount.vue +114 -114
  4. package/admin/components/text/src/Datetime.vue +44 -45
  5. package/admin/components/text/src/Duration.vue +26 -26
  6. package/admin/components/text/src/Hash.vue +40 -40
  7. package/admin/components/text/src/createTagGetter.ts +13 -13
  8. package/admin/filter/FilterDrawer.vue +96 -96
  9. package/admin/filter/FilterParam.vue +76 -76
  10. package/admin/filter/FilterReset.vue +2 -2
  11. package/admin/filter/index.ts +2 -1
  12. package/admin/filter/useFilterParams.ts +4 -3
  13. package/admin/filter/useFilterQuery.ts +31 -0
  14. package/admin/hooks/useMenu.ts +128 -132
  15. package/admin/hooks/usePage.ts +139 -138
  16. package/admin/hooks/usePageTab.ts +35 -35
  17. package/admin/layout/large/Breadcrumb.vue +70 -68
  18. package/admin/layout/large/Content.vue +24 -23
  19. package/admin/layout/large/Menu.vue +68 -73
  20. package/admin/layout/large/PageTab.vue +71 -70
  21. package/admin/styles/classCover.scss +108 -0
  22. package/admin/styles/globalCover.scss +43 -0
  23. package/admin/styles/index.scss +30 -0
  24. package/admin/unocss/index.ts +6 -0
  25. package/antd/components/InputNumberRange.vue +47 -47
  26. package/antd/hooks/useAntdDrawer.ts +73 -73
  27. package/antd/hooks/useAntdForm.ts +14 -5
  28. package/antd/hooks/useAntdTable.ts +70 -70
  29. package/antd/index.ts +1 -1
  30. package/components/infinite-query/index.ts +1 -1
  31. package/components/infinite-query/src/InfiniteQuery.vue +147 -147
  32. package/components/infinite-query/src/useCreateTrigger.ts +35 -35
  33. package/kitDependencies.ts +26 -6
  34. package/package.json +40 -40
  35. package/request/helpers.ts +32 -32
  36. package/request/type.d.ts +89 -89
  37. package/tsconfig.json +17 -17
  38. package/pnpm-lock.yaml +0 -598
@@ -1,35 +1,35 @@
1
- import { watch } from "vue";
2
- import type { Ref } from "vue";
3
- import { useIntersectionObserver, useIntervalFn } from '@vueuse/core'
4
-
5
- export function useCreateTrigger(containerEle: Ref<HTMLElement | undefined>, callback: Function) {
6
- const triggerEl = document.createElement('div')
7
-
8
- Object.assign(triggerEl.style, {
9
- position: 'relative',
10
- zIndex: '5',
11
- marginTop: '-150px',
12
- marginBottom: '150px',
13
- width: '5px',
14
- height: '5px',
15
- // background: 'red',
16
- } satisfies Partial<CSSStyleDeclaration>)
17
-
18
- useIntervalFn(() => {
19
- const { transform } = triggerEl.style
20
-
21
- if (transform)
22
- triggerEl.style.removeProperty('transform')
23
- else triggerEl.style.setProperty('transform', 'translateX(-200%)')
24
- }, 500)
25
-
26
- useIntersectionObserver(triggerEl, ([entry]) => {
27
- if (entry.isIntersecting)
28
- callback()
29
- })
30
-
31
- watch(containerEle, (ele) => {
32
- if (ele)
33
- ele.append(triggerEl)
34
- })
35
- }
1
+ import { watch } from "vue";
2
+ import type { Ref } from "vue";
3
+ import { useIntersectionObserver, useIntervalFn } from '@vueuse/core'
4
+
5
+ export function useCreateTrigger(containerEle: Ref<HTMLElement | undefined>, callback: Function) {
6
+ const triggerEl = document.createElement('div')
7
+
8
+ Object.assign(triggerEl.style, {
9
+ position: 'relative',
10
+ zIndex: '5',
11
+ marginTop: '-150px',
12
+ marginBottom: '150px',
13
+ width: '5px',
14
+ height: '5px',
15
+ // background: 'red',
16
+ } satisfies Partial<CSSStyleDeclaration>)
17
+
18
+ useIntervalFn(() => {
19
+ const { transform } = triggerEl.style
20
+
21
+ if (transform)
22
+ triggerEl.style.removeProperty('transform')
23
+ else triggerEl.style.setProperty('transform', 'translateX(-200%)')
24
+ }, 500)
25
+
26
+ useIntersectionObserver(triggerEl, ([entry]) => {
27
+ if (entry.isIntersecting)
28
+ callback()
29
+ })
30
+
31
+ watch(containerEle, (ele) => {
32
+ if (ele)
33
+ ele.append(triggerEl)
34
+ })
35
+ }
@@ -1,9 +1,29 @@
1
- import dayjs from "dayjs";
1
+ import type dayjs from "dayjs";
2
+ import type { useMenu, usePage, usePageTab, usePermission } from "./admin/hooks";
2
3
  import type { useRoute, useRouter } from 'vue-router'
3
4
 
4
- export const kitDependencies = {
5
- dayjs: dayjs,
6
- useRoute: (() => {}) as typeof useRoute,
7
- useRouter: (() => {}) as typeof useRouter,
8
- menus: undefined as any,
5
+ const KEY = '__PK_KIT_DEPENDENCIES__'
6
+
7
+ interface Dependencies {
8
+ dayjs: typeof dayjs
9
+ useRoute: typeof useRoute
10
+ useRouter: typeof useRouter
11
+ useMenu: typeof useMenu
12
+ usePage: typeof usePage
13
+ usePageTab: typeof usePageTab
14
+ usePermission: typeof usePermission
15
+ }
16
+
17
+ export function setDependencies(deps: Partial<Dependencies>) {
18
+ window[KEY] = { ...window[KEY], ...deps }
19
+ }
20
+
21
+ export function getDependencies() {
22
+ return window[KEY]
23
+ }
24
+
25
+ declare global {
26
+ interface Window {
27
+ [KEY]: Dependencies
28
+ }
9
29
  }
package/package.json CHANGED
@@ -1,40 +1,40 @@
1
- {
2
- "name": "@peng_kai/kit",
3
- "version": "0.0.9",
4
- "description": "",
5
- "main": "index.js",
6
- "scripts": {
7
- "test": "echo \"Error: no test specified\" && exit 1"
8
- },
9
- "keywords": [],
10
- "author": "",
11
- "license": "ISC",
12
- "dependencies": {
13
- "@tanstack/vue-query": "^4.37.1",
14
- "@vueuse/core": "^10.5.0",
15
- "ant-design-vue": "^4.0.6",
16
- "axios": "^1.6.0",
17
- "bignumber.js": "^9.1.2",
18
- "dayjs": "^1.11.10",
19
- "lodash-es": "^4.17.21",
20
- "vue": "^3.3.7",
21
- "vue-router": "^4.2.5"
22
- },
23
- "devDependencies": {
24
- "@types/lodash-es": "^4.17.10",
25
- "@types/node": "18",
26
- "type-fest": "^4.6.0",
27
- "vue-component-type-helpers": "^1.8.22"
28
- },
29
- "peerDependencies": {
30
- "@tanstack/vue-query": "4.x",
31
- "@vueuse/core": "10.x",
32
- "ant-design-vue": "4.0.x",
33
- "axios": "1.6.x",
34
- "bignumber.js": "9.x",
35
- "dayjs": "1.x",
36
- "lodash-es": "4.x",
37
- "vue": "3.3.x",
38
- "vue-router": "4.2.x"
39
- }
40
- }
1
+ {
2
+ "name": "@peng_kai/kit",
3
+ "version": "0.0.11",
4
+ "description": "",
5
+ "main": "index.js",
6
+ "scripts": {
7
+ "test": "echo \"Error: no test specified\" && exit 1"
8
+ },
9
+ "keywords": [],
10
+ "author": "",
11
+ "license": "ISC",
12
+ "dependencies": {
13
+ "@tanstack/vue-query": "^4.37.1",
14
+ "@vueuse/core": "^10.5.0",
15
+ "ant-design-vue": "^4.0.6",
16
+ "axios": "^1.6.0",
17
+ "bignumber.js": "^9.1.2",
18
+ "dayjs": "^1.11.10",
19
+ "lodash-es": "^4.17.21",
20
+ "vue": "^3.3.7",
21
+ "vue-router": "^4.2.5"
22
+ },
23
+ "devDependencies": {
24
+ "@types/lodash-es": "^4.17.10",
25
+ "@types/node": "18",
26
+ "type-fest": "^4.6.0",
27
+ "vue-component-type-helpers": "^1.8.22"
28
+ },
29
+ "peerDependencies": {
30
+ "@tanstack/vue-query": "4.x",
31
+ "@vueuse/core": "10.x",
32
+ "ant-design-vue": "4.0.x",
33
+ "axios": "1.6.x",
34
+ "bignumber.js": "9.x",
35
+ "dayjs": "1.x",
36
+ "lodash-es": "4.x",
37
+ "vue": "3.3.x",
38
+ "vue-router": "4.2.x"
39
+ }
40
+ }
@@ -1,32 +1,32 @@
1
- export { isTimeout, ApiCode, ApiError }
2
-
3
- enum ApiCode {
4
- NORMAL = 0, // 正常
5
- UNKNOWN = -1, // 未知错误
6
- TIMEOUT = -2, // 请求超时
7
- }
8
-
9
- function isTimeout(error: any) {
10
- return error?.message?.toLowerCase().includes('timeout')
11
- }
12
-
13
- class ApiError<TResp = any> extends Error {
14
- public static is<ErrorResp = any>(error: any): error is ApiError<ErrorResp> {
15
- return !!error?.isApiError
16
- }
17
-
18
- /**
19
- * 将HTTP status和Api code统一到一个code里
20
- */
21
- public code: number
22
- public msg: string
23
- public data: TResp
24
- public isApiError = true
25
-
26
- public constructor(info: { code: number; msg: string; data: TResp }) {
27
- super(info.msg)
28
- this.code = info.code
29
- this.msg = info.msg
30
- this.data = info.data
31
- }
32
- }
1
+ export { isTimeout, ApiCode, ApiError }
2
+
3
+ enum ApiCode {
4
+ NORMAL = 0, // 正常
5
+ UNKNOWN = -1, // 未知错误
6
+ TIMEOUT = -2, // 请求超时
7
+ }
8
+
9
+ function isTimeout(error: any) {
10
+ return error?.message?.toLowerCase().includes('timeout')
11
+ }
12
+
13
+ class ApiError<TResp = any> extends Error {
14
+ public static is<ErrorResp = any>(error: any): error is ApiError<ErrorResp> {
15
+ return !!error?.isApiError
16
+ }
17
+
18
+ /**
19
+ * 将HTTP status和Api code统一到一个code里
20
+ */
21
+ public code: number
22
+ public msg: string
23
+ public data: TResp
24
+ public isApiError = true
25
+
26
+ public constructor(info: { code: number; msg: string; data: TResp }) {
27
+ super(info.msg)
28
+ this.code = info.code
29
+ this.msg = info.msg
30
+ this.data = info.data
31
+ }
32
+ }
package/request/type.d.ts CHANGED
@@ -1,89 +1,89 @@
1
- declare namespace Api {
2
- type Request = (reqData: any, options?: Options) => Promise<any>
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,18 @@
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
- },
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
18
  }