@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,73 +1,68 @@
|
|
|
1
|
-
<script lang="ts">
|
|
2
|
-
import { computed, ref, watch } from "vue";
|
|
3
|
-
import { Menu as AMenu } from "ant-design-vue";
|
|
4
|
-
import type { ItemType } from 'ant-design-vue'
|
|
5
|
-
import {
|
|
6
|
-
import
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
const router =
|
|
26
|
-
const { menus, getMenuPath } = useMenu()
|
|
27
|
-
const items = computed(() => menus.map(formatMenu))
|
|
28
|
-
const openKeys = ref<string[]>([])
|
|
29
|
-
const selectedKeys = ref<string[]>([])
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
.ant-menu {
|
|
70
|
-
background-color: transparent;
|
|
71
|
-
}
|
|
72
|
-
}
|
|
73
|
-
</style>
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
import { computed, ref, watch } from "vue";
|
|
3
|
+
import { Menu as AMenu } from "ant-design-vue";
|
|
4
|
+
import type { ItemType } from 'ant-design-vue'
|
|
5
|
+
import type { TMenu } from '../../hooks'
|
|
6
|
+
import { getDependencies } from "../../../kitDependencies";
|
|
7
|
+
|
|
8
|
+
function formatMenu(menu: TMenu): ItemType {
|
|
9
|
+
return {
|
|
10
|
+
key: menu.key,
|
|
11
|
+
title: menu.label,
|
|
12
|
+
label: menu.label,
|
|
13
|
+
icon: menu.icon ?? undefined,
|
|
14
|
+
onClick: (e) => {
|
|
15
|
+
(e as any).stopPropagation()
|
|
16
|
+
menu.trigger()
|
|
17
|
+
},
|
|
18
|
+
children: menu.children?.map(formatMenu),
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
</script>
|
|
22
|
+
|
|
23
|
+
<script setup lang="ts">
|
|
24
|
+
const{ useRouter, useMenu } = getDependencies()
|
|
25
|
+
const router = useRouter()
|
|
26
|
+
const { menus, getMenuPath } = useMenu()
|
|
27
|
+
const items = computed(() => menus.map(formatMenu))
|
|
28
|
+
const openKeys = ref<string[]>([])
|
|
29
|
+
const selectedKeys = ref<string[]>([])
|
|
30
|
+
|
|
31
|
+
watch(
|
|
32
|
+
() => router?.currentRoute.value,
|
|
33
|
+
(route) => {
|
|
34
|
+
if (!route) return;
|
|
35
|
+
|
|
36
|
+
const menuPath = getMenuPath(route.name as string)
|
|
37
|
+
openKeys.value = menuPath.map(menu => menu.key)
|
|
38
|
+
selectedKeys.value = [openKeys.value.pop()!]
|
|
39
|
+
},
|
|
40
|
+
{ immediate: true },
|
|
41
|
+
)
|
|
42
|
+
</script>
|
|
43
|
+
|
|
44
|
+
<template>
|
|
45
|
+
<AMenu
|
|
46
|
+
class="menu"
|
|
47
|
+
:items="items"
|
|
48
|
+
:openKeys="openKeys"
|
|
49
|
+
:selectedKeys="selectedKeys"
|
|
50
|
+
mode="inline"
|
|
51
|
+
:inlineIndent="14"
|
|
52
|
+
/>
|
|
53
|
+
</template>
|
|
54
|
+
|
|
55
|
+
<style lang="scss" scoped>
|
|
56
|
+
.menu {
|
|
57
|
+
border-inline-end: none !important;
|
|
58
|
+
|
|
59
|
+
&.ant-menu-inline-collapsed {
|
|
60
|
+
width: var(--app-siderbar-width);
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
&,
|
|
64
|
+
.ant-menu {
|
|
65
|
+
background-color: transparent;
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
</style>
|
|
@@ -1,70 +1,71 @@
|
|
|
1
|
-
<script setup lang="ts">
|
|
2
|
-
import { Tabs as ATabs, TabPane as ATabPane } from "ant-design-vue";
|
|
3
|
-
import {
|
|
4
|
-
|
|
5
|
-
const {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
:
|
|
16
|
-
:
|
|
17
|
-
|
|
18
|
-
@
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
</
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
:deep(.ant-tabs-tab
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
:deep(.ant-tabs-tab
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
}
|
|
70
|
-
|
|
1
|
+
<script setup lang="ts">
|
|
2
|
+
import { Tabs as ATabs, TabPane as ATabPane } from "ant-design-vue";
|
|
3
|
+
import { getDependencies } from "../../../kitDependencies";
|
|
4
|
+
|
|
5
|
+
const { usePageTab } = getDependencies()
|
|
6
|
+
const { activeTab, tabList, openTab, closeTab } = usePageTab()
|
|
7
|
+
</script>
|
|
8
|
+
|
|
9
|
+
<template>
|
|
10
|
+
<ATabs
|
|
11
|
+
class="app-page-tabs"
|
|
12
|
+
:activeKey="activeTab"
|
|
13
|
+
type="editable-card"
|
|
14
|
+
size="small"
|
|
15
|
+
:animated="false"
|
|
16
|
+
:hideAdd="true"
|
|
17
|
+
:tabBarGutter="4"
|
|
18
|
+
@tabClick="(openTab as any)"
|
|
19
|
+
@edit="(closeTab as any)"
|
|
20
|
+
>
|
|
21
|
+
<ATabPane v-for="tab of tabList" :key="tab.key" :tab="tab.title">
|
|
22
|
+
<template #closeIcon>
|
|
23
|
+
<i class="i-icon-park-outline:close" />
|
|
24
|
+
</template>
|
|
25
|
+
</ATabPane>
|
|
26
|
+
</ATabs>
|
|
27
|
+
</template>
|
|
28
|
+
|
|
29
|
+
<style scoped lang="scss">
|
|
30
|
+
.app-page-tabs {
|
|
31
|
+
:deep(.ant-tabs-nav) {
|
|
32
|
+
margin: 0;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
:deep(.ant-tabs-nav::before) {
|
|
36
|
+
display: none;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
:deep(.ant-tabs-tab) {
|
|
40
|
+
--uno: 'border-rd-3px! text-14px p-[3px_1px_3px_8px]! select-none';
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
:deep(.ant-tabs-tab .ant-tabs-tab-btn) {
|
|
44
|
+
transform: translateX(8px);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
:deep(.ant-tabs-tab-active) {
|
|
48
|
+
--uno: 'border-[currentColor]!';
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
:deep(.ant-tabs-tab-remove) {
|
|
52
|
+
display: flex;
|
|
53
|
+
height: 100%;
|
|
54
|
+
align-items: center;
|
|
55
|
+
margin: 0;
|
|
56
|
+
opacity: 0;
|
|
57
|
+
transition: all 150ms;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
:deep(.ant-tabs-tab:hover .ant-tabs-tab-btn),
|
|
61
|
+
:deep(.ant-tabs-tab-active .ant-tabs-tab-btn) {
|
|
62
|
+
transform: translateX(0);
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
:deep(.ant-tabs-tab:hover .ant-tabs-tab-remove),
|
|
66
|
+
:deep(.ant-tabs-tab-active .ant-tabs-tab-remove) {
|
|
67
|
+
margin-left: 0;
|
|
68
|
+
opacity: 1;
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
</style>
|
|
@@ -1,47 +1,47 @@
|
|
|
1
|
-
<script setup lang="ts">
|
|
2
|
-
import { computed } from "vue";
|
|
3
|
-
import { Form, InputNumber as AInputNumber } from 'ant-design-vue'
|
|
4
|
-
|
|
5
|
-
const props = withDefaults(
|
|
6
|
-
defineProps<{
|
|
7
|
-
value: [number, number]
|
|
8
|
-
min?: number
|
|
9
|
-
max?: number
|
|
10
|
-
}>(),
|
|
11
|
-
{
|
|
12
|
-
min: Number.NEGATIVE_INFINITY,
|
|
13
|
-
max: Number.POSITIVE_INFINITY,
|
|
14
|
-
},
|
|
15
|
-
)
|
|
16
|
-
const emits = defineEmits<{
|
|
17
|
-
(e: 'update:value', value: [number, number]): void
|
|
18
|
-
}>()
|
|
19
|
-
|
|
20
|
-
const formItemContext = Form.useInjectFormItemContext()
|
|
21
|
-
const minValue = computed({
|
|
22
|
-
get() {
|
|
23
|
-
return props.value[0]
|
|
24
|
-
},
|
|
25
|
-
set(value) {
|
|
26
|
-
emits('update:value', [value, props.value[1]])
|
|
27
|
-
formItemContext.onFieldChange()
|
|
28
|
-
},
|
|
29
|
-
})
|
|
30
|
-
const maxValue = computed({
|
|
31
|
-
get() {
|
|
32
|
-
return props.value[1]
|
|
33
|
-
},
|
|
34
|
-
set(value) {
|
|
35
|
-
emits('update:value', [props.value[0], value])
|
|
36
|
-
formItemContext.onFieldChange()
|
|
37
|
-
},
|
|
38
|
-
})
|
|
39
|
-
</script>
|
|
40
|
-
|
|
41
|
-
<template>
|
|
42
|
-
<div class="flex items-center">
|
|
43
|
-
<AInputNumber v-model:value="minValue" class="w-full" :min="props.min" :max="props.max" />
|
|
44
|
-
<span> ~ </span>
|
|
45
|
-
<AInputNumber v-model:value="maxValue" class="w-full" :min="props.min" :max="props.max" />
|
|
46
|
-
</div>
|
|
47
|
-
</template>
|
|
1
|
+
<script setup lang="ts">
|
|
2
|
+
import { computed } from "vue";
|
|
3
|
+
import { Form, InputNumber as AInputNumber } from 'ant-design-vue'
|
|
4
|
+
|
|
5
|
+
const props = withDefaults(
|
|
6
|
+
defineProps<{
|
|
7
|
+
value: [number, number]
|
|
8
|
+
min?: number
|
|
9
|
+
max?: number
|
|
10
|
+
}>(),
|
|
11
|
+
{
|
|
12
|
+
min: Number.NEGATIVE_INFINITY,
|
|
13
|
+
max: Number.POSITIVE_INFINITY,
|
|
14
|
+
},
|
|
15
|
+
)
|
|
16
|
+
const emits = defineEmits<{
|
|
17
|
+
(e: 'update:value', value: [number, number]): void
|
|
18
|
+
}>()
|
|
19
|
+
|
|
20
|
+
const formItemContext = Form.useInjectFormItemContext()
|
|
21
|
+
const minValue = computed({
|
|
22
|
+
get() {
|
|
23
|
+
return props.value[0]
|
|
24
|
+
},
|
|
25
|
+
set(value) {
|
|
26
|
+
emits('update:value', [value, props.value[1]])
|
|
27
|
+
formItemContext.onFieldChange()
|
|
28
|
+
},
|
|
29
|
+
})
|
|
30
|
+
const maxValue = computed({
|
|
31
|
+
get() {
|
|
32
|
+
return props.value[1]
|
|
33
|
+
},
|
|
34
|
+
set(value) {
|
|
35
|
+
emits('update:value', [props.value[0], value])
|
|
36
|
+
formItemContext.onFieldChange()
|
|
37
|
+
},
|
|
38
|
+
})
|
|
39
|
+
</script>
|
|
40
|
+
|
|
41
|
+
<template>
|
|
42
|
+
<div class="flex items-center">
|
|
43
|
+
<AInputNumber v-model:value="minValue" class="w-full" :min="props.min" :max="props.max" />
|
|
44
|
+
<span> ~ </span>
|
|
45
|
+
<AInputNumber v-model:value="maxValue" class="w-full" :min="props.min" :max="props.max" />
|
|
46
|
+
</div>
|
|
47
|
+
</template>
|
|
@@ -1,73 +1,73 @@
|
|
|
1
|
-
import { Button as AButton, Drawer as ADrawer, Space as ASpace } from 'ant-design-vue'
|
|
2
|
-
import { defineComponent, isProxy, reactive, toRefs, toRef, h } from 'vue'
|
|
3
|
-
import type { Component } from 'vue'
|
|
4
|
-
import type { ButtonProps, DrawerProps } from 'ant-design-vue'
|
|
5
|
-
import type { ComponentProps } from 'vue-component-type-helpers'
|
|
6
|
-
import type { Writable } from 'type-fest'
|
|
7
|
-
import { useComponentRef } from '../../vue'
|
|
8
|
-
|
|
9
|
-
const defaultDrawerProps: DrawerProps = { open: false, destroyOnClose: true }
|
|
10
|
-
|
|
11
|
-
interface IComponentConfig<Comp extends Component> {
|
|
12
|
-
is: Comp
|
|
13
|
-
props?: Writable<ComponentProps<Comp>>
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
export function useAntdDrawer<Comp extends Component>(
|
|
17
|
-
comp: IComponentConfig<Comp> | Comp,
|
|
18
|
-
drawerProps = defaultDrawerProps,
|
|
19
|
-
) {
|
|
20
|
-
const _comp = ({ props: {}, ...((comp as any)?.is ? comp : { is: comp }) }) as Required<IComponentConfig<Comp>>
|
|
21
|
-
const compProps = reactive(_comp.props)
|
|
22
|
-
const compRef = useComponentRef(_comp.is)
|
|
23
|
-
const _drawerProps: DrawerProps = reactive({
|
|
24
|
-
...defaultDrawerProps,
|
|
25
|
-
...isProxy(drawerProps) ? toRefs(drawerProps) : drawerProps,
|
|
26
|
-
})
|
|
27
|
-
|
|
28
|
-
const open = (newBodyProps?: Partial<typeof compProps>, newAntdModalProps?: Omit<Partial<DrawerProps>, 'open'>) => {
|
|
29
|
-
Object.assign(_drawerProps, newAntdModalProps)
|
|
30
|
-
Object.assign(compProps, newBodyProps)
|
|
31
|
-
_drawerProps.open = true
|
|
32
|
-
}
|
|
33
|
-
const close = () => {
|
|
34
|
-
_drawerProps.open = false
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
const DrawerExtra = defineComponent({
|
|
38
|
-
setup() {
|
|
39
|
-
const cancelBtnProps: ButtonProps = reactive({ onClick: close })
|
|
40
|
-
const confirmBtnProps: ButtonProps = reactive({
|
|
41
|
-
type: 'primary',
|
|
42
|
-
loading: toRef(() => (compRef as any)?.loading),
|
|
43
|
-
onClick: () => (compRef as any)?.confirm?.(),
|
|
44
|
-
})
|
|
45
|
-
|
|
46
|
-
return { cancelBtnProps, confirmBtnProps }
|
|
47
|
-
},
|
|
48
|
-
render() {
|
|
49
|
-
const { cancelBtnProps, confirmBtnProps } = this
|
|
50
|
-
|
|
51
|
-
return h(ASpace, {}, () => [
|
|
52
|
-
h(AButton, cancelBtnProps, () => '取消'),
|
|
53
|
-
h(AButton, confirmBtnProps, () => '确定'),
|
|
54
|
-
])
|
|
55
|
-
},
|
|
56
|
-
})
|
|
57
|
-
const PresetComponent = defineComponent({
|
|
58
|
-
render() {
|
|
59
|
-
return h(ADrawer, _drawerProps, {
|
|
60
|
-
default: () => h(_comp.is, compProps as any),
|
|
61
|
-
})
|
|
62
|
-
},
|
|
63
|
-
})
|
|
64
|
-
|
|
65
|
-
_drawerProps.extra = _drawerProps.extra === undefined ? h(DrawerExtra) : _drawerProps.extra
|
|
66
|
-
_drawerProps['onUpdate:open'] = (visiable) => {
|
|
67
|
-
_drawerProps.open = visiable
|
|
68
|
-
}
|
|
69
|
-
(compProps as any).ref = compRef;
|
|
70
|
-
(compProps as any).onClose = close
|
|
71
|
-
|
|
72
|
-
return { PresetComponent, drawerProps: _drawerProps, open, close }
|
|
73
|
-
}
|
|
1
|
+
import { Button as AButton, Drawer as ADrawer, Space as ASpace } from 'ant-design-vue'
|
|
2
|
+
import { defineComponent, isProxy, reactive, toRefs, toRef, h } from 'vue'
|
|
3
|
+
import type { Component } from 'vue'
|
|
4
|
+
import type { ButtonProps, DrawerProps } from 'ant-design-vue'
|
|
5
|
+
import type { ComponentProps } from 'vue-component-type-helpers'
|
|
6
|
+
import type { Writable } from 'type-fest'
|
|
7
|
+
import { useComponentRef } from '../../vue'
|
|
8
|
+
|
|
9
|
+
const defaultDrawerProps: DrawerProps = { open: false, destroyOnClose: true }
|
|
10
|
+
|
|
11
|
+
interface IComponentConfig<Comp extends Component> {
|
|
12
|
+
is: Comp
|
|
13
|
+
props?: Writable<ComponentProps<Comp>>
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export function useAntdDrawer<Comp extends Component>(
|
|
17
|
+
comp: IComponentConfig<Comp> | Comp,
|
|
18
|
+
drawerProps = defaultDrawerProps,
|
|
19
|
+
) {
|
|
20
|
+
const _comp = ({ props: {}, ...((comp as any)?.is ? comp : { is: comp }) }) as Required<IComponentConfig<Comp>>
|
|
21
|
+
const compProps = reactive(_comp.props)
|
|
22
|
+
const compRef = useComponentRef(_comp.is)
|
|
23
|
+
const _drawerProps: DrawerProps = reactive({
|
|
24
|
+
...defaultDrawerProps,
|
|
25
|
+
...isProxy(drawerProps) ? toRefs(drawerProps) : drawerProps,
|
|
26
|
+
})
|
|
27
|
+
|
|
28
|
+
const open = (newBodyProps?: Partial<typeof compProps>, newAntdModalProps?: Omit<Partial<DrawerProps>, 'open'>) => {
|
|
29
|
+
Object.assign(_drawerProps, newAntdModalProps)
|
|
30
|
+
Object.assign(compProps, newBodyProps)
|
|
31
|
+
_drawerProps.open = true
|
|
32
|
+
}
|
|
33
|
+
const close = () => {
|
|
34
|
+
_drawerProps.open = false
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
const DrawerExtra = defineComponent({
|
|
38
|
+
setup() {
|
|
39
|
+
const cancelBtnProps: ButtonProps = reactive({ onClick: close })
|
|
40
|
+
const confirmBtnProps: ButtonProps = reactive({
|
|
41
|
+
type: 'primary',
|
|
42
|
+
loading: toRef(() => (compRef as any)?.loading),
|
|
43
|
+
onClick: () => (compRef as any)?.confirm?.(),
|
|
44
|
+
})
|
|
45
|
+
|
|
46
|
+
return { cancelBtnProps, confirmBtnProps }
|
|
47
|
+
},
|
|
48
|
+
render() {
|
|
49
|
+
const { cancelBtnProps, confirmBtnProps } = this
|
|
50
|
+
|
|
51
|
+
return h(ASpace, {}, () => [
|
|
52
|
+
h(AButton, cancelBtnProps, () => '取消'),
|
|
53
|
+
h(AButton, confirmBtnProps, () => '确定'),
|
|
54
|
+
])
|
|
55
|
+
},
|
|
56
|
+
})
|
|
57
|
+
const PresetComponent = defineComponent({
|
|
58
|
+
render() {
|
|
59
|
+
return h(ADrawer, _drawerProps, {
|
|
60
|
+
default: () => h(_comp.is, compProps as any),
|
|
61
|
+
})
|
|
62
|
+
},
|
|
63
|
+
})
|
|
64
|
+
|
|
65
|
+
_drawerProps.extra = _drawerProps.extra === undefined ? h(DrawerExtra) : _drawerProps.extra
|
|
66
|
+
_drawerProps['onUpdate:open'] = (visiable) => {
|
|
67
|
+
_drawerProps.open = visiable
|
|
68
|
+
}
|
|
69
|
+
(compProps as any).ref = compRef;
|
|
70
|
+
(compProps as any).onClose = close
|
|
71
|
+
|
|
72
|
+
return { PresetComponent, drawerProps: _drawerProps, open, close }
|
|
73
|
+
}
|
|
@@ -1,70 +1,70 @@
|
|
|
1
|
-
import { computed } from 'vue'
|
|
2
|
-
import type { UseQueryReturnType } from '@tanstack/vue-query'
|
|
3
|
-
import type { Table, TableProps } from 'ant-design-vue'
|
|
4
|
-
import type { ColumnType } from 'ant-design-vue/es/table/interface'
|
|
5
|
-
import type { ComponentProps } from 'vue-component-type-helpers'
|
|
6
|
-
|
|
7
|
-
export function useAntdTable<
|
|
8
|
-
UQRR extends UseQueryReturnType<any, any>,
|
|
9
|
-
QP extends Partial<{ page?: string | number; page_size?: string | number }>,
|
|
10
|
-
>(uqrt: UQRR, queryParams: QP) {
|
|
11
|
-
type RecordType = GetRecordType<UQRR>
|
|
12
|
-
type LocalTableProps = TableProps<RecordType>
|
|
13
|
-
type LocalColumnsType = NonNullable<LocalTableProps['columns']>
|
|
14
|
-
|
|
15
|
-
const { data, isFetching, isLoading } = uqrt
|
|
16
|
-
|
|
17
|
-
const onPaginationChange: ComponentProps<typeof Table>['onChange'] = (pagination) => {
|
|
18
|
-
const page = queryParams.page_size !== pagination.pageSize ? 1 : pagination.current
|
|
19
|
-
Object.assign(queryParams, { page, page_size: pagination.pageSize ?? 10 })
|
|
20
|
-
}
|
|
21
|
-
const defineColumns = (columnsFn: () => LocalColumnsType) => computed(columnsFn)
|
|
22
|
-
|
|
23
|
-
const tableProps = computed<LocalTableProps>(() => {
|
|
24
|
-
const { list, pagination } = data.value ?? {}
|
|
25
|
-
|
|
26
|
-
return {
|
|
27
|
-
dataSource: list,
|
|
28
|
-
pagination: {
|
|
29
|
-
disabled: isFetching.value,
|
|
30
|
-
current: Number(queryParams.page ?? 1),
|
|
31
|
-
pageSize: Number(queryParams.page_size ?? 10),
|
|
32
|
-
total: pagination?.total ?? 0,
|
|
33
|
-
},
|
|
34
|
-
loading: isLoading.value,
|
|
35
|
-
scroll: { x: 'max-content' },
|
|
36
|
-
sticky: true,
|
|
37
|
-
onChange: onPaginationChange as any,
|
|
38
|
-
}
|
|
39
|
-
})
|
|
40
|
-
const dataIndexs = new Proxy({} as Record<keyof RecordType, string>, {
|
|
41
|
-
get(_, p) {
|
|
42
|
-
return p
|
|
43
|
-
},
|
|
44
|
-
})
|
|
45
|
-
const bodyCellType = {} as {
|
|
46
|
-
index: number
|
|
47
|
-
text: any
|
|
48
|
-
value: any
|
|
49
|
-
record: RecordType
|
|
50
|
-
column: ColumnType<RecordType>
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
return {
|
|
54
|
-
/** ATable 的预设 Props */
|
|
55
|
-
tableProps,
|
|
56
|
-
/** 【类型辅助】基于接口数据类型推导出的 dataIndex,供 columns 的 dataIndex 使用 */
|
|
57
|
-
dataIndexs,
|
|
58
|
-
/** 【类型辅助】bodyCell 插槽数据的精确类型描述 */
|
|
59
|
-
bodyCellType,
|
|
60
|
-
/** 【类型辅助】用于定义出类型精确的 columns */
|
|
61
|
-
defineColumns,
|
|
62
|
-
onPaginationChange,
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
type GetRecordType<T> = T extends UseQueryReturnType<infer D, any>
|
|
67
|
-
? D extends Api.PageData
|
|
68
|
-
? NonNullable<D['list']>[0]
|
|
69
|
-
: never
|
|
70
|
-
: never
|
|
1
|
+
import { computed } from 'vue'
|
|
2
|
+
import type { UseQueryReturnType } from '@tanstack/vue-query'
|
|
3
|
+
import type { Table, TableProps } from 'ant-design-vue'
|
|
4
|
+
import type { ColumnType } from 'ant-design-vue/es/table/interface'
|
|
5
|
+
import type { ComponentProps } from 'vue-component-type-helpers'
|
|
6
|
+
|
|
7
|
+
export function useAntdTable<
|
|
8
|
+
UQRR extends UseQueryReturnType<any, any>,
|
|
9
|
+
QP extends Partial<{ page?: string | number; page_size?: string | number }>,
|
|
10
|
+
>(uqrt: UQRR, queryParams: QP) {
|
|
11
|
+
type RecordType = GetRecordType<UQRR>
|
|
12
|
+
type LocalTableProps = TableProps<RecordType>
|
|
13
|
+
type LocalColumnsType = NonNullable<LocalTableProps['columns']>
|
|
14
|
+
|
|
15
|
+
const { data, isFetching, isLoading } = uqrt
|
|
16
|
+
|
|
17
|
+
const onPaginationChange: ComponentProps<typeof Table>['onChange'] = (pagination) => {
|
|
18
|
+
const page = queryParams.page_size !== pagination.pageSize ? 1 : pagination.current
|
|
19
|
+
Object.assign(queryParams, { page, page_size: pagination.pageSize ?? 10 })
|
|
20
|
+
}
|
|
21
|
+
const defineColumns = (columnsFn: () => LocalColumnsType) => computed(columnsFn)
|
|
22
|
+
|
|
23
|
+
const tableProps = computed<LocalTableProps>(() => {
|
|
24
|
+
const { list, pagination } = data.value ?? {}
|
|
25
|
+
|
|
26
|
+
return {
|
|
27
|
+
dataSource: list,
|
|
28
|
+
pagination: {
|
|
29
|
+
disabled: isFetching.value,
|
|
30
|
+
current: Number(queryParams.page ?? 1),
|
|
31
|
+
pageSize: Number(queryParams.page_size ?? 10),
|
|
32
|
+
total: pagination?.total ?? 0,
|
|
33
|
+
},
|
|
34
|
+
loading: isLoading.value,
|
|
35
|
+
scroll: { x: 'max-content' },
|
|
36
|
+
sticky: true,
|
|
37
|
+
onChange: onPaginationChange as any,
|
|
38
|
+
}
|
|
39
|
+
})
|
|
40
|
+
const dataIndexs = new Proxy({} as Record<keyof RecordType, string>, {
|
|
41
|
+
get(_, p) {
|
|
42
|
+
return p
|
|
43
|
+
},
|
|
44
|
+
})
|
|
45
|
+
const bodyCellType = {} as {
|
|
46
|
+
index: number
|
|
47
|
+
text: any
|
|
48
|
+
value: any
|
|
49
|
+
record: RecordType
|
|
50
|
+
column: ColumnType<RecordType>
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
return {
|
|
54
|
+
/** ATable 的预设 Props */
|
|
55
|
+
tableProps,
|
|
56
|
+
/** 【类型辅助】基于接口数据类型推导出的 dataIndex,供 columns 的 dataIndex 使用 */
|
|
57
|
+
dataIndexs,
|
|
58
|
+
/** 【类型辅助】bodyCell 插槽数据的精确类型描述 */
|
|
59
|
+
bodyCellType,
|
|
60
|
+
/** 【类型辅助】用于定义出类型精确的 columns */
|
|
61
|
+
defineColumns,
|
|
62
|
+
onPaginationChange,
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
type GetRecordType<T> = T extends UseQueryReturnType<infer D, any>
|
|
67
|
+
? D extends Api.PageData
|
|
68
|
+
? NonNullable<D['list']>[0]
|
|
69
|
+
: never
|
|
70
|
+
: never
|