@peng_kai/kit 0.0.1
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/antd/admin/FilterDrawer.vue +95 -0
- package/antd/admin/FilterParam.vue +76 -0
- package/antd/admin/FilterReset.vue +22 -0
- package/antd/admin/index.ts +3 -0
- package/antd/hooks/createAntdModal.ts +61 -0
- package/antd/hooks/useAntdDrawer.ts +73 -0
- package/antd/hooks/useAntdForm.helpers.ts +48 -0
- package/antd/hooks/useAntdForm.ts +91 -0
- package/antd/hooks/useAntdModal.ts +65 -0
- package/antd/hooks/useAntdTable.ts +70 -0
- package/antd/index.ts +5 -0
- package/component/infinite-query/index.ts +1 -0
- package/component/infinite-query/src/InfiniteQuery.vue +147 -0
- package/component/infinite-query/src/useCreateTrigger.ts +35 -0
- package/package.json +38 -0
- package/pnpm-lock.yaml +586 -0
- package/request/helpers.ts +52 -0
- package/request/index.ts +0 -0
- package/request/interceptors/checkCode.ts +25 -0
- package/request/interceptors/formatPaging.ts +23 -0
- package/request/interceptors/index.ts +5 -0
- package/request/interceptors/popupMessage.ts +47 -0
- package/request/interceptors/returnResultType.ts +30 -0
- package/request/interceptors/unitizeAxiosError.ts +20 -0
- package/request/request.ts +89 -0
- package/request/type.d.ts +89 -0
- package/tsconfig.json +18 -0
- package/vue/hooks/useComponentRef.ts +27 -0
- package/vue/hooks/useTeleportTarget.ts +13 -0
- package/vue/index.ts +2 -0
|
@@ -0,0 +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>
|
|
@@ -0,0 +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
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@peng_kai/kit",
|
|
3
|
+
"version": "0.0.1",
|
|
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
|
+
},
|
|
22
|
+
"devDependencies": {
|
|
23
|
+
"@types/lodash-es": "^4.17.10",
|
|
24
|
+
"@types/node": "18",
|
|
25
|
+
"type-fest": "^4.6.0",
|
|
26
|
+
"vue-component-type-helpers": "^1.8.22"
|
|
27
|
+
},
|
|
28
|
+
"peerDependencies": {
|
|
29
|
+
"@tanstack/vue-query": "4.x",
|
|
30
|
+
"@vueuse/core": "10.x",
|
|
31
|
+
"ant-design-vue": "4.0.x",
|
|
32
|
+
"axios": "1.6.x",
|
|
33
|
+
"bignumber.js": "9.x",
|
|
34
|
+
"dayjs": "1.x",
|
|
35
|
+
"lodash-es": "4.x",
|
|
36
|
+
"vue": "3.3.x"
|
|
37
|
+
}
|
|
38
|
+
}
|