@qin-ui/antdv-next-pro 1.1.14 → 1.2.0
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/AI-CONTEXT.md +281 -23
- package/LICENSE +9 -0
- package/README.md +75 -58
- package/api.json +70 -28
- package/bin/init-ai.mjs +404 -49
- package/es/antdv-next-pro.css +9 -9
- package/es/component-provider/{index-Daiw7IxY.js → index-Tesc9NuK.js} +2 -1
- package/es/component-provider/index-Tesc9NuK.js.map +1 -0
- package/es/component-provider/index.js +2 -1
- package/es/component-provider/index.js.map +1 -0
- package/es/components/component-provider/components/index.vue.d.ts +27 -0
- package/es/components/component-provider/components/index.vue.d.ts.map +1 -0
- package/es/components/component-provider/constants/index.d.ts +16 -0
- package/es/components/component-provider/constants/index.d.ts.map +1 -0
- package/es/components/component-provider/index.d.ts +4 -0
- package/es/components/component-provider/index.d.ts.map +1 -0
- package/es/components/component-provider/types/index.d.ts +26 -0
- package/es/components/component-provider/types/index.d.ts.map +1 -0
- package/es/components/form/components/BaseField/index.vue.d.ts +13 -0
- package/es/components/form/components/BaseField/index.vue.d.ts.map +1 -0
- package/es/components/form/components/BaseField/utils/index.d.ts +3 -0
- package/es/components/form/components/BaseField/utils/index.d.ts.map +1 -0
- package/es/components/form/components/BaseFormItem/index.vue.d.ts +9 -0
- package/es/components/form/components/BaseFormItem/index.vue.d.ts.map +1 -0
- package/es/components/form/components/ContainerFragment/index.vue.d.ts +23 -0
- package/es/components/form/components/ContainerFragment/index.vue.d.ts.map +1 -0
- package/es/components/form/components/GroupedFieldAttrs/index.vue.d.ts +31 -0
- package/es/components/form/components/GroupedFieldAttrs/index.vue.d.ts.map +1 -0
- package/es/components/form/components/PathProvider/index.vue.d.ts +24 -0
- package/es/components/form/components/PathProvider/index.vue.d.ts.map +1 -0
- package/es/components/form/components/ProForm/index.vue.d.ts +36 -0
- package/es/components/form/components/ProForm/index.vue.d.ts.map +1 -0
- package/es/components/form/components/SlotComponent/index.vue.d.ts +7 -0
- package/es/components/form/components/SlotComponent/index.vue.d.ts.map +1 -0
- package/es/components/form/components/index.d.ts +12 -0
- package/es/components/form/components/index.d.ts.map +1 -0
- package/es/components/form/constants/index.d.ts +81 -0
- package/es/components/form/constants/index.d.ts.map +1 -0
- package/es/components/form/hooks/index.d.ts +5 -0
- package/es/components/form/hooks/index.d.ts.map +1 -0
- package/es/components/form/hooks/useFields.d.ts +57 -0
- package/es/components/form/hooks/useFields.d.ts.map +1 -0
- package/es/components/form/hooks/useForm.d.ts +93 -0
- package/es/components/form/hooks/useForm.d.ts.map +1 -0
- package/es/components/form/hooks/useFormRef.d.ts +30 -0
- package/es/components/form/hooks/useFormRef.d.ts.map +1 -0
- package/es/components/form/index.d.ts +7 -0
- package/es/components/form/index.d.ts.map +1 -0
- package/es/components/form/types/index.d.ts +251 -0
- package/es/components/form/types/index.d.ts.map +1 -0
- package/es/components/table/components/ColumnControl.vue.d.ts +9 -0
- package/es/components/table/components/ColumnControl.vue.d.ts.map +1 -0
- package/es/components/table/components/DefaultSearchFormContainer.vue.d.ts +18 -0
- package/es/components/table/components/DefaultSearchFormContainer.vue.d.ts.map +1 -0
- package/es/components/table/components/DefaultTableContainer.vue.d.ts +18 -0
- package/es/components/table/components/DefaultTableContainer.vue.d.ts.map +1 -0
- package/es/components/table/components/ProTable.vue.d.ts +118 -0
- package/es/components/table/components/ProTable.vue.d.ts.map +1 -0
- package/es/components/table/components/SearchForm.vue.d.ts +48 -0
- package/es/components/table/components/SearchForm.vue.d.ts.map +1 -0
- package/es/components/table/components/SizeControl.vue.d.ts +12 -0
- package/es/components/table/components/SizeControl.vue.d.ts.map +1 -0
- package/es/components/table/components/icons/ColumnHeightOutlined.vue.d.ts +3 -0
- package/es/components/table/components/icons/ColumnHeightOutlined.vue.d.ts.map +1 -0
- package/es/components/table/components/icons/DownOutlined.vue.d.ts +3 -0
- package/es/components/table/components/icons/DownOutlined.vue.d.ts.map +1 -0
- package/es/components/table/components/icons/FilterOutlined.vue.d.ts +3 -0
- package/es/components/table/components/icons/FilterOutlined.vue.d.ts.map +1 -0
- package/es/components/table/components/index.d.ts +5 -0
- package/es/components/table/components/index.d.ts.map +1 -0
- package/es/components/table/index.d.ts +8 -0
- package/es/components/table/index.d.ts.map +1 -0
- package/es/components/table/types/index.d.ts +48 -0
- package/es/components/table/types/index.d.ts.map +1 -0
- package/es/components/table/useTable.d.ts +111 -0
- package/es/components/table/useTable.d.ts.map +1 -0
- package/es/form/{index-7clzY8ZD.js → index-CcP5OaUd.js} +12 -6
- package/es/form/index-CcP5OaUd.js.map +1 -0
- package/es/form/index.js +4 -3
- package/es/form/index.js.map +1 -0
- package/es/index.d.ts +76 -1522
- package/es/index.d.ts.map +1 -0
- package/es/index.js +14 -23
- package/es/index.js.map +1 -0
- package/es/shared/core/index.d.ts +6 -0
- package/es/shared/core/index.d.ts.map +1 -0
- package/es/shared/ui/index.d.ts +9 -0
- package/es/shared/ui/index.d.ts.map +1 -0
- package/es/table/index.js +11 -9
- package/es/table/index.js.map +1 -0
- package/package.json +10 -11
- package/src/components/component-provider/components/index.vue +67 -0
- package/src/components/component-provider/constants/index.ts +177 -0
- package/src/components/component-provider/index.ts +6 -0
- package/src/components/component-provider/types/index.ts +59 -0
- package/src/components/form/components/BaseField/index.vue +181 -0
- package/src/components/form/components/BaseField/utils/index.ts +16 -0
- package/src/components/form/components/BaseFormItem/index.vue +158 -0
- package/src/components/form/components/ContainerFragment/index.vue +24 -0
- package/src/components/form/components/GroupedFieldAttrs/index.vue +119 -0
- package/src/components/form/components/PathProvider/index.vue +19 -0
- package/src/components/form/components/ProForm/index.vue +104 -0
- package/src/components/form/components/SlotComponent/index.vue +26 -0
- package/src/components/form/components/index.ts +15 -0
- package/src/components/form/constants/index.ts +140 -0
- package/src/components/form/hooks/index.ts +5 -0
- package/src/components/form/hooks/useFields.ts +67 -0
- package/src/components/form/hooks/useForm.ts +110 -0
- package/src/components/form/hooks/useFormRef.ts +35 -0
- package/src/components/form/index.ts +29 -0
- package/src/components/form/types/index.ts +317 -0
- package/src/components/table/components/ColumnControl.vue +142 -0
- package/src/components/table/components/DefaultSearchFormContainer.vue +22 -0
- package/src/components/table/components/DefaultTableContainer.vue +19 -0
- package/src/components/table/components/ProTable.vue +372 -0
- package/src/components/table/components/SearchForm.vue +296 -0
- package/src/components/table/components/SizeControl.vue +54 -0
- package/src/components/table/components/icons/ColumnHeightOutlined.vue +4 -0
- package/src/components/table/components/icons/DownOutlined.vue +4 -0
- package/src/components/table/components/icons/FilterOutlined.vue +4 -0
- package/src/components/table/components/index.ts +4 -0
- package/src/components/table/index.ts +14 -0
- package/src/components/table/types/index.ts +52 -0
- package/src/components/table/useTable.ts +129 -0
- package/src/index.ts +81 -0
- package/src/shared/core/index.ts +37 -0
- package/src/shared/ui/index.ts +55 -0
- package/es/core/index-ghYuQ3Sy.js +0 -360
- package/es/vendor/utils/lodash-es-p6jau26B.js +0 -1120
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
import {
|
|
2
|
+
Cascader,
|
|
3
|
+
CheckboxGroup,
|
|
4
|
+
DatePicker,
|
|
5
|
+
AutoComplete,
|
|
6
|
+
Input,
|
|
7
|
+
InputNumber,
|
|
8
|
+
InputPassword,
|
|
9
|
+
InputSearch,
|
|
10
|
+
RadioGroup,
|
|
11
|
+
Select,
|
|
12
|
+
Slider,
|
|
13
|
+
Switch,
|
|
14
|
+
TextArea,
|
|
15
|
+
TimePicker,
|
|
16
|
+
TimeRangePicker,
|
|
17
|
+
Transfer,
|
|
18
|
+
TreeSelect,
|
|
19
|
+
RangePicker,
|
|
20
|
+
InputOTP,
|
|
21
|
+
} from '../../../shared/ui';
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* FormItem 插槽名称列表
|
|
25
|
+
* @description 用于在字段配置中透传 FormItem 的插槽
|
|
26
|
+
*/
|
|
27
|
+
// prettier-ignore
|
|
28
|
+
export const FORM_ITEM_SLOT_KEYS = ['label', 'extra', 'help', 'tooltip'] as const;
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* 内置组件映射表
|
|
32
|
+
* @description antdv-next 内置支持的组件类型映射。
|
|
33
|
+
* 每个 key 对应 Field 配置中 `component` 可使用的字符串值,
|
|
34
|
+
* value 为实际渲染的 antdv-next 组件。
|
|
35
|
+
*
|
|
36
|
+
* @public
|
|
37
|
+
*/
|
|
38
|
+
// prettier-ignore
|
|
39
|
+
export type BaseComponentMap = {
|
|
40
|
+
'input': typeof Input;
|
|
41
|
+
'textarea': typeof TextArea;
|
|
42
|
+
'input-search': typeof InputSearch;
|
|
43
|
+
'input-password': typeof InputPassword;
|
|
44
|
+
'input-number': typeof InputNumber;
|
|
45
|
+
'input-otp': typeof InputOTP;
|
|
46
|
+
'auto-complete': typeof AutoComplete;
|
|
47
|
+
'select': typeof Select;
|
|
48
|
+
'cascader': typeof Cascader;
|
|
49
|
+
'date-picker': typeof DatePicker;
|
|
50
|
+
'range-picker': typeof RangePicker;
|
|
51
|
+
'time-picker': typeof TimePicker;
|
|
52
|
+
'time-range-picker': typeof TimeRangePicker;
|
|
53
|
+
'checkbox-group': typeof CheckboxGroup;
|
|
54
|
+
'radio-group': typeof RadioGroup;
|
|
55
|
+
'switch': typeof Switch;
|
|
56
|
+
'slider': typeof Slider;
|
|
57
|
+
'tree-select': typeof TreeSelect;
|
|
58
|
+
'transfer': typeof Transfer;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* 组件映射扩展接口
|
|
63
|
+
* @description 暴露给外部扩充自定义组件类型的接口。
|
|
64
|
+
* 用户可通过 TypeScript 的声明合并(module augmentation)添加自定义组件。
|
|
65
|
+
*
|
|
66
|
+
* @example
|
|
67
|
+
* ```ts
|
|
68
|
+
* // 在项目中任意 .d.ts 文件中
|
|
69
|
+
* declare module '@qin-ui/antdv-next-pro' {
|
|
70
|
+
* interface ComponentMap {
|
|
71
|
+
* 'my-custom-input': typeof MyCustomInput;
|
|
72
|
+
* }
|
|
73
|
+
* }
|
|
74
|
+
* ```
|
|
75
|
+
|
|
76
|
+
* @public
|
|
77
|
+
*/
|
|
78
|
+
// eslint-disable-next-line @typescript-eslint/no-empty-object-type
|
|
79
|
+
export interface ComponentMap {}
|
|
80
|
+
|
|
81
|
+
/**
|
|
82
|
+
* 组件名称联合类型
|
|
83
|
+
* @description 所有支持的组件名称
|
|
84
|
+
|
|
85
|
+
* @public
|
|
86
|
+
*/
|
|
87
|
+
export type ComponentName =
|
|
88
|
+
| keyof BaseComponentMap
|
|
89
|
+
| keyof ComponentMap
|
|
90
|
+
| 'custom';
|
|
91
|
+
|
|
92
|
+
/**
|
|
93
|
+
* 根据组件名获取组件类型
|
|
94
|
+
* @template K - 组件名称
|
|
95
|
+
*/
|
|
96
|
+
export type GetComponentType<K extends ComponentName> =
|
|
97
|
+
K extends keyof ComponentMap
|
|
98
|
+
? ComponentMap[K]
|
|
99
|
+
: K extends keyof BaseComponentMap
|
|
100
|
+
? BaseComponentMap[K]
|
|
101
|
+
: never;
|
|
102
|
+
|
|
103
|
+
/**
|
|
104
|
+
* 组件名称到 antdv-next 组件的运行时映射
|
|
105
|
+
* @description ProForm 通过此映射将 Field 配置中的 component 字符串解析为实际 Vue 组件。
|
|
106
|
+
* 例如 `component: 'input'` → `Input`, `component: 'select'` → `Select`。
|
|
107
|
+
*
|
|
108
|
+
* @public
|
|
109
|
+
*/
|
|
110
|
+
// prettier-ignore
|
|
111
|
+
export const componentMap: BaseComponentMap = {
|
|
112
|
+
'input': Input,
|
|
113
|
+
'textarea': TextArea,
|
|
114
|
+
'input-search': InputSearch,
|
|
115
|
+
'input-password': InputPassword,
|
|
116
|
+
'input-number': InputNumber,
|
|
117
|
+
'input-otp': InputOTP,
|
|
118
|
+
'auto-complete': AutoComplete,
|
|
119
|
+
'select': Select,
|
|
120
|
+
'cascader': Cascader,
|
|
121
|
+
'date-picker': DatePicker,
|
|
122
|
+
'range-picker': RangePicker,
|
|
123
|
+
'time-picker': TimePicker,
|
|
124
|
+
'time-range-picker': TimeRangePicker,
|
|
125
|
+
'checkbox-group': CheckboxGroup,
|
|
126
|
+
'radio-group': RadioGroup,
|
|
127
|
+
'switch': Switch,
|
|
128
|
+
'slider': Slider,
|
|
129
|
+
'tree-select': TreeSelect,
|
|
130
|
+
'transfer': Transfer,
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
/**
|
|
134
|
+
* Teleport 组件名称前缀
|
|
135
|
+
* @description 用于通过插槽动态替换指定 path 的组件
|
|
136
|
+
*/
|
|
137
|
+
export const TeleportComponentNamePrefix = 'TeleportComponent_';
|
|
138
|
+
|
|
139
|
+
// inject keys
|
|
140
|
+
export { InjectionFormKey, InjectionPathKey } from '../../../shared/core';
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import { FormItemInstance } from '../../../shared/ui';
|
|
2
|
+
import {
|
|
3
|
+
useFields as coreUseFields,
|
|
4
|
+
type UseFieldsReturn,
|
|
5
|
+
} from '../../../shared/core';
|
|
6
|
+
import type { Data } from '../../../shared/core';
|
|
7
|
+
import type { Field, Fields } from '../types';
|
|
8
|
+
import type { ComponentName } from '../constants';
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* 字段配置管理 Hook
|
|
12
|
+
*
|
|
13
|
+
* @description 基于 `@qin-ui/pro-components-core` 的 `useFields`,将泛型参数绑定为 antdv-next 的本地类型:
|
|
14
|
+
* - 字段类型 F → `Field<ComponentName, D>`(支持 antdv-next 组件类型推导)
|
|
15
|
+
* - FormItem 实例 → antdv-next 的 `FormItemInstance`
|
|
16
|
+
*
|
|
17
|
+
* 提供对字段配置数组的增删改查操作,支持:
|
|
18
|
+
* - 通过路径字符串或查找函数定位字段
|
|
19
|
+
* - 深层嵌套字段的遍历和匹配
|
|
20
|
+
* - 字段配置的合并/覆盖更新
|
|
21
|
+
* - 字段的添加、插入、删除
|
|
22
|
+
* - 父级字段查找
|
|
23
|
+
*
|
|
24
|
+
* @template D - 表单数据类型
|
|
25
|
+
* @param {Fields<D>} [initFields] - 初始字段配置数组
|
|
26
|
+
*
|
|
27
|
+
* @returns 字段操作对象,包含以下属性:
|
|
28
|
+
* - `fields` — 字段配置数组(响应式 Ref\<F[]\>)
|
|
29
|
+
* - `getField(path)` — 获取字段配置,支持路径字符串或查找函数
|
|
30
|
+
* - `setField(path, field, options?)` — 更新字段配置,默认合并模式
|
|
31
|
+
* - `deleteField(path, options?)` — 删除字段配置
|
|
32
|
+
* - `appendField(path, field, options?)` — 在指定字段后追加
|
|
33
|
+
* - `prependField(path, field, options?)` — 在指定字段前插入
|
|
34
|
+
* - `getParentField(path, options?)` — 获取父级字段配置
|
|
35
|
+
*
|
|
36
|
+
* @example
|
|
37
|
+
* ```ts
|
|
38
|
+
* interface User { name: string; age: number }
|
|
39
|
+
*
|
|
40
|
+
* const { fields, getField, setField } = useFields<User>([
|
|
41
|
+
* { path: 'name', label: '姓名', component: 'input' },
|
|
42
|
+
* { path: 'age', label: '年龄', component: 'input-number' },
|
|
43
|
+
* ])
|
|
44
|
+
*
|
|
45
|
+
* // 通过路径获取
|
|
46
|
+
* getField('name')
|
|
47
|
+
* // 通过查找函数获取
|
|
48
|
+
* getField(f => f.label === '姓名')
|
|
49
|
+
* // 更新字段(合并模式)
|
|
50
|
+
* setField('name', { label: '用户名', disabled: true })
|
|
51
|
+
* ```
|
|
52
|
+
*
|
|
53
|
+
* @see {@link coreUseFields} 底层核心实现(来自 @qin-ui/pro-components-core)
|
|
54
|
+
*
|
|
55
|
+
* @public
|
|
56
|
+
*/
|
|
57
|
+
export function useFields<D extends Data = Data>(
|
|
58
|
+
initFields?: Fields<D>
|
|
59
|
+
): UseFieldsReturn<D, Field<ComponentName, D>, FormItemInstance>;
|
|
60
|
+
export function useFields(initFields?: any) {
|
|
61
|
+
return coreUseFields(initFields);
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
/** useFields 返回值类型
|
|
65
|
+
* @public
|
|
66
|
+
*/
|
|
67
|
+
export type UseFields<D extends Data = Data> = ReturnType<typeof useFields<D>>;
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
import {
|
|
2
|
+
useForm as coreUseForm,
|
|
3
|
+
type Form as _Form,
|
|
4
|
+
} from '../../../shared/core';
|
|
5
|
+
import type { Data, ExtendWithAny, DeepPartial } from '../../../shared/core';
|
|
6
|
+
import type { Field } from '../types';
|
|
7
|
+
import type { ComponentName } from '../constants';
|
|
8
|
+
import type { FormInstance } from '../../../shared/ui';
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* 表单实例类型
|
|
12
|
+
*
|
|
13
|
+
* @description 在 core Form 类型的基础上,将字段类型 F 绑定为本地 Field<ComponentName, D>,
|
|
14
|
+
* 将底层表单实例 I 绑定为 antdv-next 的 FormInstance,使 formRef 获得完整的类型提示。
|
|
15
|
+
*
|
|
16
|
+
* @template D - 表单数据类型
|
|
17
|
+
* @template F - 字段配置类型,默认使用本地 Field 类型
|
|
18
|
+
*
|
|
19
|
+
* @property formData - 响应式表单数据对象,可直接读写,支持深层路径如 `formData.address.city`
|
|
20
|
+
* @property getFormData - 获取指定路径的表单数据,支持点号分隔的深层路径,如 `getFormData('address.city')`
|
|
21
|
+
* @property setFormData - 设置表单数据,支持三种调用方式:<br>
|
|
22
|
+
* 1. `setFormData(path, value)` — 设置指定路径的值<br>
|
|
23
|
+
* 2. `setFormData(path, prev => newVal)` — 函数式更新<br>
|
|
24
|
+
* 3. `setFormData({ ... })` — 批量覆盖整个表单
|
|
25
|
+
* @property fields - 字段配置数组(响应式 Ref),ProForm 根据此数组渲染表单字段
|
|
26
|
+
* @property getField - 获取字段配置,支持路径字符串(如 `'name'`)或查找函数(如 `f => f.label === '姓名'`)
|
|
27
|
+
* @property setField - 更新字段配置,默认合并模式(Object.assign),可通过 `{ updateType: 'rewrite' }` 覆盖
|
|
28
|
+
* @property deleteField - 删除字段配置,支持 `{ all: true }` 批量删除所有匹配项
|
|
29
|
+
* @property appendField - 在指定字段后追加新字段,传 `undefined` 则在末尾追加
|
|
30
|
+
* @property prependField - 在指定字段前插入新字段,传 `undefined` 则在开头插入
|
|
31
|
+
* @property getParentField - 获取指定字段的父级字段配置,用于嵌套字段场景
|
|
32
|
+
* @property formRef - 底层 antdv-next Form 组件实例的响应式引用(Ref),可调用 `validate()`、`resetFields()` 等方法
|
|
33
|
+
* @property setFormRef - 设置底层 Form 组件实例,由 ProForm 内部自动调用,一般无需手动使用
|
|
34
|
+
*
|
|
35
|
+
* @example
|
|
36
|
+
* ```ts
|
|
37
|
+
* interface User { name: string; age: number }
|
|
38
|
+
* const form: Form<User> = useForm({ name: '张三', age: 25 })
|
|
39
|
+
*
|
|
40
|
+
* form.formData.name // 直接读写响应式数据
|
|
41
|
+
* form.getFormData('name') // 通过路径读取
|
|
42
|
+
* form.setFormData('name', '李四') // 更新数据
|
|
43
|
+
* form.formRef.value?.validate() // 访问底层 Form 实例
|
|
44
|
+
* ```
|
|
45
|
+
*
|
|
46
|
+
* @public
|
|
47
|
+
*/
|
|
48
|
+
export type Form<
|
|
49
|
+
D extends Data = Data,
|
|
50
|
+
F extends Field<ComponentName, D> = Field<ComponentName, D>,
|
|
51
|
+
> = _Form<D, F, FormInstance>;
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* 创建表单实例的 Hook
|
|
55
|
+
*
|
|
56
|
+
* @description 基于 `@qin-ui/pro-components-core` 的 `useForm`,将泛型参数绑定为 antdv-next 的本地类型:
|
|
57
|
+
* - 字段类型 F → `Field<ComponentName, D>`(支持 antdv-next 所有内置组件类型推导)
|
|
58
|
+
* - 表单实例 → antdv-next 的 `FormInstance`(使 formRef 获得完整的类型提示)
|
|
59
|
+
*
|
|
60
|
+
* 表单实例组合了三个子模块的能力:
|
|
61
|
+
* - **useFormData**:表单数据管理(响应式数据、读写、批量更新)
|
|
62
|
+
* - **useFields**:字段配置管理(增删改查字段配置,支持嵌套)
|
|
63
|
+
* - **useFormRef**:底层 Form 组件实例引用
|
|
64
|
+
*
|
|
65
|
+
* @template D - 表单数据类型
|
|
66
|
+
*
|
|
67
|
+
* @param {ExtendWithAny<DeepPartial<D>>} [initFormData] - 初始表单数据
|
|
68
|
+
* @param {Field<ComponentName, D>[]} [initFields] - 初始字段配置数组
|
|
69
|
+
* @param {boolean} [root=true] - 是否为根表单。设为 `false` 时尝试从父组件注入获取表单实例
|
|
70
|
+
*
|
|
71
|
+
* @returns {Form<D>} 表单实例,包含数据操作、字段操作和 ref 操作
|
|
72
|
+
*
|
|
73
|
+
* @example
|
|
74
|
+
* ```ts
|
|
75
|
+
* interface User { name: string; age: number }
|
|
76
|
+
*
|
|
77
|
+
* // 方式一:同时传入初始数据和字段
|
|
78
|
+
* const form = useForm<User>(
|
|
79
|
+
* { name: '张三', age: 25 },
|
|
80
|
+
* [
|
|
81
|
+
* { path: 'name', label: '姓名', component: 'input' },
|
|
82
|
+
* { path: 'age', label: '年龄', component: 'input-number' },
|
|
83
|
+
* ],
|
|
84
|
+
* true
|
|
85
|
+
* )
|
|
86
|
+
*
|
|
87
|
+
* // 方式二:仅设置 root 标识
|
|
88
|
+
* const form = useForm<User>(true)
|
|
89
|
+
*
|
|
90
|
+
* // 使用
|
|
91
|
+
* const { formData, formRef, fields, setFormData, getField } = form
|
|
92
|
+
* setFormData('name', '李四')
|
|
93
|
+
* await formRef.value?.validate()
|
|
94
|
+
* ```
|
|
95
|
+
*
|
|
96
|
+
* @see {@link coreUseForm} 底层核心实现(来自 @qin-ui/pro-components-core)
|
|
97
|
+
*
|
|
98
|
+
* @public
|
|
99
|
+
*/
|
|
100
|
+
export function useForm<D extends Data = Data>(
|
|
101
|
+
initFormData?: ExtendWithAny<DeepPartial<D>>,
|
|
102
|
+
initFields?: Field<ComponentName, D>[],
|
|
103
|
+
root?: boolean
|
|
104
|
+
): Form<D, Field<ComponentName, D>>;
|
|
105
|
+
export function useForm<D extends Data = Data>(
|
|
106
|
+
root?: boolean
|
|
107
|
+
): Form<D, Field<ComponentName, D>>;
|
|
108
|
+
export function useForm(...args: any[]) {
|
|
109
|
+
return coreUseForm(...(args as any));
|
|
110
|
+
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import {
|
|
2
|
+
useFormRef as coreUseFormRef,
|
|
3
|
+
type UseFormRefReturn,
|
|
4
|
+
} from '../../../shared/core';
|
|
5
|
+
import type { FormInstance } from '../../../shared/ui';
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* 表单组件实例引用 Hook
|
|
9
|
+
*
|
|
10
|
+
* @description 基于 `@qin-ui/pro-components-core` 的 `useFormRef`,将泛型参数绑定为 antdv-next 的 `FormInstance`,
|
|
11
|
+
* 使 formRef 获取到完整的 antdv-next Form 组件 API 类型提示(如 `validate()`、`resetFields()` 等)。
|
|
12
|
+
*
|
|
13
|
+
* `formRef` 由 ProForm 组件内部自动通过 `setFormRef` 绑定,无需手动调用。
|
|
14
|
+
*
|
|
15
|
+
* @returns 表单组件实例引用管理对象:
|
|
16
|
+
* - `formRef` — antdv-next Form 组件实例的响应式引用(`Ref<FormInstance | undefined>`)
|
|
17
|
+
* - `setFormRef(inst)` — 设置 Form 组件实例,由 ProForm 内部自动调用
|
|
18
|
+
*
|
|
19
|
+
* @example
|
|
20
|
+
* ```ts
|
|
21
|
+
* const { formRef, setFormRef } = useFormRef()
|
|
22
|
+
*
|
|
23
|
+
* // formRef 由 ProForm 自动绑定,可直接使用
|
|
24
|
+
* await formRef.value?.validate()
|
|
25
|
+
* formRef.value?.resetFields()
|
|
26
|
+
* formRef.value?.scrollToField('username')
|
|
27
|
+
* ```
|
|
28
|
+
*
|
|
29
|
+
* @see {@link coreUseFormRef} 底层核心实现(来自 @qin-ui/pro-components-core)
|
|
30
|
+
*
|
|
31
|
+
* @public
|
|
32
|
+
*/
|
|
33
|
+
export function useFormRef(): UseFormRefReturn<FormInstance> {
|
|
34
|
+
return coreUseFormRef();
|
|
35
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import ProForm from './components/ProForm/index.vue';
|
|
2
|
+
|
|
3
|
+
// 1. 仅导出核心 Vue 组件包装及外部可重用组件与类型
|
|
4
|
+
export {
|
|
5
|
+
ContainerFragment,
|
|
6
|
+
SlotComponent,
|
|
7
|
+
type ProFormProps,
|
|
8
|
+
type ProFormInstance,
|
|
9
|
+
type ProFormItemProps,
|
|
10
|
+
type ProFormItemInstance,
|
|
11
|
+
} from './components';
|
|
12
|
+
|
|
13
|
+
// 2. 仅导出允许模块合并扩展的 ComponentMap 以及组件名类型
|
|
14
|
+
export { type ComponentMap, type ComponentName } from './constants';
|
|
15
|
+
|
|
16
|
+
// 3. 仅导出核心表单配置 Schema 类型
|
|
17
|
+
export { type Field, type Fields } from './types';
|
|
18
|
+
|
|
19
|
+
// 4. 仅导出核心业务 Hooks
|
|
20
|
+
export {
|
|
21
|
+
useForm,
|
|
22
|
+
useFields,
|
|
23
|
+
useFormRef,
|
|
24
|
+
useFormData,
|
|
25
|
+
type Form,
|
|
26
|
+
type UseFields,
|
|
27
|
+
} from './hooks';
|
|
28
|
+
|
|
29
|
+
export default ProForm;
|