@peng_kai/kit 0.0.15 → 0.0.16
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/.vscode/settings.json +41 -0
- package/admin/components/filter/index.ts +5 -0
- package/admin/{filter → components/filter/src}/FilterDrawer.vue +12 -9
- package/admin/{filter → components/filter/src}/FilterParam.vue +15 -15
- package/admin/{filter → components/filter/src}/FilterReset.vue +7 -4
- package/admin/{filter → components/filter/src}/useFilterParams.ts +9 -9
- package/admin/{filter → components/filter/src}/useFilterQuery.ts +11 -11
- package/admin/components/scroll-nav/index.ts +1 -1
- package/admin/components/scroll-nav/src/ScrollNav.vue +9 -9
- package/admin/components/text/index.ts +6 -6
- package/admin/components/text/src/Amount.vue +22 -19
- package/admin/components/text/src/Datetime.vue +12 -12
- package/admin/components/text/src/Duration.vue +13 -13
- package/admin/components/text/src/Hash.vue +13 -11
- package/admin/components/text/src/createTagGetter.ts +7 -7
- package/admin/defines/index.ts +4 -5
- package/admin/defines/page/definePage.ts +12 -0
- package/admin/defines/page/index.ts +1 -0
- package/admin/defines/route/defineRoute.ts +14 -0
- package/admin/defines/route/getRoutes.ts +84 -0
- package/admin/defines/route/helpers.ts +49 -0
- package/admin/defines/route/index.ts +73 -0
- package/admin/defines/route-guard/defineRouteGuard.ts +18 -0
- package/admin/defines/route-guard/getRouteGuards.ts +40 -0
- package/admin/defines/route-guard/index.ts +2 -0
- package/admin/defines/startup/defineStartup.ts +11 -0
- package/admin/defines/startup/getStartups.ts +30 -0
- package/admin/defines/startup/index.ts +2 -0
- package/admin/hooks/index.ts +5 -6
- package/admin/hooks/useMenu.ts +48 -48
- package/admin/hooks/usePage.ts +67 -65
- package/admin/hooks/usePageTab.ts +17 -17
- package/admin/layout/large/Breadcrumb.vue +15 -16
- package/admin/layout/large/Content.vue +4 -4
- package/admin/layout/large/Menu.vue +20 -19
- package/admin/layout/large/PageTab.vue +4 -4
- package/admin/layout/large/index.ts +4 -4
- package/admin/permission/index.ts +4 -0
- package/admin/permission/routerGuard.ts +43 -0
- package/admin/permission/usePermission.ts +52 -0
- package/admin/permission/vuePlugin.ts +30 -0
- package/admin/route-guards/index.ts +2 -0
- package/admin/route-guards/pageProgress.ts +16 -0
- package/admin/route-guards/pageTitle.ts +24 -0
- package/admin/types/assist.ts +10 -0
- package/admin/unocss/index.ts +1 -1
- package/antd/components/InputNumberRange.vue +21 -15
- package/antd/directives/formLabelAlign.ts +28 -23
- package/antd/hooks/createAntdModal.ts +29 -29
- package/antd/hooks/useAntdDrawer.ts +31 -31
- package/antd/hooks/useAntdForm.helpers.ts +18 -18
- package/antd/hooks/useAntdForm.ts +38 -37
- package/antd/hooks/useAntdModal.ts +25 -25
- package/antd/hooks/useAntdTable.ts +22 -22
- package/antd/hooks/useAntdTheme.ts +86 -0
- package/antd/index.ts +8 -7
- package/eslint.config.js +50 -0
- package/kitDependencies.ts +21 -7
- package/package.json +22 -16
- package/pnpm-lock.yaml +2147 -56
- package/request/helpers.ts +30 -13
- package/request/index.ts +2 -2
- package/request/interceptors/checkCode.ts +8 -8
- package/request/interceptors/filterEmptyValue.ts +9 -9
- package/request/interceptors/formatPaging.ts +12 -12
- package/request/interceptors/index.ts +7 -6
- package/request/interceptors/popupMessage.ts +35 -35
- package/request/interceptors/returnResultType.ts +19 -19
- package/request/interceptors/toLogin.ts +13 -0
- package/request/interceptors/unitizeAxiosError.ts +7 -7
- package/request/queryClient.ts +42 -0
- package/request/request.ts +21 -21
- package/request/type.d.ts +18 -18
- package/tsconfig.json +41 -12
- package/utils/index.ts +59 -31
- package/vue/components/index.ts +1 -0
- package/{components → vue/components}/infinite-query/index.ts +1 -1
- package/{components → vue/components}/infinite-query/src/InfiniteQuery.vue +29 -29
- package/{components → vue/components}/infinite-query/src/useCreateTrigger.ts +13 -13
- package/vue/hooks/useComponentRef.ts +12 -12
- package/vue/hooks/useIsMounted.ts +4 -4
- package/vue/hooks/useTeleportTarget.ts +7 -7
- package/vue/index.ts +4 -3
- package/admin/defines/definePage.ts +0 -14
- package/admin/defines/defineRoute.helpers.ts +0 -37
- package/admin/defines/defineRoute.ts +0 -161
- package/admin/defines/defineRouteGuard.ts +0 -56
- package/admin/defines/defineStartup.ts +0 -41
- package/admin/filter/index.ts +0 -5
- package/admin/hooks/usePermission.ts +0 -5
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
<script setup lang="ts">
|
|
2
|
-
import { computed } from
|
|
3
|
-
import {
|
|
2
|
+
import { computed } from 'vue';
|
|
3
|
+
import { InputNumber as AInputNumber, Form } from 'ant-design-vue';
|
|
4
4
|
|
|
5
5
|
const props = withDefaults(
|
|
6
6
|
defineProps<{
|
|
@@ -12,36 +12,42 @@ const props = withDefaults(
|
|
|
12
12
|
min: Number.NEGATIVE_INFINITY,
|
|
13
13
|
max: Number.POSITIVE_INFINITY,
|
|
14
14
|
},
|
|
15
|
-
)
|
|
15
|
+
);
|
|
16
16
|
const emits = defineEmits<{
|
|
17
17
|
(e: 'update:value', value: [number, number]): void
|
|
18
|
-
}>()
|
|
18
|
+
}>();
|
|
19
19
|
|
|
20
|
-
const formItemContext = Form.useInjectFormItemContext()
|
|
20
|
+
const formItemContext = Form.useInjectFormItemContext();
|
|
21
21
|
const minValue = computed({
|
|
22
22
|
get() {
|
|
23
|
-
return props.value[0]
|
|
23
|
+
return props.value[0];
|
|
24
24
|
},
|
|
25
25
|
set(value) {
|
|
26
|
-
emits('update:value', [value, props.value[1]])
|
|
27
|
-
formItemContext.onFieldChange()
|
|
26
|
+
emits('update:value', [value, props.value[1]]);
|
|
27
|
+
formItemContext.onFieldChange();
|
|
28
28
|
},
|
|
29
|
-
})
|
|
29
|
+
});
|
|
30
30
|
const maxValue = computed({
|
|
31
31
|
get() {
|
|
32
|
-
return props.value[1]
|
|
32
|
+
return props.value[1];
|
|
33
33
|
},
|
|
34
34
|
set(value) {
|
|
35
|
-
emits('update:value', [props.value[0], value])
|
|
36
|
-
formItemContext.onFieldChange()
|
|
35
|
+
emits('update:value', [props.value[0], value]);
|
|
36
|
+
formItemContext.onFieldChange();
|
|
37
37
|
},
|
|
38
|
-
})
|
|
38
|
+
});
|
|
39
39
|
</script>
|
|
40
40
|
|
|
41
41
|
<template>
|
|
42
42
|
<div class="flex items-center">
|
|
43
|
-
<AInputNumber
|
|
43
|
+
<AInputNumber
|
|
44
|
+
v-model:value="minValue" class="w-full" :min="props.min"
|
|
45
|
+
:max="props.max"
|
|
46
|
+
/>
|
|
44
47
|
<span> ~ </span>
|
|
45
|
-
<AInputNumber
|
|
48
|
+
<AInputNumber
|
|
49
|
+
v-model:value="maxValue" class="w-full" :min="props.min"
|
|
50
|
+
:max="props.max"
|
|
51
|
+
/>
|
|
46
52
|
</div>
|
|
47
53
|
</template>
|
|
@@ -1,31 +1,36 @@
|
|
|
1
|
-
import type { App } from 'vue'
|
|
1
|
+
import type { App } from 'vue';
|
|
2
2
|
|
|
3
3
|
export function formLabelAlign(app: App) {
|
|
4
|
-
const directiveName = 'antd-form-label-align'
|
|
5
|
-
const resizeObserverKey = `${directiveName}@resizeObserver
|
|
4
|
+
const directiveName = 'antd-form-label-align';
|
|
5
|
+
const resizeObserverKey = `${directiveName}@resizeObserver`;
|
|
6
6
|
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
const
|
|
11
|
-
|
|
12
|
-
|
|
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;
|
|
13
15
|
|
|
14
|
-
|
|
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
|
+
});
|
|
16
22
|
|
|
17
|
-
|
|
18
|
-
entries.forEach((e) => {
|
|
19
|
-
const target = e.target as HTMLElement
|
|
20
|
-
target.style.setProperty('width', 'var(--max-label-width)')
|
|
21
|
-
})
|
|
22
|
-
})
|
|
23
|
+
Array.from(labels).forEach(label => resizeObserver.observe(label));
|
|
23
24
|
|
|
24
|
-
|
|
25
|
-
|
|
25
|
+
return resizeObserver;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
app.directive(directiveName, {
|
|
29
|
+
mounted(el: HTMLElement) {
|
|
30
|
+
(el as any)[resizeObserverKey] = init(el);
|
|
26
31
|
},
|
|
27
|
-
|
|
28
|
-
el[resizeObserverKey]
|
|
32
|
+
updated(el) {
|
|
33
|
+
(el as any)[resizeObserverKey] = init(el);
|
|
29
34
|
},
|
|
30
|
-
})
|
|
31
|
-
}
|
|
35
|
+
});
|
|
36
|
+
}
|
|
@@ -1,61 +1,61 @@
|
|
|
1
|
-
import { createVNode, defineComponent, reactive, render as vueRender } from 'vue'
|
|
2
|
-
import { Modal as AntModal } from 'ant-design-vue'
|
|
3
|
-
import { tryOnUnmounted } from '@vueuse/core'
|
|
4
|
-
import type {
|
|
5
|
-
import type { ModalProps } from 'ant-design-vue'
|
|
6
|
-
import type { ComponentProps } from 'vue-component-type-helpers'
|
|
7
|
-
import type { Writable } from 'type-fest'
|
|
1
|
+
import { createVNode, defineComponent, reactive, render as vueRender } from 'vue';
|
|
2
|
+
import { Modal as AntModal } from 'ant-design-vue';
|
|
3
|
+
import { tryOnUnmounted } from '@vueuse/core';
|
|
4
|
+
import type { Component, VNode } from 'vue';
|
|
5
|
+
import type { ModalProps } from 'ant-design-vue';
|
|
6
|
+
import type { ComponentProps } from 'vue-component-type-helpers';
|
|
7
|
+
import type { Writable } from 'type-fest';
|
|
8
8
|
|
|
9
9
|
export function createAntdModal<Comp extends Component>(comp: Comp, defaultModalProps: ModalProps = {}) {
|
|
10
|
-
type TCompProps = Writable<ComponentProps<Comp
|
|
10
|
+
type TCompProps = Writable<ComponentProps<Comp>>;
|
|
11
11
|
|
|
12
|
-
let holderUsed = false // 是否是使用 ContextHolder 的方式挂载弹窗
|
|
13
|
-
let container: DocumentFragment
|
|
14
|
-
let instance: VNode
|
|
15
|
-
const compProps = reactive({} as TCompProps)
|
|
12
|
+
let holderUsed = false; // 是否是使用 ContextHolder 的方式挂载弹窗
|
|
13
|
+
let container: DocumentFragment;
|
|
14
|
+
let instance: VNode;
|
|
15
|
+
const compProps = reactive({} as TCompProps);
|
|
16
16
|
const modalProps = reactive<ModalProps>({
|
|
17
17
|
'open': false,
|
|
18
18
|
'destroyOnClose': true,
|
|
19
19
|
...defaultModalProps,
|
|
20
20
|
'onUpdate:open': (value) => {
|
|
21
|
-
modalProps.open = value
|
|
21
|
+
modalProps.open = value;
|
|
22
22
|
},
|
|
23
23
|
'afterClose': () => {
|
|
24
24
|
container && vueRender(null, container as any);
|
|
25
25
|
(instance as any) = null;
|
|
26
|
-
(container as any) = null
|
|
26
|
+
(container as any) = null;
|
|
27
27
|
},
|
|
28
|
-
})
|
|
28
|
+
});
|
|
29
29
|
const ContextHolder = defineComponent({
|
|
30
30
|
setup() {
|
|
31
31
|
if (!instance)
|
|
32
|
-
holderUsed = true
|
|
32
|
+
holderUsed = true;
|
|
33
33
|
},
|
|
34
34
|
render() {
|
|
35
|
-
return createVNode(AntModal, modalProps, { modalRender: () => createVNode(comp, compProps) })
|
|
35
|
+
return createVNode(AntModal, modalProps, { modalRender: () => createVNode(comp, compProps) });
|
|
36
36
|
},
|
|
37
|
-
})
|
|
37
|
+
});
|
|
38
38
|
|
|
39
39
|
const open = (newCompProps: TCompProps) => {
|
|
40
|
-
Object.keys(compProps).forEach(k => delete compProps[k])
|
|
40
|
+
Object.keys(compProps).forEach(k => delete compProps[k]);
|
|
41
41
|
Object.assign(compProps, {
|
|
42
42
|
...newCompProps,
|
|
43
43
|
onClose: close,
|
|
44
|
-
})
|
|
44
|
+
});
|
|
45
45
|
|
|
46
46
|
if (!holderUsed) {
|
|
47
|
-
container = document.createDocumentFragment()
|
|
48
|
-
instance = createVNode(ContextHolder)
|
|
49
|
-
vueRender(instance, container as any)
|
|
47
|
+
container = document.createDocumentFragment();
|
|
48
|
+
instance = createVNode(ContextHolder);
|
|
49
|
+
vueRender(instance, container as any);
|
|
50
50
|
}
|
|
51
51
|
|
|
52
|
-
modalProps.open = true
|
|
53
|
-
}
|
|
52
|
+
modalProps.open = true;
|
|
53
|
+
};
|
|
54
54
|
const close = () => {
|
|
55
|
-
modalProps.open = false
|
|
56
|
-
}
|
|
55
|
+
modalProps.open = false;
|
|
56
|
+
};
|
|
57
57
|
|
|
58
|
-
tryOnUnmounted(close)
|
|
58
|
+
tryOnUnmounted(close);
|
|
59
59
|
|
|
60
|
-
return { open, close, ContextHolder }
|
|
60
|
+
return { open, close, ContextHolder };
|
|
61
61
|
}
|
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
import { Button as AButton, Drawer as ADrawer, Space as ASpace } from 'ant-design-vue'
|
|
2
|
-
import { defineComponent, isProxy, reactive,
|
|
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'
|
|
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
8
|
|
|
9
|
-
const defaultDrawerProps: DrawerProps = { open: false, destroyOnClose: true }
|
|
9
|
+
const defaultDrawerProps: DrawerProps = { open: false, destroyOnClose: true };
|
|
10
10
|
|
|
11
11
|
interface IComponentConfig<Comp extends Component> {
|
|
12
12
|
is: Comp
|
|
@@ -17,57 +17,57 @@ export function useAntdDrawer<Comp extends Component>(
|
|
|
17
17
|
comp: IComponentConfig<Comp> | Comp,
|
|
18
18
|
drawerProps = defaultDrawerProps,
|
|
19
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)
|
|
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
23
|
const _drawerProps: DrawerProps = reactive({
|
|
24
24
|
...defaultDrawerProps,
|
|
25
25
|
...isProxy(drawerProps) ? toRefs(drawerProps) : drawerProps,
|
|
26
|
-
})
|
|
26
|
+
});
|
|
27
27
|
|
|
28
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
|
-
}
|
|
29
|
+
Object.assign(_drawerProps, newAntdModalProps);
|
|
30
|
+
Object.assign(compProps, newBodyProps);
|
|
31
|
+
_drawerProps.open = true;
|
|
32
|
+
};
|
|
33
33
|
const close = () => {
|
|
34
|
-
_drawerProps.open = false
|
|
35
|
-
}
|
|
34
|
+
_drawerProps.open = false;
|
|
35
|
+
};
|
|
36
36
|
|
|
37
37
|
const DrawerExtra = defineComponent({
|
|
38
38
|
setup() {
|
|
39
|
-
const cancelBtnProps: ButtonProps = reactive({ onClick: close })
|
|
39
|
+
const cancelBtnProps: ButtonProps = reactive({ onClick: close });
|
|
40
40
|
const confirmBtnProps: ButtonProps = reactive({
|
|
41
41
|
type: 'primary',
|
|
42
42
|
loading: toRef(() => (compRef as any)?.loading),
|
|
43
43
|
onClick: () => (compRef as any)?.confirm?.(),
|
|
44
|
-
})
|
|
44
|
+
});
|
|
45
45
|
|
|
46
|
-
return { cancelBtnProps, confirmBtnProps }
|
|
46
|
+
return { cancelBtnProps, confirmBtnProps };
|
|
47
47
|
},
|
|
48
48
|
render() {
|
|
49
|
-
const { cancelBtnProps, confirmBtnProps } = this
|
|
49
|
+
const { cancelBtnProps, confirmBtnProps } = this;
|
|
50
50
|
|
|
51
51
|
return h(ASpace, {}, () => [
|
|
52
52
|
h(AButton, cancelBtnProps, () => '取消'),
|
|
53
53
|
h(AButton, confirmBtnProps, () => '确定'),
|
|
54
|
-
])
|
|
54
|
+
]);
|
|
55
55
|
},
|
|
56
|
-
})
|
|
56
|
+
});
|
|
57
57
|
const PresetComponent = defineComponent({
|
|
58
58
|
render() {
|
|
59
59
|
return h(ADrawer, _drawerProps, {
|
|
60
60
|
default: () => h(_comp.is, compProps as any),
|
|
61
|
-
})
|
|
61
|
+
});
|
|
62
62
|
},
|
|
63
|
-
})
|
|
63
|
+
});
|
|
64
64
|
|
|
65
|
-
_drawerProps.extra = _drawerProps.extra === undefined ? h(DrawerExtra) : _drawerProps.extra
|
|
65
|
+
_drawerProps.extra = _drawerProps.extra === undefined ? h(DrawerExtra) : _drawerProps.extra;
|
|
66
66
|
_drawerProps['onUpdate:open'] = (visiable) => {
|
|
67
|
-
_drawerProps.open = visiable
|
|
68
|
-
}
|
|
67
|
+
_drawerProps.open = visiable;
|
|
68
|
+
};
|
|
69
69
|
(compProps as any).ref = compRef;
|
|
70
|
-
(compProps as any).onClose = close
|
|
70
|
+
(compProps as any).onClose = close;
|
|
71
71
|
|
|
72
|
-
return { PresetComponent, drawerProps: _drawerProps, open, close }
|
|
72
|
+
return { PresetComponent, drawerProps: _drawerProps, open, close };
|
|
73
73
|
}
|
|
@@ -1,48 +1,48 @@
|
|
|
1
|
-
export { buildGroupFieldName, parseGroupFieldName, isSameGroup, isSameField, getGroupIndex, GROUP_SEP }
|
|
1
|
+
export { buildGroupFieldName, parseGroupFieldName, isSameGroup, isSameField, getGroupIndex, GROUP_SEP };
|
|
2
2
|
|
|
3
|
-
const GROUP_SEP = '__'
|
|
3
|
+
const GROUP_SEP = '__';
|
|
4
4
|
const groupFieldNameRE = new RegExp(
|
|
5
5
|
`(?<groupName>[a-zA-Z0-9]+)${GROUP_SEP}(?<index>\\d+)${GROUP_SEP}(?<fieldName>[a-zA-Z0-9]+)`,
|
|
6
|
-
)
|
|
6
|
+
);
|
|
7
7
|
|
|
8
8
|
function buildGroupFieldName(name: string, index: number, field: string) {
|
|
9
|
-
return name + GROUP_SEP + index + GROUP_SEP + field
|
|
9
|
+
return name + GROUP_SEP + index + GROUP_SEP + field;
|
|
10
10
|
}
|
|
11
11
|
|
|
12
12
|
function parseGroupFieldName(name: string) {
|
|
13
|
-
const res = name.match(groupFieldNameRE)
|
|
13
|
+
const res = name.match(groupFieldNameRE);
|
|
14
14
|
const ret = {
|
|
15
15
|
fieldName: '',
|
|
16
16
|
index: -1,
|
|
17
17
|
groupName: '',
|
|
18
|
-
}
|
|
18
|
+
};
|
|
19
19
|
|
|
20
20
|
if (res?.groups) {
|
|
21
|
-
ret.fieldName = res.groups.fieldName
|
|
22
|
-
ret.index = Number(res.groups.index)
|
|
23
|
-
ret.groupName = res.groups.groupName
|
|
21
|
+
ret.fieldName = res.groups.fieldName;
|
|
22
|
+
ret.index = Number(res.groups.index);
|
|
23
|
+
ret.groupName = res.groups.groupName;
|
|
24
24
|
}
|
|
25
25
|
|
|
26
|
-
return ret
|
|
26
|
+
return ret;
|
|
27
27
|
}
|
|
28
28
|
|
|
29
29
|
function getGroupIndex(name: string, schemas: Record<string, any>) {
|
|
30
30
|
const indexs = Object.keys(schemas).map((key) => {
|
|
31
|
-
const { groupName, index } = parseGroupFieldName(key)
|
|
32
|
-
return groupName === name ? index : -1
|
|
33
|
-
})
|
|
31
|
+
const { groupName, index } = parseGroupFieldName(key);
|
|
32
|
+
return groupName === name ? index : -1;
|
|
33
|
+
});
|
|
34
34
|
|
|
35
|
-
return Math.max.apply(undefined, indexs)
|
|
35
|
+
return Math.max.apply(undefined, indexs);
|
|
36
36
|
}
|
|
37
37
|
|
|
38
38
|
function isSameGroup(name: string, groupName: string) {
|
|
39
|
-
const { groupName: gn } = parseGroupFieldName(name)
|
|
39
|
+
const { groupName: gn } = parseGroupFieldName(name);
|
|
40
40
|
|
|
41
|
-
return gn === groupName
|
|
41
|
+
return gn === groupName;
|
|
42
42
|
}
|
|
43
43
|
|
|
44
44
|
function isSameField(name: string, fieldName: string) {
|
|
45
|
-
const { fieldName: fn } = parseGroupFieldName(name)
|
|
45
|
+
const { fieldName: fn } = parseGroupFieldName(name);
|
|
46
46
|
|
|
47
|
-
return fn === fieldName
|
|
47
|
+
return fn === fieldName;
|
|
48
48
|
}
|
|
@@ -1,81 +1,82 @@
|
|
|
1
|
-
import { reactiveComputed } from '@vueuse/core'
|
|
2
|
-
import type { FormInstance, FormItemProps,
|
|
3
|
-
import {
|
|
4
|
-
import
|
|
5
|
-
import {
|
|
1
|
+
import { reactiveComputed } from '@vueuse/core';
|
|
2
|
+
import type { FormInstance, FormItemProps, RuleObject } from 'ant-design-vue/es/form';
|
|
3
|
+
import type { FormProps } from 'ant-design-vue';
|
|
4
|
+
import { computed, ref } from 'vue';
|
|
5
|
+
import type { ComputedRef, UnwrapRef } from 'vue';
|
|
6
|
+
import { GROUP_SEP, buildGroupFieldName, getGroupIndex } from './useAntdForm.helpers';
|
|
6
7
|
|
|
7
|
-
export { useAntdForm }
|
|
8
|
-
export type { TField, RecordToSchemas }
|
|
8
|
+
export { useAntdForm };
|
|
9
|
+
export type { TField, RecordToSchemas };
|
|
9
10
|
|
|
10
11
|
function useAntdForm<
|
|
11
|
-
F extends Record<string, TField>,
|
|
12
|
-
S extends GetFormState<F>,
|
|
13
|
-
STF = S
|
|
12
|
+
F extends Record<string, TField>,
|
|
13
|
+
S extends GetFormState<F>,
|
|
14
|
+
STF = S,
|
|
14
15
|
>(
|
|
15
16
|
schemas: F,
|
|
16
17
|
_options?: {
|
|
17
18
|
transform?: (state: S) => STF
|
|
18
19
|
},
|
|
19
20
|
) {
|
|
20
|
-
const formRef = ref<FormInstance>()
|
|
21
|
+
const formRef = ref<FormInstance>();
|
|
21
22
|
const $form = {
|
|
22
23
|
get clearValidate() {
|
|
23
|
-
return formRef.value?.clearValidate
|
|
24
|
+
return formRef.value?.clearValidate;
|
|
24
25
|
},
|
|
25
26
|
get getFieldsValue() {
|
|
26
|
-
return formRef.value?.getFieldsValue
|
|
27
|
+
return formRef.value?.getFieldsValue;
|
|
27
28
|
},
|
|
28
29
|
get resetFields() {
|
|
29
|
-
return formRef.value?.resetFields
|
|
30
|
+
return formRef.value?.resetFields;
|
|
30
31
|
},
|
|
31
32
|
get scrollToField() {
|
|
32
|
-
return formRef.value?.scrollToField
|
|
33
|
+
return formRef.value?.scrollToField;
|
|
33
34
|
},
|
|
34
35
|
get validate() {
|
|
35
|
-
return formRef.value?.validate
|
|
36
|
+
return formRef.value?.validate;
|
|
36
37
|
},
|
|
37
38
|
get validateFields() {
|
|
38
|
-
return formRef.value?.validateFields
|
|
39
|
+
return formRef.value?.validateFields;
|
|
39
40
|
},
|
|
40
41
|
setField(name: string, schema: TField) {
|
|
41
|
-
(schemas as any)[name] = schema
|
|
42
|
+
(schemas as any)[name] = schema;
|
|
42
43
|
},
|
|
43
44
|
addGroup(groupName: string, groupSchemas: Record<string, TField>) {
|
|
44
|
-
const i = getGroupIndex(groupName, schemas) + 1
|
|
45
|
+
const i = getGroupIndex(groupName, schemas) + 1;
|
|
45
46
|
|
|
46
47
|
Object.keys(groupSchemas).forEach((key) => {
|
|
47
48
|
const name = buildGroupFieldName(groupName, i, key);
|
|
48
|
-
(schemas as any)[name] = groupSchemas[key]
|
|
49
|
-
})
|
|
49
|
+
(schemas as any)[name] = groupSchemas[key];
|
|
50
|
+
});
|
|
50
51
|
},
|
|
51
52
|
removeGroup(groupName: string, index?: number) {
|
|
52
|
-
const i = index ?? getGroupIndex(groupName, schemas)
|
|
53
|
+
const i = index ?? getGroupIndex(groupName, schemas);
|
|
53
54
|
|
|
54
55
|
Object.keys(schemas).forEach((key) => {
|
|
55
56
|
if (key.startsWith(groupName + GROUP_SEP + i))
|
|
56
|
-
Reflect.deleteProperty(schemas, key)
|
|
57
|
-
})
|
|
57
|
+
Reflect.deleteProperty(schemas, key);
|
|
58
|
+
});
|
|
58
59
|
},
|
|
59
|
-
}
|
|
60
|
+
};
|
|
60
61
|
const state = reactiveComputed(() => {
|
|
61
|
-
return Object.fromEntries(Object.entries(schemas).map(([k, v]) => [k, v.value])) as S
|
|
62
|
-
})
|
|
62
|
+
return Object.fromEntries(Object.entries(schemas).map(([k, v]) => [k, v.value])) as S;
|
|
63
|
+
});
|
|
63
64
|
const props = reactiveComputed<FormProps>(() => {
|
|
64
65
|
return {
|
|
65
66
|
model: state,
|
|
66
67
|
ref: (c: any) => (formRef.value = c),
|
|
67
|
-
}
|
|
68
|
-
})
|
|
68
|
+
};
|
|
69
|
+
});
|
|
69
70
|
const itemProps = reactiveComputed(() => {
|
|
70
71
|
const propsTuple = Object.entries(schemas).map(([key, value]): [string, FormItemProps] => [
|
|
71
72
|
key,
|
|
72
73
|
{ name: key, rules: value.rules },
|
|
73
|
-
])
|
|
74
|
-
const props = Object.fromEntries(propsTuple) as Record<keyof S, FormItemProps
|
|
74
|
+
]);
|
|
75
|
+
const props = Object.fromEntries(propsTuple) as Record<keyof S, FormItemProps>;
|
|
75
76
|
|
|
76
|
-
return props
|
|
77
|
-
})
|
|
78
|
-
const stateTF = _options?.transform ? computed(() => _options.transform!(state)) : computed(() => state)
|
|
77
|
+
return props;
|
|
78
|
+
});
|
|
79
|
+
const stateTF = _options?.transform ? computed(() => _options.transform!(state)) : computed(() => state);
|
|
79
80
|
|
|
80
81
|
return {
|
|
81
82
|
$form,
|
|
@@ -83,7 +84,7 @@ function useAntdForm<
|
|
|
83
84
|
stateTF: stateTF as ComputedRef<STF>,
|
|
84
85
|
props,
|
|
85
86
|
itemProps,
|
|
86
|
-
}
|
|
87
|
+
};
|
|
87
88
|
}
|
|
88
89
|
|
|
89
90
|
interface TField<V = any> {
|
|
@@ -93,8 +94,8 @@ interface TField<V = any> {
|
|
|
93
94
|
|
|
94
95
|
type RecordToSchemas<T extends Record<string, unknown>> = {
|
|
95
96
|
[K in keyof T]: TField<T[K]>
|
|
96
|
-
}
|
|
97
|
+
};
|
|
97
98
|
|
|
98
99
|
type GetFormState<C extends Record<string, TField>> = {
|
|
99
100
|
[K in keyof C]: UnwrapRef<C[K]['value']>;
|
|
100
|
-
}
|
|
101
|
+
};
|
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
import { Modal as AntModal } from 'ant-design-vue'
|
|
2
|
-
import { createVNode, defineComponent, isProxy, reactive,
|
|
3
|
-
import type { Component } from 'vue'
|
|
4
|
-
import type { ModalProps } 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'
|
|
1
|
+
import { Modal as AntModal } from 'ant-design-vue';
|
|
2
|
+
import { createVNode, defineComponent, isProxy, reactive, toRef, toRefs } from 'vue';
|
|
3
|
+
import type { Component } from 'vue';
|
|
4
|
+
import type { ModalProps } 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
8
|
|
|
9
|
-
const defaultModalProps: ModalProps = { open: false, destroyOnClose: true, wrapClassName: 'antd-cover__basic-modal' }
|
|
9
|
+
const defaultModalProps: ModalProps = { open: false, destroyOnClose: true, wrapClassName: 'antd-cover__basic-modal' };
|
|
10
10
|
|
|
11
11
|
interface IComponentConfig<Comp extends Component> {
|
|
12
12
|
is: Comp
|
|
@@ -26,40 +26,40 @@ export function useAntdModal<Comp extends Component>(
|
|
|
26
26
|
comp: IComponentConfig<Comp> | Comp,
|
|
27
27
|
modalProps = defaultModalProps,
|
|
28
28
|
) {
|
|
29
|
-
const _comp = ({ props: {}, type: 'body', ...((comp as any)?.is ? comp : { is: comp }) }) as Required<IComponentConfig<Comp
|
|
30
|
-
const compProps = reactive(_comp.props)
|
|
31
|
-
const compRef = useComponentRef(_comp.is)
|
|
29
|
+
const _comp = ({ props: {}, type: 'body', ...((comp as any)?.is ? comp : { is: comp }) }) as Required<IComponentConfig<Comp>>;
|
|
30
|
+
const compProps = reactive(_comp.props);
|
|
31
|
+
const compRef = useComponentRef(_comp.is);
|
|
32
32
|
const _modalProps: ModalProps = reactive({
|
|
33
33
|
...defaultModalProps,
|
|
34
34
|
...isProxy(modalProps) ? toRefs(modalProps) : modalProps,
|
|
35
35
|
confirmLoading: toRef(() => (compRef as any)?.loading),
|
|
36
36
|
onOk: () => (compRef as any)?.confirm?.(),
|
|
37
|
-
})
|
|
38
|
-
const modalSlotName = _comp.type === 'body' ? 'default' : 'modalRender'
|
|
37
|
+
});
|
|
38
|
+
const modalSlotName = _comp.type === 'body' ? 'default' : 'modalRender';
|
|
39
39
|
|
|
40
40
|
const open = (newCompProps?: Partial<typeof compProps>, newAntdModalProps?: Omit<Partial<ModalProps>, 'open'>) => {
|
|
41
|
-
Object.assign(_modalProps, newAntdModalProps)
|
|
42
|
-
Object.assign(compProps, newCompProps)
|
|
41
|
+
Object.assign(_modalProps, newAntdModalProps);
|
|
42
|
+
Object.assign(compProps, newCompProps);
|
|
43
43
|
|
|
44
|
-
_modalProps.open = true
|
|
45
|
-
}
|
|
44
|
+
_modalProps.open = true;
|
|
45
|
+
};
|
|
46
46
|
const close = () => {
|
|
47
|
-
_modalProps.open = false
|
|
48
|
-
}
|
|
47
|
+
_modalProps.open = false;
|
|
48
|
+
};
|
|
49
49
|
|
|
50
50
|
const PresetComponent = defineComponent({
|
|
51
51
|
render() {
|
|
52
52
|
return createVNode(AntModal, _modalProps, {
|
|
53
53
|
[modalSlotName]: () => createVNode(_comp.is, compProps as any),
|
|
54
|
-
})
|
|
54
|
+
});
|
|
55
55
|
},
|
|
56
|
-
})
|
|
56
|
+
});
|
|
57
57
|
|
|
58
58
|
_modalProps['onUpdate:open'] = (visiable) => {
|
|
59
|
-
_modalProps.open = visiable
|
|
60
|
-
}
|
|
59
|
+
_modalProps.open = visiable;
|
|
60
|
+
};
|
|
61
61
|
(compProps as any).ref = compRef;
|
|
62
|
-
(compProps as any).onClose = close
|
|
62
|
+
(compProps as any).onClose = close;
|
|
63
63
|
|
|
64
|
-
return { PresetComponent, modalProps: _modalProps, compProps, $comp: compRef, open, close }
|
|
64
|
+
return { PresetComponent, modalProps: _modalProps, compProps, $comp: compRef, open, close };
|
|
65
65
|
}
|