@xiaohaih/json-form-vant 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +9 -0
- package/README.md +807 -0
- package/TODO.md +36 -0
- package/components/area/index.ts +6 -0
- package/components/area/index.vue +120 -0
- package/components/area/types.ts +84 -0
- package/components/cascader/index.ts +6 -0
- package/components/cascader/index.vue +146 -0
- package/components/cascader/types.ts +75 -0
- package/components/checkbox/index.ts +6 -0
- package/components/checkbox/index.vue +59 -0
- package/components/checkbox/types.ts +54 -0
- package/components/checkbox-group/index.ts +6 -0
- package/components/checkbox-group/index.vue +67 -0
- package/components/checkbox-group/types.ts +63 -0
- package/components/component-definition/components.ts +29 -0
- package/components/component-definition/definition.ts +25 -0
- package/components/component-definition/index.ts +4 -0
- package/components/custom-render/index.ts +6 -0
- package/components/custom-render/index.vue +66 -0
- package/components/custom-render/types.ts +43 -0
- package/components/date-picker/index.ts +6 -0
- package/components/date-picker/index.vue +130 -0
- package/components/date-picker/types.ts +91 -0
- package/components/date-time-picker-group/index.ts +6 -0
- package/components/date-time-picker-group/index.vue +158 -0
- package/components/date-time-picker-group/types.ts +115 -0
- package/components/datetime-picker/index.ts +6 -0
- package/components/datetime-picker/index.vue +128 -0
- package/components/datetime-picker/types.ts +78 -0
- package/components/dynamic-group/index.ts +10 -0
- package/components/dynamic-group/index.vue +140 -0
- package/components/dynamic-group/types.ts +68 -0
- package/components/group/assist.ts +99 -0
- package/components/group/index.ts +7 -0
- package/components/group/index.vue +117 -0
- package/components/group/types.ts +57 -0
- package/components/group/virtual-group.vue +38 -0
- package/components/index.ts +10 -0
- package/components/input/index.ts +6 -0
- package/components/input/index.vue +83 -0
- package/components/input/types.ts +43 -0
- package/components/input-slot/index.ts +6 -0
- package/components/input-slot/index.vue +148 -0
- package/components/input-slot/types.ts +34 -0
- package/components/number-keyboard/index.ts +6 -0
- package/components/number-keyboard/index.vue +81 -0
- package/components/number-keyboard/types.ts +57 -0
- package/components/password-input/index.ts +6 -0
- package/components/password-input/index.vue +103 -0
- package/components/password-input/types.ts +64 -0
- package/components/picker/index.ts +6 -0
- package/components/picker/index.vue +136 -0
- package/components/picker/types.ts +94 -0
- package/components/radio/index.ts +6 -0
- package/components/radio/index.vue +68 -0
- package/components/radio/types.ts +58 -0
- package/components/radio-group/index.ts +6 -0
- package/components/radio-group/index.vue +74 -0
- package/components/radio-group/types.ts +65 -0
- package/components/rate/index.ts +6 -0
- package/components/rate/index.vue +63 -0
- package/components/rate/types.ts +47 -0
- package/components/share.ts +78 -0
- package/components/signature/index.ts +6 -0
- package/components/signature/index.vue +65 -0
- package/components/signature/instance.vue +161 -0
- package/components/signature/types.ts +79 -0
- package/components/slider/index.ts +6 -0
- package/components/slider/index.vue +63 -0
- package/components/slider/types.ts +53 -0
- package/components/stepper/index.ts +6 -0
- package/components/stepper/index.vue +62 -0
- package/components/stepper/types.ts +47 -0
- package/components/switch/index.ts +6 -0
- package/components/switch/index.vue +61 -0
- package/components/switch/types.ts +51 -0
- package/components/time-picker/index.ts +6 -0
- package/components/time-picker/index.vue +130 -0
- package/components/time-picker/types.ts +91 -0
- package/components/tree-select/index.ts +6 -0
- package/components/tree-select/index.vue +160 -0
- package/components/tree-select/types.ts +77 -0
- package/components/upload/index.ts +6 -0
- package/components/upload/index.vue +109 -0
- package/components/upload/types.ts +85 -0
- package/components/use.ts +45 -0
- package/components/utils.ts +52 -0
- package/components/wrapper/index.ts +6 -0
- package/components/wrapper/index.vue +117 -0
- package/components/wrapper/types.ts +94 -0
- package/dist/components/area/index.d.ts +5 -0
- package/dist/components/area/index.vue.d.ts +1843 -0
- package/dist/components/area/types.d.ts +1434 -0
- package/dist/components/cascader/index.d.ts +5 -0
- package/dist/components/cascader/index.vue.d.ts +2467 -0
- package/dist/components/cascader/types.d.ts +1419 -0
- package/dist/components/checkbox/index.d.ts +5 -0
- package/dist/components/checkbox/index.vue.d.ts +1550 -0
- package/dist/components/checkbox/types.d.ts +1313 -0
- package/dist/components/checkbox-group/index.d.ts +5 -0
- package/dist/components/checkbox-group/index.vue.d.ts +1643 -0
- package/dist/components/checkbox-group/types.d.ts +1372 -0
- package/dist/components/component-definition/components.d.ts +30 -0
- package/dist/components/component-definition/index.d.ts +4 -0
- package/dist/components/custom-render/index.d.ts +5 -0
- package/dist/components/custom-render/index.vue.d.ts +1473 -0
- package/dist/components/custom-render/types.d.ts +1175 -0
- package/dist/components/date-picker/index.d.ts +5 -0
- package/dist/components/date-picker/index.vue.d.ts +1888 -0
- package/dist/components/date-picker/types.d.ts +1458 -0
- package/dist/components/date-time-picker-group/index.d.ts +5 -0
- package/dist/components/date-time-picker-group/index.vue.d.ts +2181 -0
- package/dist/components/date-time-picker-group/types.d.ts +1549 -0
- package/dist/components/dynamic-group/index.d.ts +5 -0
- package/dist/components/dynamic-group/index.vue.d.ts +457 -0
- package/dist/components/dynamic-group/types.d.ts +403 -0
- package/dist/components/group/assist.d.ts +58 -0
- package/dist/components/group/index.d.ts +6 -0
- package/dist/components/group/index.vue.d.ts +139 -0
- package/dist/components/group/types.d.ts +189 -0
- package/dist/components/group/virtual-group.vue.d.ts +42 -0
- package/dist/components/index.d.ts +3 -0
- package/dist/components/input/index.d.ts +5 -0
- package/dist/components/input/index.vue.d.ts +2229 -0
- package/dist/components/input/types.d.ts +1258 -0
- package/dist/components/input-slot/index.d.ts +5 -0
- package/dist/components/input-slot/index.vue.d.ts +626 -0
- package/dist/components/input-slot/types.d.ts +311 -0
- package/dist/components/number-keyboard/index.d.ts +5 -0
- package/dist/components/number-keyboard/index.vue.d.ts +1643 -0
- package/dist/components/number-keyboard/types.d.ts +1324 -0
- package/dist/components/password-input/index.d.ts +5 -0
- package/dist/components/password-input/index.vue.d.ts +1715 -0
- package/dist/components/password-input/types.d.ts +1357 -0
- package/dist/components/picker/index.d.ts +5 -0
- package/dist/components/picker/index.vue.d.ts +1868 -0
- package/dist/components/picker/types.d.ts +1466 -0
- package/dist/components/radio/index.d.ts +5 -0
- package/dist/components/radio/index.vue.d.ts +1563 -0
- package/dist/components/radio/types.d.ts +1327 -0
- package/dist/components/radio-group/index.d.ts +5 -0
- package/dist/components/radio-group/index.vue.d.ts +1617 -0
- package/dist/components/radio-group/types.d.ts +1383 -0
- package/dist/components/rate/index.d.ts +5 -0
- package/dist/components/rate/index.vue.d.ts +1557 -0
- package/dist/components/rate/types.d.ts +1281 -0
- package/dist/components/share.d.ts +679 -0
- package/dist/components/signature/index.d.ts +5 -0
- package/dist/components/signature/index.vue.d.ts +3017 -0
- package/dist/components/signature/instance.vue.d.ts +1614 -0
- package/dist/components/signature/types.d.ts +1369 -0
- package/dist/components/slider/index.d.ts +5 -0
- package/dist/components/slider/index.vue.d.ts +1563 -0
- package/dist/components/slider/types.d.ts +1302 -0
- package/dist/components/stepper/index.d.ts +5 -0
- package/dist/components/stepper/index.vue.d.ts +1620 -0
- package/dist/components/stepper/types.d.ts +1281 -0
- package/dist/components/switch/index.d.ts +5 -0
- package/dist/components/switch/index.vue.d.ts +1529 -0
- package/dist/components/switch/types.d.ts +1296 -0
- package/dist/components/time-picker/index.d.ts +5 -0
- package/dist/components/time-picker/index.vue.d.ts +1936 -0
- package/dist/components/time-picker/types.d.ts +1458 -0
- package/dist/components/tree-select/index.d.ts +5 -0
- package/dist/components/tree-select/index.vue.d.ts +1802 -0
- package/dist/components/tree-select/types.d.ts +1411 -0
- package/dist/components/upload/index.d.ts +5 -0
- package/dist/components/upload/index.vue.d.ts +1697 -0
- package/dist/components/upload/types.d.ts +1376 -0
- package/dist/components/use.d.ts +53 -0
- package/dist/components/utils.d.ts +15 -0
- package/dist/components/wrapper/index.d.ts +5 -0
- package/dist/components/wrapper/index.vue.d.ts +1085 -0
- package/dist/components/wrapper/types.d.ts +541 -0
- package/dist/docs/.vitepress/config.d.ts +3 -0
- package/dist/docs/.vitepress/theme/index.d.ts +2 -0
- package/dist/index.cjs.js +5459 -0
- package/dist/index.cjs.js.map +1 -0
- package/dist/index.cjs.min.js +3568 -0
- package/dist/index.cjs.min.js.map +1 -0
- package/dist/index.esm.js +5264 -0
- package/dist/index.esm.js.map +1 -0
- package/dist/index.esm.min.js +3559 -0
- package/dist/index.esm.min.js.map +1 -0
- package/dist/index.umd.js +5465 -0
- package/dist/index.umd.js.map +1 -0
- package/dist/index.umd.min.js +3573 -0
- package/dist/index.umd.min.js.map +1 -0
- package/dist/src/assist.d.ts +32 -0
- package/dist/src/index.d.ts +5 -0
- package/dist/src/interface.d.ts +129 -0
- package/dist/src/utils.d.ts +9 -0
- package/dist/src/version.d.ts +2 -0
- package/docs/.vitepress/config.ts +99 -0
- package/docs/.vitepress/theme/index.ts +5 -0
- package/docs/README.md +20 -0
- package/docs/index.md +25 -0
- package/env.d.ts +8 -0
- package/package.json +71 -0
- package/scripts/generate-version.mjs +26 -0
- package/scripts/postinstall.cjs +13 -0
- package/scripts/utils.cjs +67 -0
- package/src/assist.ts +40 -0
- package/src/index.ts +5 -0
- package/src/interface.ts +293 -0
- package/src/utils.ts +22 -0
- package/src/version.ts +2 -0
- package/tsconfig.app.json +41 -0
- package/tsconfig.json +7 -0
- package/tsconfig.node.json +24 -0
- package/tsdown.config.ts +12 -0
- package/vite.config.ts +93 -0
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import type { usePlain } from '@xiaohaih/json-form-core';
|
|
2
|
+
import type { Ref } from 'vue';
|
|
3
|
+
import { computed, nextTick, ref, watch } from 'vue';
|
|
4
|
+
import { pick } from '../src/utils';
|
|
5
|
+
|
|
6
|
+
/** 表单组件的常用属性 */
|
|
7
|
+
export function useCommonSetup<Props extends Record<string, any>, Context extends Record<string, any>>(props: Props, ctx: Context, plain: ReturnType<typeof usePlain>) {
|
|
8
|
+
/** 插槽常用属性 */
|
|
9
|
+
const slotProps = computed(() => ({ props, plain }));
|
|
10
|
+
|
|
11
|
+
return { slotProps };
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* 为选中值构建临时变量
|
|
16
|
+
* 某些 UI 组件并不直接使用 modelValue, 而是内部维护一个变量
|
|
17
|
+
* 当内部值发生变化, 而 modelValue 又立马重置为相同值时
|
|
18
|
+
* 导致组件内部值无法同步 modelValue
|
|
19
|
+
*/
|
|
20
|
+
export function useTempChecked(checked: Ref<any>) {
|
|
21
|
+
const tempChecked = ref(checked.value);
|
|
22
|
+
// 监听外部值变化, 当第三方组件直接改变值时, 需要同步
|
|
23
|
+
watch(checked, (val) => tempChecked.value = val);
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* 对 change 做特殊处理, 异步改变值
|
|
27
|
+
* 防止存在默认值时, vant 组件清空值时
|
|
28
|
+
* 内部马上重写会导致值更新了, ui 未更新
|
|
29
|
+
*/
|
|
30
|
+
function change(value: any) {
|
|
31
|
+
checked.value = tempChecked.value = value;
|
|
32
|
+
tempChecked.value !== checked.value && nextTick(() => tempChecked.value = checked.value);
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* 对 change 做特殊处理, 同步改变值
|
|
36
|
+
* 临时变量直接等于值时, 无法得到 checked.value 最新的值
|
|
37
|
+
* 因此等 checked.value 赋值后再等于其即可
|
|
38
|
+
*/
|
|
39
|
+
function changeSync(value: any) {
|
|
40
|
+
checked.value = value;
|
|
41
|
+
tempChecked.value = checked.value;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
return { tempChecked, change, changeSync };
|
|
45
|
+
}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 根据指定值获取树形链
|
|
3
|
+
* @param {Array} sources 待查找的数据源
|
|
4
|
+
* @param {object} value 匹配值
|
|
5
|
+
* @param {string} childrenKey 子级的 key, 默认 children
|
|
6
|
+
*/
|
|
7
|
+
export function getChained<T extends Record<string, any>>(
|
|
8
|
+
sources: T[],
|
|
9
|
+
value: Partial<T>,
|
|
10
|
+
childrenKey = 'children',
|
|
11
|
+
): T[] {
|
|
12
|
+
const result: T[] = [];
|
|
13
|
+
carryChained(
|
|
14
|
+
sources,
|
|
15
|
+
value,
|
|
16
|
+
(data) => {
|
|
17
|
+
result.unshift(data);
|
|
18
|
+
},
|
|
19
|
+
childrenKey,
|
|
20
|
+
);
|
|
21
|
+
return result;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* 寻找匹配条件值并执行回调
|
|
26
|
+
* @param {Array} sources 待查找的数据源
|
|
27
|
+
* @param {object} value 匹配值
|
|
28
|
+
* @param {Function} callback 执行的回调
|
|
29
|
+
* @param {string} childrenKey 子级的 key, 默认 children
|
|
30
|
+
*/
|
|
31
|
+
export function carryChained<T extends Record<string, any>>(
|
|
32
|
+
sources: T[],
|
|
33
|
+
value: Partial<T>,
|
|
34
|
+
callback: (data: T, isDeep?: boolean) => void,
|
|
35
|
+
childrenKey = 'children',
|
|
36
|
+
): boolean | undefined {
|
|
37
|
+
const conditions = Object.entries(value);
|
|
38
|
+
for (const v of sources) {
|
|
39
|
+
const status = conditions.every(([k, val]) => val === v[k]);
|
|
40
|
+
if (status) {
|
|
41
|
+
callback(v, true);
|
|
42
|
+
return true;
|
|
43
|
+
}
|
|
44
|
+
if (v[childrenKey] && v[childrenKey].length) {
|
|
45
|
+
const result = carryChained(v[childrenKey], value, callback, childrenKey);
|
|
46
|
+
if (result) {
|
|
47
|
+
callback(v);
|
|
48
|
+
return true;
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
}
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<HGroup v-bind="$attrs" ref="groupRef" :disabled="disabled" :config="config" :model="query" :query="query" :get-form-ref="getFormRef" :tag="VanForm" v-on="events" @submit="submitHandle">
|
|
3
|
+
<template v-if="$slots.prepend" #prepend>
|
|
4
|
+
<slot name="prepend" v-bind="slotProps" />
|
|
5
|
+
</template>
|
|
6
|
+
<template #append>
|
|
7
|
+
<slot v-bind="slotProps" />
|
|
8
|
+
</template>
|
|
9
|
+
</HGroup>
|
|
10
|
+
</template>
|
|
11
|
+
|
|
12
|
+
<script lang="ts">
|
|
13
|
+
import { execOnCallback, useWrapper } from '@xiaohaih/json-form-core';
|
|
14
|
+
import type { FormInstance } from 'vant';
|
|
15
|
+
import { Form as VanForm } from 'vant';
|
|
16
|
+
import type { Ref, SlotsType } from 'vue';
|
|
17
|
+
import { computed, defineComponent, Fragment, markRaw, nextTick, onMounted, ref, watch } from 'vue';
|
|
18
|
+
import type { ComponentExposed } from 'vue-component-type-helpers';
|
|
19
|
+
import { pick } from '../../src/utils';
|
|
20
|
+
import { HGroup } from '../group/index';
|
|
21
|
+
import type { FormSlots } from './types';
|
|
22
|
+
import { formEmitsPrivate as emits, formPropsPrivate as props } from './types';
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* @file 容器
|
|
26
|
+
*/
|
|
27
|
+
export default defineComponent({
|
|
28
|
+
name: 'HForm',
|
|
29
|
+
components: {
|
|
30
|
+
HGroup,
|
|
31
|
+
},
|
|
32
|
+
inheritAttrs: false,
|
|
33
|
+
props,
|
|
34
|
+
emits,
|
|
35
|
+
slots: Object as SlotsType<FormSlots<any, any>>,
|
|
36
|
+
setup(props, ctx) {
|
|
37
|
+
const groupRef = ref<ComponentExposed<typeof HGroup>>();
|
|
38
|
+
const formRef = computed(() => groupRef.value?.tagRef as FormInstance | undefined);
|
|
39
|
+
// @ts-expect-error 兼容 vue2.x
|
|
40
|
+
const events = computed(() => ctx.listeners || {});
|
|
41
|
+
|
|
42
|
+
/** 覆盖 van-form 的 submit 事件 */
|
|
43
|
+
function submitHandle(params: Record<any, string>) {
|
|
44
|
+
ctx.emit('submit', wrapper.getQuery());
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/** 验证 vant 的表单 */
|
|
48
|
+
function validate(...args: Parameters<FormInstance['validate']>) {
|
|
49
|
+
return formRef.value!.validate(...args);
|
|
50
|
+
}
|
|
51
|
+
/** 验证 vant 的表单字段 */
|
|
52
|
+
function validateField(...args: Parameters<FormInstance['validate']>) {
|
|
53
|
+
return formRef.value!.validate(...args);
|
|
54
|
+
}
|
|
55
|
+
/** 清除 vant 的表单验证 */
|
|
56
|
+
function clearValidate(...args: Parameters<FormInstance['resetValidation']>) {
|
|
57
|
+
return formRef.value!.resetValidation(...args);
|
|
58
|
+
}
|
|
59
|
+
/** 重置 vant 的表单验证 */
|
|
60
|
+
function resetValidation(...args: Parameters<FormInstance['resetValidation']>) {
|
|
61
|
+
return formRef.value!.resetValidation(...args);
|
|
62
|
+
}
|
|
63
|
+
/** 获取所有表单项当前的值 */
|
|
64
|
+
function getValues(...args: Parameters<FormInstance['getValues']>) {
|
|
65
|
+
return formRef.value!.getValues(...args);
|
|
66
|
+
}
|
|
67
|
+
/** 获取所有表单项的校验状态 */
|
|
68
|
+
function getValidationStatus(...args: Parameters<FormInstance['getValidationStatus']>) {
|
|
69
|
+
return formRef.value!.getValidationStatus(...args);
|
|
70
|
+
}
|
|
71
|
+
/** 滚动到指定表单字段 */
|
|
72
|
+
function scrollToField(...args: Parameters<FormInstance['scrollToField']>) {
|
|
73
|
+
return formRef.value!.scrollToField(...args);
|
|
74
|
+
}
|
|
75
|
+
/** 获取表单实例 */
|
|
76
|
+
function getFormRef() {
|
|
77
|
+
return formRef.value;
|
|
78
|
+
}
|
|
79
|
+
const wrapper = useWrapper(props, {
|
|
80
|
+
formRef,
|
|
81
|
+
});
|
|
82
|
+
/** 触发提交事件 */
|
|
83
|
+
function submit() {
|
|
84
|
+
formRef.value?.submit();
|
|
85
|
+
}
|
|
86
|
+
/** 重置 */
|
|
87
|
+
function reset() {
|
|
88
|
+
wrapper.reset();
|
|
89
|
+
setTimeout(clearValidate);
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
const slotProps = computed(() => ({ props, wrapper }));
|
|
93
|
+
|
|
94
|
+
return {
|
|
95
|
+
groupRef,
|
|
96
|
+
VanForm: markRaw(VanForm),
|
|
97
|
+
formRef: formRef as Ref<ComponentExposed<typeof VanForm>>,
|
|
98
|
+
events,
|
|
99
|
+
submitHandle,
|
|
100
|
+
...wrapper,
|
|
101
|
+
validate,
|
|
102
|
+
validateField,
|
|
103
|
+
clearValidate,
|
|
104
|
+
resetValidation,
|
|
105
|
+
submit,
|
|
106
|
+
reset,
|
|
107
|
+
getValues,
|
|
108
|
+
getValidationStatus,
|
|
109
|
+
scrollToField,
|
|
110
|
+
getFormRef,
|
|
111
|
+
slotProps,
|
|
112
|
+
};
|
|
113
|
+
},
|
|
114
|
+
});
|
|
115
|
+
</script>
|
|
116
|
+
|
|
117
|
+
<style></style>
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 表单包装器类型定义文件
|
|
3
|
+
*
|
|
4
|
+
* 定义表单组件所需的各种类型、属性和事件
|
|
5
|
+
*/
|
|
6
|
+
import type { CamelCase, WrapperProps as CoreWrapperProps, emits2props, Obj2Props, useWrapper, WrapperArrayable } from '@xiaohaih/json-form-core';
|
|
7
|
+
import { wrapperProps as coreWrapperProps, emits2obj } from '@xiaohaih/json-form-core';
|
|
8
|
+
import { Form as VanForm } from 'vant';
|
|
9
|
+
import type { Component, ExtractPublicPropTypes, PropType } from 'vue';
|
|
10
|
+
import type { ComponentExposed, ComponentProps } from 'vue-component-type-helpers';
|
|
11
|
+
import type { defineOption } from '../../src/assist';
|
|
12
|
+
import type { ComponentType } from '../share';
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Vant 表单属性对象
|
|
16
|
+
* 从 Vant Form 组件中提取属性定义
|
|
17
|
+
*/
|
|
18
|
+
const vantFormProps = VanForm.props as unknown as Obj2Props<ComponentProps<typeof VanForm>>;
|
|
19
|
+
/**
|
|
20
|
+
* Vant 表单事件对象
|
|
21
|
+
*/
|
|
22
|
+
const vantFormEmits = emits2obj(VanForm.emits);
|
|
23
|
+
|
|
24
|
+
/** 表单属性生成函数 */
|
|
25
|
+
export function formPropsGeneric<T extends Record<string, any> = Record<string, any>, O extends Record<keyof T, any> = Record<keyof T, any>>() {
|
|
26
|
+
type _Prop = typeof vantFormProps & ReturnType<typeof emits2props<null, [NonNullable<typeof vantFormEmits>]>> & {
|
|
27
|
+
class: { type: PropType<string | Record<string, any> | any[]> };
|
|
28
|
+
style: { type: PropType<string | Record<string, any> | any[]> };
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
return {
|
|
32
|
+
...{} as Omit<_Prop, 'model'>,
|
|
33
|
+
...coreWrapperProps,
|
|
34
|
+
/** 数据源 - 表单项配置对象 */
|
|
35
|
+
config: { type: [Object, Array, Function] as PropType<any[] | ((...args: any[]) => any) | Record<string, any>> },
|
|
36
|
+
} as const;
|
|
37
|
+
}
|
|
38
|
+
/** 表单组件内部使用的属性定义 */
|
|
39
|
+
export const formPropsPrivate = formPropsGeneric();
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* 表单组件对外暴露的属性定义
|
|
43
|
+
*/
|
|
44
|
+
export const formProps = {
|
|
45
|
+
...vantFormProps,
|
|
46
|
+
...formPropsPrivate,
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* 表单事件生成函数 - 泛型版本
|
|
51
|
+
*/
|
|
52
|
+
export function formEmitsGeneric<T>() {
|
|
53
|
+
return {
|
|
54
|
+
...{} as typeof vantFormEmits,
|
|
55
|
+
/** 重写提交事件 - 覆盖传参 */
|
|
56
|
+
submit: (params: Record<string, any>) => true,
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
/** 表单组件内部使用的事件定义 */
|
|
61
|
+
export const formEmitsPrivate = formEmitsGeneric();
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* 表单组件对外暴露的事件定义
|
|
65
|
+
*/
|
|
66
|
+
export const formEmits = {
|
|
67
|
+
...vantFormEmits,
|
|
68
|
+
...formEmitsPrivate,
|
|
69
|
+
} as typeof vantFormEmits & typeof formEmitsPrivate;
|
|
70
|
+
|
|
71
|
+
/**
|
|
72
|
+
* 表单事件类型定义
|
|
73
|
+
*/
|
|
74
|
+
export type FormEmits<T> = ReturnType<typeof formEmitsGeneric<T>>;
|
|
75
|
+
|
|
76
|
+
/**
|
|
77
|
+
* 表单插槽接口
|
|
78
|
+
*/
|
|
79
|
+
export interface FormSlots<Query extends Record<string, any>, OptionQuery extends Partial<Record<keyof Query, any>>> {
|
|
80
|
+
/** 前置插槽 - 在表单项之前 */
|
|
81
|
+
prepend?: ComponentType<FormSlotProps<Query, OptionQuery>>;
|
|
82
|
+
/** 默认插槽 - 在表单项之后 */
|
|
83
|
+
default?: ComponentType<FormSlotProps<Query, OptionQuery>>;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
/**
|
|
87
|
+
* 表单插槽属性接口
|
|
88
|
+
*/
|
|
89
|
+
export interface FormSlotProps<Query extends Record<string, any>, OptionQuery extends Partial<Record<keyof Query, any>>> {
|
|
90
|
+
/** 获取表单属性的方法 */
|
|
91
|
+
props: ExtractPublicPropTypes<ReturnType<typeof formPropsGeneric<Query, OptionQuery>>>;
|
|
92
|
+
/** 表单包装器实例 */
|
|
93
|
+
wrapper: ReturnType<typeof useWrapper>;
|
|
94
|
+
}
|