@peng_kai/kit 0.2.0-beta.0 → 0.2.0-beta.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/adminPlugin.ts +1 -0
- package/admin/components/filter/src/FilterDrawer.vue +153 -153
- package/admin/components/filter/src/FilterParam.vue +1 -1
- package/admin/components/scroll-nav/index.ts +1 -1
- 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 +121 -121
- package/admin/components/text/src/Datetime.vue +1 -1
- package/admin/components/text/src/Duration.vue +26 -26
- package/admin/components/text/src/Hash.vue +51 -51
- package/admin/components/text/src/createTagGetter.ts +13 -13
- package/admin/route-guards/index.ts +3 -3
- package/admin/route-guards/pageProgress.ts +27 -27
- package/admin/styles/globalCover.scss +54 -54
- package/antd/components/InputNumberRange.vue +59 -59
- package/antd/directives/formLabelAlign.ts +36 -36
- package/antd/hooks/useAntdDrawer.ts +73 -73
- package/antd/hooks/useAntdTable.ts +127 -127
- package/libs/dayjs.ts +7 -0
- package/package.json +91 -97
- package/request/helpers.ts +68 -68
- package/request/interceptors/toLogin.ts +26 -26
- package/request/type.d.ts +92 -92
- package/stylelint.config.cjs +7 -7
- package/tsconfig.json +50 -50
- package/utils/date.ts +1 -9
- package/utils/upload/AwsS3.ts +0 -8
- package/vue/components/infinite-query/index.ts +1 -1
- package/vue/components/infinite-query/src/InfiniteQuery.vue +199 -199
- package/vue/components/infinite-query/src/useCreateTrigger.ts +39 -39
|
@@ -1,59 +1,59 @@
|
|
|
1
|
-
<script lang="ts">
|
|
2
|
-
import { computed } from 'vue';
|
|
3
|
-
import { InputNumber as AInputNumber, Form } from 'ant-design-vue';
|
|
4
|
-
</script>
|
|
5
|
-
|
|
6
|
-
<script setup lang="ts">
|
|
7
|
-
const props = withDefaults(
|
|
8
|
-
defineProps<{
|
|
9
|
-
value: [number | undefined, number | undefined]
|
|
10
|
-
placeholder?: [string, string]
|
|
11
|
-
min?: number
|
|
12
|
-
max?: number
|
|
13
|
-
}>(),
|
|
14
|
-
{
|
|
15
|
-
min: Number.NEGATIVE_INFINITY,
|
|
16
|
-
max: Number.POSITIVE_INFINITY,
|
|
17
|
-
},
|
|
18
|
-
);
|
|
19
|
-
const emits = defineEmits<{
|
|
20
|
-
(e: 'update:value', value: typeof props.value): void
|
|
21
|
-
}>();
|
|
22
|
-
|
|
23
|
-
const formItemContext = Form.useInjectFormItemContext();
|
|
24
|
-
const minValue = computed({
|
|
25
|
-
get() {
|
|
26
|
-
return props.value[0];
|
|
27
|
-
},
|
|
28
|
-
set(value) {
|
|
29
|
-
updateValue(value, maxValue.value);
|
|
30
|
-
},
|
|
31
|
-
});
|
|
32
|
-
const maxValue = computed({
|
|
33
|
-
get() {
|
|
34
|
-
return props.value[1];
|
|
35
|
-
},
|
|
36
|
-
set(value) {
|
|
37
|
-
updateValue(minValue.value, value);
|
|
38
|
-
},
|
|
39
|
-
});
|
|
40
|
-
|
|
41
|
-
function updateValue(...args: typeof props.value) {
|
|
42
|
-
emits('update:value', args.sort());
|
|
43
|
-
formItemContext.onFieldChange();
|
|
44
|
-
}
|
|
45
|
-
</script>
|
|
46
|
-
|
|
47
|
-
<template>
|
|
48
|
-
<div class="flex items-center">
|
|
49
|
-
<AInputNumber
|
|
50
|
-
v-model:value="minValue" class="w-full" :min="props.min"
|
|
51
|
-
:max="props.max" :placeholder="props.placeholder?.[0]"
|
|
52
|
-
/>
|
|
53
|
-
<span> - </span>
|
|
54
|
-
<AInputNumber
|
|
55
|
-
v-model:value="maxValue" class="w-full" :min="props.min"
|
|
56
|
-
:max="props.max" :placeholder="props.placeholder?.[1]"
|
|
57
|
-
/>
|
|
58
|
-
</div>
|
|
59
|
-
</template>
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
import { computed } from 'vue';
|
|
3
|
+
import { InputNumber as AInputNumber, Form } from 'ant-design-vue';
|
|
4
|
+
</script>
|
|
5
|
+
|
|
6
|
+
<script setup lang="ts">
|
|
7
|
+
const props = withDefaults(
|
|
8
|
+
defineProps<{
|
|
9
|
+
value: [number | undefined, number | undefined]
|
|
10
|
+
placeholder?: [string, string]
|
|
11
|
+
min?: number
|
|
12
|
+
max?: number
|
|
13
|
+
}>(),
|
|
14
|
+
{
|
|
15
|
+
min: Number.NEGATIVE_INFINITY,
|
|
16
|
+
max: Number.POSITIVE_INFINITY,
|
|
17
|
+
},
|
|
18
|
+
);
|
|
19
|
+
const emits = defineEmits<{
|
|
20
|
+
(e: 'update:value', value: typeof props.value): void
|
|
21
|
+
}>();
|
|
22
|
+
|
|
23
|
+
const formItemContext = Form.useInjectFormItemContext();
|
|
24
|
+
const minValue = computed({
|
|
25
|
+
get() {
|
|
26
|
+
return props.value[0];
|
|
27
|
+
},
|
|
28
|
+
set(value) {
|
|
29
|
+
updateValue(value, maxValue.value);
|
|
30
|
+
},
|
|
31
|
+
});
|
|
32
|
+
const maxValue = computed({
|
|
33
|
+
get() {
|
|
34
|
+
return props.value[1];
|
|
35
|
+
},
|
|
36
|
+
set(value) {
|
|
37
|
+
updateValue(minValue.value, value);
|
|
38
|
+
},
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
function updateValue(...args: typeof props.value) {
|
|
42
|
+
emits('update:value', args.sort());
|
|
43
|
+
formItemContext.onFieldChange();
|
|
44
|
+
}
|
|
45
|
+
</script>
|
|
46
|
+
|
|
47
|
+
<template>
|
|
48
|
+
<div class="flex items-center">
|
|
49
|
+
<AInputNumber
|
|
50
|
+
v-model:value="minValue" class="w-full" :min="props.min"
|
|
51
|
+
:max="props.max" :placeholder="props.placeholder?.[0]"
|
|
52
|
+
/>
|
|
53
|
+
<span> - </span>
|
|
54
|
+
<AInputNumber
|
|
55
|
+
v-model:value="maxValue" class="w-full" :min="props.min"
|
|
56
|
+
:max="props.max" :placeholder="props.placeholder?.[1]"
|
|
57
|
+
/>
|
|
58
|
+
</div>
|
|
59
|
+
</template>
|
|
@@ -1,36 +1,36 @@
|
|
|
1
|
-
import type { App } from 'vue';
|
|
2
|
-
|
|
3
|
-
export function formLabelAlign(app: App) {
|
|
4
|
-
const directiveName = 'antd-form-label-align';
|
|
5
|
-
const resizeObserverKey = `${directiveName}@resizeObserver`;
|
|
6
|
-
|
|
7
|
-
function init(el: HTMLElement) {
|
|
8
|
-
const labels = el.querySelectorAll('.ant-form-item .ant-form-item-label');
|
|
9
|
-
const resizeObserver = new ResizeObserver((entries) => {
|
|
10
|
-
const widths = entries.map(e => e.borderBoxSize?.[0]?.inlineSize ?? 0);
|
|
11
|
-
const maxWidth = Math.max(...widths);
|
|
12
|
-
|
|
13
|
-
if (maxWidth <= 0)
|
|
14
|
-
return;
|
|
15
|
-
|
|
16
|
-
el.style.setProperty('--max-label-width', `${maxWidth}px`);
|
|
17
|
-
entries.forEach((e) => {
|
|
18
|
-
const target = e.target as HTMLElement;
|
|
19
|
-
target.style.setProperty('width', 'var(--max-label-width)');
|
|
20
|
-
});
|
|
21
|
-
});
|
|
22
|
-
|
|
23
|
-
Array.from(labels).forEach(label => resizeObserver.observe(label));
|
|
24
|
-
|
|
25
|
-
return resizeObserver;
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
app.directive(directiveName, {
|
|
29
|
-
mounted(el: HTMLElement) {
|
|
30
|
-
(el as any)[resizeObserverKey] = init(el);
|
|
31
|
-
},
|
|
32
|
-
updated(el) {
|
|
33
|
-
(el as any)[resizeObserverKey] = init(el);
|
|
34
|
-
},
|
|
35
|
-
});
|
|
36
|
-
}
|
|
1
|
+
import type { App } from 'vue';
|
|
2
|
+
|
|
3
|
+
export function formLabelAlign(app: App) {
|
|
4
|
+
const directiveName = 'antd-form-label-align';
|
|
5
|
+
const resizeObserverKey = `${directiveName}@resizeObserver`;
|
|
6
|
+
|
|
7
|
+
function init(el: HTMLElement) {
|
|
8
|
+
const labels = el.querySelectorAll('.ant-form-item .ant-form-item-label');
|
|
9
|
+
const resizeObserver = new ResizeObserver((entries) => {
|
|
10
|
+
const widths = entries.map(e => e.borderBoxSize?.[0]?.inlineSize ?? 0);
|
|
11
|
+
const maxWidth = Math.max(...widths);
|
|
12
|
+
|
|
13
|
+
if (maxWidth <= 0)
|
|
14
|
+
return;
|
|
15
|
+
|
|
16
|
+
el.style.setProperty('--max-label-width', `${maxWidth}px`);
|
|
17
|
+
entries.forEach((e) => {
|
|
18
|
+
const target = e.target as HTMLElement;
|
|
19
|
+
target.style.setProperty('width', 'var(--max-label-width)');
|
|
20
|
+
});
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
Array.from(labels).forEach(label => resizeObserver.observe(label));
|
|
24
|
+
|
|
25
|
+
return resizeObserver;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
app.directive(directiveName, {
|
|
29
|
+
mounted(el: HTMLElement) {
|
|
30
|
+
(el as any)[resizeObserverKey] = init(el);
|
|
31
|
+
},
|
|
32
|
+
updated(el) {
|
|
33
|
+
(el as any)[resizeObserverKey] = init(el);
|
|
34
|
+
},
|
|
35
|
+
});
|
|
36
|
+
}
|
|
@@ -1,73 +1,73 @@
|
|
|
1
|
-
import { Button as AButton, Drawer as ADrawer, Space as ASpace } from 'ant-design-vue';
|
|
2
|
-
import { defineComponent, h, isProxy, reactive, toRef, toRefs } 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, rootClassName: 'antd-cover__basic-drawer' };
|
|
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 DrawerFooter = 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.footer = _drawerProps.footer === undefined ? h(DrawerFooter) : _drawerProps.footer;
|
|
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, h, isProxy, reactive, toRef, toRefs } 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, rootClassName: 'antd-cover__basic-drawer' };
|
|
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 DrawerFooter = 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.footer = _drawerProps.footer === undefined ? h(DrawerFooter) : _drawerProps.footer;
|
|
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,127 +1,127 @@
|
|
|
1
|
-
import { computed, reactive, ref } from 'vue';
|
|
2
|
-
import { pick } from 'lodash-es';
|
|
3
|
-
import type { UseQueryReturnType } from '@tanstack/vue-query';
|
|
4
|
-
import type { Table, TableProps } from 'ant-design-vue';
|
|
5
|
-
import type { ColumnType, FilterValue } from 'ant-design-vue/es/table/interface';
|
|
6
|
-
import type { ComponentProps } from 'vue-component-type-helpers';
|
|
7
|
-
|
|
8
|
-
interface ISorter {
|
|
9
|
-
field?: string
|
|
10
|
-
order?: string
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
const defaultPageSizeOptions = ['10', '20', '50', '100'];
|
|
14
|
-
|
|
15
|
-
export function useAntdTable<
|
|
16
|
-
UQRR extends UseQueryReturnType<any, any>,
|
|
17
|
-
QP extends Partial<{ page?: string | number, page_size?: string | number }>,
|
|
18
|
-
>(uqrt: UQRR, queryParams: QP = ({} as any)) {
|
|
19
|
-
type RecordType = GetRecordType<UQRR>;
|
|
20
|
-
type LocalTableProps = TableProps<RecordType>;
|
|
21
|
-
type LocalColumnsType = NonNullable<LocalTableProps['columns']>;
|
|
22
|
-
type LocalTableRowSelection = NonNullable<LocalTableProps['rowSelection']>;
|
|
23
|
-
|
|
24
|
-
const { data, isFetching, isLoading } = uqrt;
|
|
25
|
-
const filters = ref<Record<string, FilterValue>>();
|
|
26
|
-
const sorter = ref<ISorter>();
|
|
27
|
-
const sorters = ref<ISorter[]>();
|
|
28
|
-
|
|
29
|
-
/* pageSizeOptions 初始化 */
|
|
30
|
-
const pageSizeOptions = [...defaultPageSizeOptions];
|
|
31
|
-
const initPageSize = String(queryParams?.page_size ?? '10');
|
|
32
|
-
|
|
33
|
-
if (!pageSizeOptions.includes(initPageSize)) {
|
|
34
|
-
pageSizeOptions.push(initPageSize);
|
|
35
|
-
pageSizeOptions.sort((p, n) => Number(p) - Number(n));
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
const onChange: ComponentProps<typeof Table>['onChange'] = (_pagination, _filters, _sorter, extra) => {
|
|
39
|
-
if (extra.action === 'paginate') {
|
|
40
|
-
const page = queryParams.page_size !== _pagination.pageSize ? 1 : _pagination.current;
|
|
41
|
-
Object.assign(queryParams, { page, page_size: _pagination.pageSize ?? 10 });
|
|
42
|
-
}
|
|
43
|
-
else if (extra.action === 'filter') {
|
|
44
|
-
filters.value = _filters;
|
|
45
|
-
}
|
|
46
|
-
else if (extra.action === 'sort') {
|
|
47
|
-
if (Array.isArray(_sorter)) {
|
|
48
|
-
sorter.value = pick(_sorter[0], ['field', 'order']) as any;
|
|
49
|
-
sorters.value = _sorter.map(item => pick(item, ['field', 'order'])) as any;
|
|
50
|
-
}
|
|
51
|
-
else {
|
|
52
|
-
sorter.value = pick(_sorter, ['field', 'order']) as any;
|
|
53
|
-
sorters.value = [{ ...sorter.value }];
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
};
|
|
57
|
-
const defineColumns = (columnsGetter: () => LocalColumnsType) => computed(columnsGetter);
|
|
58
|
-
const defineRowSelection = (rowSelectionGetter: () => LocalTableRowSelection) => {
|
|
59
|
-
const rowSelection = reactive(rowSelectionGetter());
|
|
60
|
-
|
|
61
|
-
rowSelection.selectedRowKeys ??= [];
|
|
62
|
-
rowSelection.onChange ??= keys => rowSelection.selectedRowKeys = keys;
|
|
63
|
-
|
|
64
|
-
return rowSelection;
|
|
65
|
-
};
|
|
66
|
-
|
|
67
|
-
const tableProps = computed<LocalTableProps>(() => {
|
|
68
|
-
const { list, pagination } = data.value ?? {};
|
|
69
|
-
|
|
70
|
-
return {
|
|
71
|
-
dataSource: list,
|
|
72
|
-
pagination: {
|
|
73
|
-
disabled: isFetching.value,
|
|
74
|
-
current: Number(queryParams.page ?? 1),
|
|
75
|
-
pageSize: Number(queryParams.page_size ?? 10),
|
|
76
|
-
total: pagination?.total ?? 0,
|
|
77
|
-
showSizeChanger: true,
|
|
78
|
-
showQuickJumper: true,
|
|
79
|
-
pageSizeOptions,
|
|
80
|
-
showTotal: total => `共 ${total} 条`,
|
|
81
|
-
},
|
|
82
|
-
loading: isLoading.value,
|
|
83
|
-
scroll: { x: 'max-content' },
|
|
84
|
-
sticky: true,
|
|
85
|
-
onChange: onChange as any,
|
|
86
|
-
};
|
|
87
|
-
});
|
|
88
|
-
const dataIndexs = new Proxy({} as Record<keyof RecordType, string>, {
|
|
89
|
-
get(_, p) {
|
|
90
|
-
return p;
|
|
91
|
-
},
|
|
92
|
-
});
|
|
93
|
-
const bodyCellType = {} as {
|
|
94
|
-
index: number
|
|
95
|
-
text: any
|
|
96
|
-
value: any
|
|
97
|
-
record: RecordType
|
|
98
|
-
column: ColumnType<RecordType>
|
|
99
|
-
};
|
|
100
|
-
|
|
101
|
-
return {
|
|
102
|
-
/** ATable 的预设 Props */
|
|
103
|
-
tableProps,
|
|
104
|
-
/* 过滤的字段 */
|
|
105
|
-
filters,
|
|
106
|
-
/* 排序的字段 */
|
|
107
|
-
sorter,
|
|
108
|
-
/* 多维排序的字段 */
|
|
109
|
-
sorters,
|
|
110
|
-
/** 【类型辅助】基于接口数据类型推导出的 dataIndex,供 columns 的 dataIndex 使用 */
|
|
111
|
-
dataIndexs,
|
|
112
|
-
/** 【类型辅助】bodyCell 插槽数据的精确类型描述 */
|
|
113
|
-
bodyCellType,
|
|
114
|
-
/** 【类型辅助】用于定义出类型精确的 columns */
|
|
115
|
-
defineColumns,
|
|
116
|
-
/** 【类型辅助】用于定义出类型精确的 rowSelection */
|
|
117
|
-
defineRowSelection,
|
|
118
|
-
/** 内置的 ATable onChange 事件,默认在 `tableProps` 中 */
|
|
119
|
-
onChange,
|
|
120
|
-
};
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
type GetRecordType<T> = T extends UseQueryReturnType<infer D, any>
|
|
124
|
-
? D extends Api.PageData
|
|
125
|
-
? NonNullable<D['list']>[0]
|
|
126
|
-
: never
|
|
127
|
-
: never;
|
|
1
|
+
import { computed, reactive, ref } from 'vue';
|
|
2
|
+
import { pick } from 'lodash-es';
|
|
3
|
+
import type { UseQueryReturnType } from '@tanstack/vue-query';
|
|
4
|
+
import type { Table, TableProps } from 'ant-design-vue';
|
|
5
|
+
import type { ColumnType, FilterValue } from 'ant-design-vue/es/table/interface';
|
|
6
|
+
import type { ComponentProps } from 'vue-component-type-helpers';
|
|
7
|
+
|
|
8
|
+
interface ISorter {
|
|
9
|
+
field?: string
|
|
10
|
+
order?: string
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
const defaultPageSizeOptions = ['10', '20', '50', '100'];
|
|
14
|
+
|
|
15
|
+
export function useAntdTable<
|
|
16
|
+
UQRR extends UseQueryReturnType<any, any>,
|
|
17
|
+
QP extends Partial<{ page?: string | number, page_size?: string | number }>,
|
|
18
|
+
>(uqrt: UQRR, queryParams: QP = ({} as any)) {
|
|
19
|
+
type RecordType = GetRecordType<UQRR>;
|
|
20
|
+
type LocalTableProps = TableProps<RecordType>;
|
|
21
|
+
type LocalColumnsType = NonNullable<LocalTableProps['columns']>;
|
|
22
|
+
type LocalTableRowSelection = NonNullable<LocalTableProps['rowSelection']>;
|
|
23
|
+
|
|
24
|
+
const { data, isFetching, isLoading } = uqrt;
|
|
25
|
+
const filters = ref<Record<string, FilterValue>>();
|
|
26
|
+
const sorter = ref<ISorter>();
|
|
27
|
+
const sorters = ref<ISorter[]>();
|
|
28
|
+
|
|
29
|
+
/* pageSizeOptions 初始化 */
|
|
30
|
+
const pageSizeOptions = [...defaultPageSizeOptions];
|
|
31
|
+
const initPageSize = String(queryParams?.page_size ?? '10');
|
|
32
|
+
|
|
33
|
+
if (!pageSizeOptions.includes(initPageSize)) {
|
|
34
|
+
pageSizeOptions.push(initPageSize);
|
|
35
|
+
pageSizeOptions.sort((p, n) => Number(p) - Number(n));
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
const onChange: ComponentProps<typeof Table>['onChange'] = (_pagination, _filters, _sorter, extra) => {
|
|
39
|
+
if (extra.action === 'paginate') {
|
|
40
|
+
const page = queryParams.page_size !== _pagination.pageSize ? 1 : _pagination.current;
|
|
41
|
+
Object.assign(queryParams, { page, page_size: _pagination.pageSize ?? 10 });
|
|
42
|
+
}
|
|
43
|
+
else if (extra.action === 'filter') {
|
|
44
|
+
filters.value = _filters;
|
|
45
|
+
}
|
|
46
|
+
else if (extra.action === 'sort') {
|
|
47
|
+
if (Array.isArray(_sorter)) {
|
|
48
|
+
sorter.value = pick(_sorter[0], ['field', 'order']) as any;
|
|
49
|
+
sorters.value = _sorter.map(item => pick(item, ['field', 'order'])) as any;
|
|
50
|
+
}
|
|
51
|
+
else {
|
|
52
|
+
sorter.value = pick(_sorter, ['field', 'order']) as any;
|
|
53
|
+
sorters.value = [{ ...sorter.value }];
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
};
|
|
57
|
+
const defineColumns = (columnsGetter: () => LocalColumnsType) => computed(columnsGetter);
|
|
58
|
+
const defineRowSelection = (rowSelectionGetter: () => LocalTableRowSelection) => {
|
|
59
|
+
const rowSelection = reactive(rowSelectionGetter());
|
|
60
|
+
|
|
61
|
+
rowSelection.selectedRowKeys ??= [];
|
|
62
|
+
rowSelection.onChange ??= keys => rowSelection.selectedRowKeys = keys;
|
|
63
|
+
|
|
64
|
+
return rowSelection;
|
|
65
|
+
};
|
|
66
|
+
|
|
67
|
+
const tableProps = computed<LocalTableProps>(() => {
|
|
68
|
+
const { list, pagination } = data.value ?? {};
|
|
69
|
+
|
|
70
|
+
return {
|
|
71
|
+
dataSource: list,
|
|
72
|
+
pagination: {
|
|
73
|
+
disabled: isFetching.value,
|
|
74
|
+
current: Number(queryParams.page ?? 1),
|
|
75
|
+
pageSize: Number(queryParams.page_size ?? 10),
|
|
76
|
+
total: pagination?.total ?? 0,
|
|
77
|
+
showSizeChanger: true,
|
|
78
|
+
showQuickJumper: true,
|
|
79
|
+
pageSizeOptions,
|
|
80
|
+
showTotal: total => `共 ${total} 条`,
|
|
81
|
+
},
|
|
82
|
+
loading: isLoading.value,
|
|
83
|
+
scroll: { x: 'max-content' },
|
|
84
|
+
sticky: true,
|
|
85
|
+
onChange: onChange as any,
|
|
86
|
+
};
|
|
87
|
+
});
|
|
88
|
+
const dataIndexs = new Proxy({} as Record<keyof RecordType, string>, {
|
|
89
|
+
get(_, p) {
|
|
90
|
+
return p;
|
|
91
|
+
},
|
|
92
|
+
});
|
|
93
|
+
const bodyCellType = {} as {
|
|
94
|
+
index: number
|
|
95
|
+
text: any
|
|
96
|
+
value: any
|
|
97
|
+
record: RecordType
|
|
98
|
+
column: ColumnType<RecordType>
|
|
99
|
+
};
|
|
100
|
+
|
|
101
|
+
return {
|
|
102
|
+
/** ATable 的预设 Props */
|
|
103
|
+
tableProps,
|
|
104
|
+
/* 过滤的字段 */
|
|
105
|
+
filters,
|
|
106
|
+
/* 排序的字段 */
|
|
107
|
+
sorter,
|
|
108
|
+
/* 多维排序的字段 */
|
|
109
|
+
sorters,
|
|
110
|
+
/** 【类型辅助】基于接口数据类型推导出的 dataIndex,供 columns 的 dataIndex 使用 */
|
|
111
|
+
dataIndexs,
|
|
112
|
+
/** 【类型辅助】bodyCell 插槽数据的精确类型描述 */
|
|
113
|
+
bodyCellType,
|
|
114
|
+
/** 【类型辅助】用于定义出类型精确的 columns */
|
|
115
|
+
defineColumns,
|
|
116
|
+
/** 【类型辅助】用于定义出类型精确的 rowSelection */
|
|
117
|
+
defineRowSelection,
|
|
118
|
+
/** 内置的 ATable onChange 事件,默认在 `tableProps` 中 */
|
|
119
|
+
onChange,
|
|
120
|
+
};
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
type GetRecordType<T> = T extends UseQueryReturnType<infer D, any>
|
|
124
|
+
? D extends Api.PageData
|
|
125
|
+
? NonNullable<D['list']>[0]
|
|
126
|
+
: never
|
|
127
|
+
: never;
|
package/libs/dayjs.ts
CHANGED
|
@@ -1,5 +1,12 @@
|
|
|
1
1
|
import dayjs from 'dayjs';
|
|
2
2
|
|
|
3
|
+
import relativeTime from 'dayjs/plugin/relativeTime';
|
|
4
|
+
import 'dayjs/locale/zh';
|
|
5
|
+
import 'dayjs/locale/en';
|
|
6
|
+
|
|
3
7
|
export { isDayjs, unix, locale, extend } from 'dayjs';
|
|
4
8
|
export type { Dayjs, PluginFunc, UnitType, UnitTypeLong, UnitTypeLongPlural, UnitTypeShort, QUnitType, ConfigType, ConfigTypeMap, OpUnitType, OptionType, ManipulateType } from 'dayjs';
|
|
5
9
|
export default dayjs;
|
|
10
|
+
|
|
11
|
+
dayjs.locale('zh');
|
|
12
|
+
dayjs.extend(relativeTime);
|