@peng_kai/kit 0.0.13 → 0.0.15

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 (33) 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 -44
  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/defines/defineRoute.helpers.ts +10 -3
  9. package/admin/filter/FilterDrawer.vue +96 -96
  10. package/admin/filter/FilterParam.vue +76 -76
  11. package/admin/hooks/useMenu.ts +128 -128
  12. package/admin/hooks/usePage.ts +139 -139
  13. package/admin/hooks/usePageTab.ts +35 -35
  14. package/admin/layout/large/Breadcrumb.vue +70 -70
  15. package/admin/layout/large/Content.vue +24 -24
  16. package/admin/layout/large/Menu.vue +68 -68
  17. package/admin/layout/large/PageTab.vue +71 -71
  18. package/admin/styles/globalCover.scss +43 -43
  19. package/antd/components/InputNumberRange.vue +47 -47
  20. package/antd/directives/formLabelAlign.ts +30 -30
  21. package/antd/hooks/useAntdDrawer.ts +73 -73
  22. package/antd/hooks/useAntdTable.ts +70 -70
  23. package/components/infinite-query/index.ts +1 -1
  24. package/components/infinite-query/src/InfiniteQuery.vue +147 -147
  25. package/components/infinite-query/src/useCreateTrigger.ts +35 -35
  26. package/package.json +40 -40
  27. package/pnpm-lock.yaml +598 -0
  28. package/request/helpers.ts +32 -32
  29. package/request/interceptors/popupMessage.ts +2 -2
  30. package/request/interceptors/unitizeAxiosError.ts +2 -2
  31. package/request/type.d.ts +89 -89
  32. package/tsconfig.json +17 -17
  33. package/utils/index.ts +10 -0
@@ -1 +1 @@
1
- export { default as InfiniteQuery } from './src/InfiniteQuery.vue'
1
+ export { default as InfiniteQuery } from './src/InfiniteQuery.vue'
@@ -1,147 +1,147 @@
1
- <script lang="ts">
2
- import { computed, ref, unref } from "vue";
3
- import type { UseInfiniteQueryReturnType } from '@tanstack/vue-query'
4
- import { useCreateTrigger } from './useCreateTrigger'
5
- </script>
6
-
7
- <script setup lang="ts" generic="T extends UseInfiniteQueryReturnType<any, any>">
8
- type TPage = T extends UseInfiniteQueryReturnType<infer P, any> ? NonNullable<P> : any
9
- type TRecord = TPage extends { list: Array<infer I> } ? I : any
10
-
11
- const props = defineProps<{
12
- queryier: T
13
- }>()
14
-
15
- const { queryier } = props
16
- const pages = computed(() => queryier.data.value?.pages)
17
- // TODO: 状态之间的互斥仍有问题
18
- const isInitialLoading = computed(() => queryier.isInitialLoading.value)
19
- const isInitialLoadingError = computed(() => queryier.isLoadingError.value && !isInitialLoading.value)
20
- const isMoreLoading = computed(
21
- () => (queryier.isFetchingNextPage.value || queryier.isFetching.value) && !isInitialLoading.value,
22
- )
23
- const isMoreLoadingError = computed(() => queryier.isRefetchError.value && !isMoreLoading.value)
24
- const noMore = computed(
25
- () =>
26
- !queryier.hasNextPage?.value
27
- && !isInitialLoading.value
28
- && !isInitialLoadingError.value
29
- && !isMoreLoading.value
30
- && !isMoreLoadingError.value,
31
- )
32
- const $container = ref<HTMLElement>()
33
- const containerCssVars = computed(() => {
34
- const ctnEle = unref($container)
35
-
36
- if (!ctnEle)
37
- return {}
38
-
39
- const rect = ctnEle.getBoundingClientRect()
40
-
41
- return {
42
- '--ctn-height': `${rect.height}px`,
43
- }
44
- })
45
-
46
- function refetch() {
47
- queryier.refetch()
48
- }
49
-
50
- function refetchLastPage() {
51
- queryier.refetch({
52
- refetchPage(lastPage: any, _index, allPages: any[]) {
53
- const lastIndex = allPages?.length - 1
54
- return lastPage?.pagination?.page === allPages?.[lastIndex]?.pagination?.page
55
- },
56
- })
57
- }
58
-
59
- function fetchNextPage() {
60
- const { isFetching, isLoading, hasNextPage } = queryier
61
-
62
- if (isFetching.value || isLoading.value || !hasNextPage?.value)
63
- return
64
-
65
- queryier.fetchNextPage()
66
- }
67
-
68
- function triggerFetchNextPage() {
69
- if (queryier.isError.value)
70
- return
71
-
72
- fetchNextPage()
73
- }
74
-
75
- useCreateTrigger($container, triggerFetchNextPage)
76
- </script>
77
-
78
- <template>
79
- <div ref="$container" class="infinite-query-wrapper" :style="containerCssVars">
80
- <div v-if="isInitialLoading" class="initial-loading">
81
- <i class="i-svg-spinners:180-ring-with-bg loading-icon" />
82
- </div>
83
- <div v-if="isInitialLoadingError" class="initial-loading-error" @click="refetch()">
84
- <span>加载失败,点击重试</span>
85
- </div>
86
-
87
- <div v-for="(page, i) of pages" :key="i">
88
- <template v-for="record of page.list">
89
- <slot :record="record as TRecord" />
90
- </template>
91
- </div>
92
-
93
- <div v-if="isMoreLoading" class="more-loading">
94
- <i class="i-svg-spinners:180-ring-with-bg loading-icon" />
95
- <span class="ml-1 text">加载中...</span>
96
- </div>
97
- <div v-if="isMoreLoadingError" class="more-loading-error" @click="fetchNextPage()">
98
- <span class="text">加载失败,点击重试</span>
99
- </div>
100
- <div v-if="noMore" class="no-more" @click="refetchLastPage()">
101
- <span class="text">暂无更多</span>
102
- </div>
103
- </div>
104
- </template>
105
-
106
- <style scoped lang="scss">
107
- .infinite-query-wrapper {
108
- overflow: auto;
109
- font-size: 14px;
110
- }
111
-
112
- .loading-icon {
113
- display: block;
114
- color: var(--antd-colorPrimary);
115
- font-size: 1.2em;
116
- }
117
-
118
- .initial-loading,
119
- .initial-loading-error,
120
- .more-loading,
121
- .more-loading-error,
122
- .no-more {
123
- display: flex;
124
- align-items: center;
125
- justify-content: center;
126
- color: var(--antd-colorTextSecondary);
127
- }
128
-
129
- .initial-loading,
130
- .initial-loading-error {
131
- height: var(--ctn-height, 100px);
132
- }
133
-
134
- .initial-loading-error {
135
- cursor: pointer;
136
- }
137
-
138
- .more-loading,
139
- .more-loading-error,
140
- .no-more {
141
- height: 50px;
142
- }
143
-
144
- .more-loading-error {
145
- cursor: pointer;
146
- }
147
- </style>
1
+ <script lang="ts">
2
+ import { computed, ref, unref } from "vue";
3
+ import type { UseInfiniteQueryReturnType } from '@tanstack/vue-query'
4
+ import { useCreateTrigger } from './useCreateTrigger'
5
+ </script>
6
+
7
+ <script setup lang="ts" generic="T extends UseInfiniteQueryReturnType<any, any>">
8
+ type TPage = T extends UseInfiniteQueryReturnType<infer P, any> ? NonNullable<P> : any
9
+ type TRecord = TPage extends { list: Array<infer I> } ? I : any
10
+
11
+ const props = defineProps<{
12
+ queryier: T
13
+ }>()
14
+
15
+ const { queryier } = props
16
+ const pages = computed(() => queryier.data.value?.pages)
17
+ // TODO: 状态之间的互斥仍有问题
18
+ const isInitialLoading = computed(() => queryier.isInitialLoading.value)
19
+ const isInitialLoadingError = computed(() => queryier.isLoadingError.value && !isInitialLoading.value)
20
+ const isMoreLoading = computed(
21
+ () => (queryier.isFetchingNextPage.value || queryier.isFetching.value) && !isInitialLoading.value,
22
+ )
23
+ const isMoreLoadingError = computed(() => queryier.isRefetchError.value && !isMoreLoading.value)
24
+ const noMore = computed(
25
+ () =>
26
+ !queryier.hasNextPage?.value
27
+ && !isInitialLoading.value
28
+ && !isInitialLoadingError.value
29
+ && !isMoreLoading.value
30
+ && !isMoreLoadingError.value,
31
+ )
32
+ const $container = ref<HTMLElement>()
33
+ const containerCssVars = computed(() => {
34
+ const ctnEle = unref($container)
35
+
36
+ if (!ctnEle)
37
+ return {}
38
+
39
+ const rect = ctnEle.getBoundingClientRect()
40
+
41
+ return {
42
+ '--ctn-height': `${rect.height}px`,
43
+ }
44
+ })
45
+
46
+ function refetch() {
47
+ queryier.refetch()
48
+ }
49
+
50
+ function refetchLastPage() {
51
+ queryier.refetch({
52
+ refetchPage(lastPage: any, _index, allPages: any[]) {
53
+ const lastIndex = allPages?.length - 1
54
+ return lastPage?.pagination?.page === allPages?.[lastIndex]?.pagination?.page
55
+ },
56
+ })
57
+ }
58
+
59
+ function fetchNextPage() {
60
+ const { isFetching, isLoading, hasNextPage } = queryier
61
+
62
+ if (isFetching.value || isLoading.value || !hasNextPage?.value)
63
+ return
64
+
65
+ queryier.fetchNextPage()
66
+ }
67
+
68
+ function triggerFetchNextPage() {
69
+ if (queryier.isError.value)
70
+ return
71
+
72
+ fetchNextPage()
73
+ }
74
+
75
+ useCreateTrigger($container, triggerFetchNextPage)
76
+ </script>
77
+
78
+ <template>
79
+ <div ref="$container" class="infinite-query-wrapper" :style="containerCssVars">
80
+ <div v-if="isInitialLoading" class="initial-loading">
81
+ <i class="i-svg-spinners:180-ring-with-bg loading-icon" />
82
+ </div>
83
+ <div v-if="isInitialLoadingError" class="initial-loading-error" @click="refetch()">
84
+ <span>加载失败,点击重试</span>
85
+ </div>
86
+
87
+ <div v-for="(page, i) of pages" :key="i">
88
+ <template v-for="record of page.list">
89
+ <slot :record="record as TRecord" />
90
+ </template>
91
+ </div>
92
+
93
+ <div v-if="isMoreLoading" class="more-loading">
94
+ <i class="i-svg-spinners:180-ring-with-bg loading-icon" />
95
+ <span class="ml-1 text">加载中...</span>
96
+ </div>
97
+ <div v-if="isMoreLoadingError" class="more-loading-error" @click="fetchNextPage()">
98
+ <span class="text">加载失败,点击重试</span>
99
+ </div>
100
+ <div v-if="noMore" class="no-more" @click="refetchLastPage()">
101
+ <span class="text">暂无更多</span>
102
+ </div>
103
+ </div>
104
+ </template>
105
+
106
+ <style scoped lang="scss">
107
+ .infinite-query-wrapper {
108
+ overflow: auto;
109
+ font-size: 14px;
110
+ }
111
+
112
+ .loading-icon {
113
+ display: block;
114
+ color: var(--antd-colorPrimary);
115
+ font-size: 1.2em;
116
+ }
117
+
118
+ .initial-loading,
119
+ .initial-loading-error,
120
+ .more-loading,
121
+ .more-loading-error,
122
+ .no-more {
123
+ display: flex;
124
+ align-items: center;
125
+ justify-content: center;
126
+ color: var(--antd-colorTextSecondary);
127
+ }
128
+
129
+ .initial-loading,
130
+ .initial-loading-error {
131
+ height: var(--ctn-height, 100px);
132
+ }
133
+
134
+ .initial-loading-error {
135
+ cursor: pointer;
136
+ }
137
+
138
+ .more-loading,
139
+ .more-loading-error,
140
+ .no-more {
141
+ height: 50px;
142
+ }
143
+
144
+ .more-loading-error {
145
+ cursor: pointer;
146
+ }
147
+ </style>
@@ -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
+ }
package/package.json CHANGED
@@ -1,40 +1,40 @@
1
- {
2
- "name": "@peng_kai/kit",
3
- "version": "0.0.13",
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.15",
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
+ }