@peng_kai/kit 0.0.9 → 0.0.10
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/admin/components/scroll-nav/src/ScrollNav.vue +59 -59
- package/admin/components/text/index.ts +13 -13
- package/admin/components/text/src/Amount.vue +114 -114
- package/admin/components/text/src/Datetime.vue +44 -45
- package/admin/components/text/src/Duration.vue +26 -26
- package/admin/components/text/src/Hash.vue +40 -40
- package/admin/components/text/src/createTagGetter.ts +13 -13
- package/admin/filter/FilterDrawer.vue +96 -96
- package/admin/filter/FilterParam.vue +76 -76
- package/admin/hooks/useMenu.ts +128 -132
- package/admin/hooks/usePage.ts +139 -138
- package/admin/hooks/usePageTab.ts +35 -35
- package/admin/layout/large/Breadcrumb.vue +70 -68
- package/admin/layout/large/Content.vue +24 -23
- package/admin/layout/large/Menu.vue +68 -73
- package/admin/layout/large/PageTab.vue +71 -70
- package/antd/components/InputNumberRange.vue +47 -47
- package/antd/hooks/useAntdDrawer.ts +73 -73
- package/antd/hooks/useAntdTable.ts +70 -70
- package/components/infinite-query/index.ts +1 -1
- package/components/infinite-query/src/InfiniteQuery.vue +147 -147
- package/components/infinite-query/src/useCreateTrigger.ts +35 -35
- package/kitDependencies.ts +26 -6
- package/package.json +40 -40
- package/request/helpers.ts +32 -32
- package/request/type.d.ts +89 -89
- package/tsconfig.json +17 -17
- package/pnpm-lock.yaml +0 -598
|
@@ -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/kitDependencies.ts
CHANGED
|
@@ -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
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
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.
|
|
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.10",
|
|
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
|
+
}
|
package/request/helpers.ts
CHANGED
|
@@ -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
|
+
}
|