@qin-ui/vant-pro 1.0.4 → 1.1.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.
Files changed (88) hide show
  1. package/AI-CONTEXT.md +165 -23
  2. package/LICENSE +9 -0
  3. package/README.md +1 -1
  4. package/api.json +27 -22
  5. package/bin/init-ai.mjs +242 -52
  6. package/es/component-provider/{index-DC_k4_R3.js → index-cldbPMDQ.js} +5 -4
  7. package/es/component-provider/index-cldbPMDQ.js.map +1 -0
  8. package/es/component-provider/index.js +2 -1
  9. package/es/component-provider/index.js.map +1 -0
  10. package/es/components/component-provider/components/index.vue.d.ts +27 -0
  11. package/es/components/component-provider/components/index.vue.d.ts.map +1 -0
  12. package/es/components/component-provider/constants/index.d.ts +16 -0
  13. package/es/components/component-provider/constants/index.d.ts.map +1 -0
  14. package/es/components/component-provider/index.d.ts +4 -0
  15. package/es/components/component-provider/index.d.ts.map +1 -0
  16. package/es/components/component-provider/types/index.d.ts +16 -0
  17. package/es/components/component-provider/types/index.d.ts.map +1 -0
  18. package/es/components/form/components/BaseField/index.vue.d.ts +1323 -0
  19. package/es/components/form/components/BaseField/index.vue.d.ts.map +1 -0
  20. package/es/components/form/components/BaseField/utils/index.d.ts +3 -0
  21. package/es/components/form/components/BaseField/utils/index.d.ts.map +1 -0
  22. package/es/components/form/components/BaseFormItem/index.vue.d.ts +7 -0
  23. package/es/components/form/components/BaseFormItem/index.vue.d.ts.map +1 -0
  24. package/es/components/form/components/ContainerFragment/index.vue.d.ts +23 -0
  25. package/es/components/form/components/ContainerFragment/index.vue.d.ts.map +1 -0
  26. package/es/components/form/components/GroupedFieldAttrs/index.vue.d.ts +24 -0
  27. package/es/components/form/components/GroupedFieldAttrs/index.vue.d.ts.map +1 -0
  28. package/es/components/form/components/PathProvider/index.vue.d.ts +23 -0
  29. package/es/components/form/components/PathProvider/index.vue.d.ts.map +1 -0
  30. package/es/components/form/components/ProForm/index.vue.d.ts +34 -0
  31. package/es/components/form/components/ProForm/index.vue.d.ts.map +1 -0
  32. package/es/components/form/components/SlotComponent/index.vue.d.ts +7 -0
  33. package/es/components/form/components/SlotComponent/index.vue.d.ts.map +1 -0
  34. package/es/components/form/components/index.d.ts +12 -0
  35. package/es/components/form/components/index.d.ts.map +1 -0
  36. package/es/components/form/constants/index.d.ts +62 -0
  37. package/es/components/form/constants/index.d.ts.map +1 -0
  38. package/es/components/form/hooks/index.d.ts +6 -0
  39. package/es/components/form/hooks/index.d.ts.map +1 -0
  40. package/es/components/form/hooks/useFields.d.ts +57 -0
  41. package/es/components/form/hooks/useFields.d.ts.map +1 -0
  42. package/es/components/form/hooks/useForm.d.ts +101 -0
  43. package/es/components/form/hooks/useForm.d.ts.map +1 -0
  44. package/es/components/form/hooks/useFormPopup.d.ts +57 -0
  45. package/es/components/form/hooks/useFormPopup.d.ts.map +1 -0
  46. package/es/components/form/hooks/useFormRef.d.ts +30 -0
  47. package/es/components/form/hooks/useFormRef.d.ts.map +1 -0
  48. package/es/components/form/index.d.ts +7 -0
  49. package/es/components/form/index.d.ts.map +1 -0
  50. package/es/components/form/types/index.d.ts +152 -0
  51. package/es/components/form/types/index.d.ts.map +1 -0
  52. package/es/form/index.js +11 -7
  53. package/es/form/index.js.map +1 -0
  54. package/es/index.d.ts +58 -954
  55. package/es/index.d.ts.map +1 -0
  56. package/es/index.js +10 -21
  57. package/es/index.js.map +1 -0
  58. package/es/shared/core/index.d.ts +6 -0
  59. package/es/shared/core/index.d.ts.map +1 -0
  60. package/es/shared/ui/index.d.ts +2 -0
  61. package/es/shared/ui/index.d.ts.map +1 -0
  62. package/package.json +11 -12
  63. package/src/components/component-provider/components/index.vue +67 -0
  64. package/src/components/component-provider/constants/index.ts +110 -0
  65. package/src/components/component-provider/index.ts +6 -0
  66. package/src/components/component-provider/types/index.ts +31 -0
  67. package/src/components/form/components/BaseField/index.vue +340 -0
  68. package/src/components/form/components/BaseField/utils/index.ts +14 -0
  69. package/src/components/form/components/BaseFormItem/index.vue +77 -0
  70. package/src/components/form/components/ContainerFragment/index.vue +24 -0
  71. package/src/components/form/components/GroupedFieldAttrs/index.vue +51 -0
  72. package/src/components/form/components/PathProvider/index.vue +18 -0
  73. package/src/components/form/components/ProForm/index.vue +114 -0
  74. package/src/components/form/components/SlotComponent/index.vue +26 -0
  75. package/src/components/form/components/index.ts +15 -0
  76. package/src/components/form/constants/index.ts +109 -0
  77. package/src/components/form/hooks/index.ts +6 -0
  78. package/src/components/form/hooks/useFields.ts +67 -0
  79. package/src/components/form/hooks/useForm.ts +126 -0
  80. package/src/components/form/hooks/useFormPopup.ts +111 -0
  81. package/src/components/form/hooks/useFormRef.ts +35 -0
  82. package/src/components/form/index.ts +27 -0
  83. package/src/components/form/types/index.ts +220 -0
  84. package/src/index.ts +62 -0
  85. package/src/shared/core/index.ts +37 -0
  86. package/src/shared/ui/index.ts +26 -0
  87. package/es/core/index-B5vvm4Fj.js +0 -236
  88. package/es/vendor/utils/lodash-es-DN4QDiDm.js +0 -1079
package/AI-CONTEXT.md CHANGED
@@ -1,38 +1,180 @@
1
- # @qin-ui/vant-pro
1
+ # @qin-ui/vant-pro — AI 上下文
2
2
 
3
- > 基于 Vant v4 的配置驱动表单组件库。
3
+ > Schema-driven高级表单组件库,基于 **vant v4**(Vue 3 移动端UI,`van-` 前缀)。
4
+ > 核心思想:用 JS 对象描述 UI,而非在模板中堆砌组件标签。
4
5
 
5
- ## 安装
6
+ ---
6
7
 
7
- ```bash
8
- npm install @qin-ui/vant-pro vant vue
8
+ ## 1. 三层架构
9
+
10
+ ```
11
+ Field[] 配置层(用户编写的 JS 对象)
12
+ { path:'city', component:'picker', label:'城市', columns:[...], popup:true }
13
+
14
+ @qin-ui/vant-pro(Schema 解析 + 属性分层剥离)
15
+ van-field 属性 → <van-field> / 其余属性 → 内部输入控件
16
+
17
+ vant v4(Vue 3 移动端组件库)
18
+ van-field / van-picker / van-switch / van-stepper / ...
19
+ ```
20
+
21
+ ProForm 是**渲染引擎**,不是组件库。所有 UI 来自 vant。Field 配置的属性被**逐层剥离**,分发到 `van-field`(容器)和内部控件。
22
+
23
+ ### 组件映射表(componentMap,15 个内置组件)
24
+
25
+ | Field `component` | 渲染的 vant 组件 | 备注 |
26
+ | :----------------- | :--------------- | :------------------------------------------- |
27
+ | `'field'` | Field | **特殊:直接渲染 van-field,无内部控件包裹** |
28
+ | `'switch'` | Switch | v-model 绑定 `modelValue`(vant 默认约定) |
29
+ | `'stepper'` | Stepper | |
30
+ | `'rate'` | Rate | |
31
+ | `'slider'` | Slider | |
32
+ | `'uploader'` | Uploader | |
33
+ | `'checkbox-group'` | CheckboxGroup | |
34
+ | `'radio-group'` | RadioGroup | |
35
+ | `'picker'` | Picker | 常用 popup 模式(底部弹出) |
36
+ | `'date-picker'` | DatePicker | 常用 popup 模式 |
37
+ | `'time-picker'` | TimePicker | 常用 popup 模式 |
38
+ | `'cascader'` | Cascader | 常用 popup 模式 |
39
+ | `'area'` | Area | 常用 popup 模式 |
40
+ | `'signature'` | Signature | 常用 popup 模式 |
41
+ | `'button'` | Button | |
42
+ | `'custom'` | 自定义 | 传入 Vue 组件或 h() 渲染函数 |
43
+
44
+ > **编写任何输入控件属性前,必须查阅 [vant v4 官方文档](https://vant-ui.com/) 确认属性名和类型。**
45
+
46
+ ---
47
+
48
+ ## 2. 属性分层传递机制
49
+
50
+ Field 配置的属性**逐层剥离**,分发到两个目标:
51
+
52
+ **van-field 容器层(fieldAttrs):**
53
+ `label`, `rules`, `required`, `clearable`, `inputAlign`, `errorMessageAlign`, `colon`, `readonly`, `clickable`, `isLink`, `labelWidth`, `labelAlign`, `labelClass`, `error`, `center`, `border`, `autosize`, `type`, `maxlength`, `placeholder`, `rows`,以及所有 `on*` 事件回调。`fieldClass`/`fieldStyle` → `class`/`style` 绑定到 van-field。
54
+
55
+ **内部控件层(bindAttrs):**
56
+ 除上述外的其余属性(`columns`, `options`, `activeValue`, `min`, `max`, `step`, `count`, `size`, `direction`, `disabled` 等)。`componentClass`/`componentStyle` → 内部组件的 `class`/`style`。
57
+
58
+ **剥离逻辑:**
59
+
60
+ - 第一阶段(GroupedFieldAttrs):解构 `path`, `fields`, `hidden`, `extraProps` → 剩余 → `componentProps` → BaseField
61
+ - 第二阶段(BaseField):解构 `valueFormatter`, `displayFormatter`, `modelProp`, `slots`, `popup` 等 → 匹配 vant Field.props 的属性 + `on*` → `fieldAttrs` → van-field;其余 → `bindAttrs` → 内部控件
62
+
63
+ **`'field'` 特殊:** `component: 'field'` 直接渲染 van-field,无内部控件包裹,所有属性绑定到 van-field。
64
+
65
+ ### modelProp
66
+
67
+ 默认 `modelProp: 'modelValue'` → `v-model:modelValue`(vant 组件统一使用 `modelValue` 作为 v-model 绑定属性名)。
68
+
69
+ ---
70
+
71
+ ## 3. 渐进式用法
72
+
73
+ ### 3.1 基础渲染
74
+
75
+ 完全依赖 Field 配置,**禁止手写 `<van-field>` 或 `<van-switch>`**。
76
+
77
+ ```ts
78
+ import { ProForm, useForm } from '@qin-ui/vant-pro';
79
+ const form = useForm({ username: '', password: '' }, [
80
+ {
81
+ path: 'username',
82
+ component: 'field',
83
+ label: '用户名',
84
+ placeholder: '请输入用户名',
85
+ rules: [{ required: true }],
86
+ },
87
+ {
88
+ path: 'password',
89
+ component: 'field',
90
+ label: '密码',
91
+ type: 'password',
92
+ rules: [{ required: true }],
93
+ },
94
+ ]);
95
+ ```
96
+
97
+ ```html
98
+ <template><ProForm :form="form" /></template>
9
99
  ```
10
100
 
11
- ## 核心导出
101
+ ### 3.2 字段联动
12
102
 
13
- ### 组件
103
+ 初始化联动用 `computed()`,运行时联动用 `setField()`,外部状态用 `ref()`。**越简单越好:**
14
104
 
15
- - `ProForm` - 配置驱动表单组件
16
- - `ProComponentProvider` - 全局配置提供者
105
+ ```ts
106
+ // computed() 初始化时已确定的联动
107
+ disabled: computed(() => !form.formData.enabled);
17
108
 
18
- ### Hooks
109
+ // setField() — 事件触发时动态修改
110
+ form.setField('limitCount', { disabled: true });
111
+ ```
19
112
 
20
- - `useForm<D>()` - 创建表单实例
21
- - `useFields<D>()` - 字段配置管理
22
- - `useFormRef()` - 表单组件引用
113
+ ### 3.3 自定义组件
23
114
 
24
- ## 字段配置(Field)
115
+ ```ts
116
+ // h() 挂载或插槽接管
117
+ component: (p, ctx) => h(CustomPicker, { ...p, ...ctx.attrs }),
118
+ ```
25
119
 
26
- 每个字段支持:`path`, `label`, `component`, `hidden`, `disabled`, `rules`, `valueFormatter`, `fields`, `grid`, `slots`, `componentStyle`, `componentClass`, `componentContainer`, `formItemStyle`, `formItemClass`, `formItemContainer`, `modelProp`
120
+ ```html
121
+ <ProForm :form="form">
122
+ <template #city="scoped"><CustomPicker v-bind="scoped" /></template>
123
+ </ProForm>
124
+ ```
27
125
 
28
- 内置组件:field, switch, stepper, rate, slider, uploader, checkbox-group, radio-group, picker, date-picker, time-picker, cascader, area, signature, button, custom
126
+ ### 3.4 Popup 弹窗模式
29
127
 
30
- ## 类型扩展
128
+ Field 配置 `popup: true` 时:表单项以只读 van-field 展示,点击后底部弹出 Popup,内部控件在 Popup 中渲染。确认提交值,取消丢弃修改。`displayFormatter` 控制只读展示文本。
31
129
 
32
- ```typescript
33
- declare module '@qin-ui/vant-pro' {
34
- interface ComponentMap {
35
- 'my-custom-component': typeof MyComponent;
36
- }
37
- }
130
+ ```ts
131
+ { path: 'city', component: 'picker', label: '城市', columns: ['北京','上海'], popup: true, displayFormatter: (v) => v || '请选择' }
38
132
  ```
133
+
134
+ ---
135
+
136
+ ## 4. 反模式
137
+
138
+ - **禁止手写 van-field**:所有表单项通过 Field 配置驱动,ProForm 自动渲染 van-field
139
+ - **禁止猜测属性名**:编写组件属性前必须查 [vant 文档](https://vant-ui.com/),vant 不使用 `allowClear`/`mode:'multiple'` 等第三方库命名
140
+ - **联动选简单方式**:初始化联动用 `computed()`,运行时用 `setField()`,避免过度设计
141
+
142
+ ---
143
+
144
+ ## 5. ProComponentProvider 全局默认配置
145
+
146
+ 通过 `ProComponentProvider` 在应用顶层统一配置默认属性,避免重复。属性优先级:Field 级别 > componentVars > INJECT_CONFIG 预设。
147
+
148
+ ### INJECT_CONFIG 预设默认值
149
+
150
+ | 组件 | 预设默认值 |
151
+ | :----------- | :----------------------------------------------------------------------------------------------------------------------------- |
152
+ | `pro-form` | `{ inputAlign: 'right', errorMessageAlign: 'right', required: 'auto', scrollToError: true, scrollToErrorPosition: 'nearest' }` |
153
+ | `field` | `{ clearable: true, placeholder: '请输入' }` |
154
+ | 其余所有组件 | `{}`(无预设,直接使用 vant 默认值) |
155
+
156
+ ### componentVars 额外配置键
157
+
158
+ `valueFormatter`, `displayFormatter`, `componentContainer`, `modelProp`, `popup` — 可通过 ProComponentProvider 全局统一配置。
159
+
160
+ ```vue
161
+ <ProComponentProvider
162
+ :component-vars="{
163
+ 'pro-form': { inputAlign: 'left' },
164
+ field: { clearable: false, placeholder: '请输入内容' },
165
+ switch: { activeColor: '#07c160' },
166
+ stepper: { integer: true, min: 0 },
167
+ }"
168
+ >
169
+ <ProForm :form="form" />
170
+ </ProComponentProvider>
171
+ ```
172
+
173
+ ---
174
+
175
+ ## 6. 关键参考文件
176
+
177
+ 1. **`node_modules/@qin-ui/vant-pro/api.json`** — 结构化 API 元数据(函数签名、类型定义、JSDoc)
178
+ 2. **`node_modules/@qin-ui/vant-pro/README.md`** — 完整使用文档和代码示例
179
+ 3. **`https://vant-ui.com/`** — vant v4 官方文档(确认组件属性时必查)
180
+ 4. 源码类型定义 — `src/components/form/types/index.ts`(Field 类型)、`src/components/form/constants/index.ts`(componentMap)、`src/components/component-provider/constants/index.ts`(INJECT_CONFIG)
package/LICENSE ADDED
@@ -0,0 +1,9 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2023-present pro-components
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
6
+
7
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
8
+
9
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
package/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # @qin-ui/vant-pro
2
2
 
3
- > 基于 **Vant 4** 和 **@qin-ui/core** 二次封装的移动端高级表单组件库,专门针对移动端 H5 精细化打造,助您极速构建交互流畅、配置驱动的移动端表单应用。
3
+ > 基于 **Vant 4** 和 **@qin-ui/pro-components-core** 二次封装的移动端高级表单组件库,专门针对移动端 H5 精细化打造,助您极速构建交互流畅、配置驱动的移动端表单应用。
4
4
 
5
5
  <p align="center">
6
6
  <img src="https://img.shields.io/badge/Vant-4.x-blue" alt="Vant 4.x" />
package/api.json CHANGED
@@ -1,5 +1,5 @@
1
1
  {
2
- "generatedAt": "2026-05-26T08:42:45.735Z",
2
+ "generatedAt": "2026-07-09T04:30:07.554Z",
3
3
  "name": "@qin-ui/vant-pro",
4
4
  "api": [
5
5
  {
@@ -12,25 +12,25 @@
12
12
  "```vue\n<ProComponentProvider\n:componentVars=\"{ 'field': { placeholder: '请输入' } }\"\n>\n<ProForm :form=\"form\" :fields=\"fields\" />\n</ProComponentProvider>\n```"
13
13
  ]
14
14
  },
15
+ {
16
+ "name": "ContainerFragment",
17
+ "type": "component",
18
+ "package": "@qin-ui/vant-pro",
19
+ "signature": "<ContainerFragment>",
20
+ "description": "容器分片渲染组件。用于动态渲染表单行或表单项的外部包裹容器(例如 Grid 行、Col 列等布局容器)。"
21
+ },
15
22
  {
16
23
  "name": "ProForm",
17
24
  "type": "component",
18
25
  "package": "@qin-ui/vant-pro",
19
26
  "signature": "<ProForm>",
20
- "description": "@qin-ui/vant-pro 配置驱动表单组件(移动端)\n通过配置驱动的方式快速构建移动端表单,支持:\n- 字段联动、嵌套字段、自定义组件\n- 弹出层表单(Popup,适用于移动端选择器场景)",
27
+ "description": "@qin-ui/vant-pro 配置驱动表单组件(移动端)\n架构设计说明 (Architecture Overview)\n[ 数据层 (Core) ] => [ 绑定层 (ProForm) ] => [ 渲染层 (BaseFormItem / BaseField) ]\n1. 数据隔离:ProForm 本身不负责存储和管理表单状态,所有核心状态(formData, fields, 校验规则)\n均交由底层的 `useForm`(@qin-ui/pro-components-core)驱动。\n2. 上下文透传:通过 `provide` 将核心状态下发给子组件,避免了深层嵌套的 Props 传递。\n3. 递归渲染:具体字段的解析交由 `<BaseFormItem>` 递归完成,实现了 UI 布局与表单逻辑的解耦。\n通过配置驱动的方式快速构建移动端表单,支持:\n- 字段联动、嵌套字段、自定义组件\n- 弹出层表单(Popup,适用于移动端选择器场景)",
21
28
  "typeParams": [
22
29
  {
23
30
  "name": "F"
24
31
  }
25
32
  ]
26
33
  },
27
- {
28
- "name": "ContainerFragment",
29
- "type": "component",
30
- "package": "@qin-ui/vant-pro",
31
- "signature": "<ContainerFragment>",
32
- "description": "容器分片渲染组件。用于动态渲染表单行或表单项的外部包裹容器(例如 Grid 行、Col 列等布局容器)。"
33
- },
34
34
  {
35
35
  "name": "SlotComponent",
36
36
  "type": "component",
@@ -59,9 +59,9 @@
59
59
  "name": "useFormData",
60
60
  "type": "function",
61
61
  "package": "@qin-ui/vant-pro",
62
- "signature": "export const useFormData = <D extends Data = Data>(\n initFormData?: ExtendWithAny<DeepPartial<D>>\n) =>",
62
+ "signature": "export const useFormData = <D extends Data = Data>(\n initFormData?: ExtendWithAny<DeepPartial<D>>\n): UseFormDataReturn<D> =>",
63
63
  "description": "表单数据处理 Hook\n提供响应式表单数据的管理能力,支持:\n- 响应式数据存储(基于 Vue reactive)\n- 深层路径读写(支持点号分隔,如 'address.city')\n- 类型安全的路径提示(传入泛型 D 后,path 参数可获得类型推导)\n- 父子表单自动注入(非根表单会从注入中获取数据)",
64
- "returns": "{Function} .setFormData(path, value) - 设置指定路径的数据",
64
+ "returns": "{UseFormDataReturn<D>} 表单数据操作对象",
65
65
  "typeParams": [
66
66
  {
67
67
  "name": "D"
@@ -75,15 +75,16 @@
75
75
  "name": "useFields",
76
76
  "type": "function",
77
77
  "package": "@qin-ui/vant-pro",
78
- "signature": "export const useFields = _useFields as",
79
- "description": "类型安全的 re-export。将 core useFields 的泛型参数绑定为本地类型:\n- 字段类型 F Field<ComponentName, D>(支持 Vant 组件类型推导)\n- Field 实例 Vant 的 FieldInstance",
78
+ "signature": "export function useFields<D extends Data = Data>(\n initFields?: Fields<D>\n): UseFieldsReturn<D, Field<ComponentName, D>, FieldInstance>;",
79
+ "description": "字段配置管理 Hook\n基于 `@qin-ui/pro-components-core` 的 `useFields`,将泛型参数绑定为 Vant 的本地类型:\n- 字段类型 F -> `Field<ComponentName, D>`(支持 Vant 组件类型推导)\n- Field 实例 -> Vant 的 `FieldInstance`\n提供对字段配置数组的增删改查操作,支持:\n- 通过路径字符串或查找函数定位字段\n- 深层嵌套字段的遍历和匹配\n- 字段配置的合并/覆盖更新\n- 字段的添加、插入、删除\n- 父级字段查找\n- `fields` - 字段配置数组(响应式 Ref\\<F[]\\>)\n- `getField(path)` - 获取字段配置,支持路径字符串或查找函数\n- `setField(path, field, options?)` - 更新字段配置,默认合并模式\n- `deleteField(path, options?)` - 删除字段配置\n- `appendField(path, field, options?)` - 在指定字段后追加\n- `prependField(path, field, options?)` - 在指定字段前插入\n- `getParentField(path, options?)` - 获取父级字段配置",
80
+ "returns": "字段操作对象,包含以下属性:",
80
81
  "typeParams": [
81
82
  {
82
83
  "name": "D"
83
84
  }
84
85
  ],
85
86
  "examples": [
86
- "```ts\ninterface User { name: string; age: number }\n\nconst { fields, getField, setField } = useFields<User>([\n{ path: 'name', label: '姓名', component: 'field' },\n{ path: 'age', label: '年龄', component: 'stepper' },\n])\n```"
87
+ "```ts\ninterface User { name: string; age: number }\n\nconst { fields, getField, setField } = useFields<User>([\n{ path: 'name', label: '姓名', component: 'field' },\n{ path: 'age', label: '年龄', component: 'stepper' },\n])\n\n// 通过路径获取\ngetField('name')\n// 通过查找函数获取\ngetField(f => f.label === '姓名')\n// 更新字段(合并模式)\nsetField('name', { label: '用户名', disabled: true })\n```"
87
88
  ]
88
89
  },
89
90
  {
@@ -91,14 +92,14 @@
91
92
  "type": "type",
92
93
  "package": "@qin-ui/vant-pro",
93
94
  "signature": "export type UseFields<D extends Data = Data> = ReturnType<typeof useFields<D>>;",
94
- "description": "useFields 返回值类型,固定为本地 Fields<D>"
95
+ "description": "useFields 返回值类型"
95
96
  },
96
97
  {
97
98
  "name": "Form",
98
99
  "type": "type",
99
100
  "package": "@qin-ui/vant-pro",
100
101
  "signature": "export type Form<\n D extends Data = Data,\n F extends Field<ComponentName, D> = Field<ComponentName, D>,\n> = _Form<D, F, FormInstance> & { formPopup: FormPopup };",
101
- "description": "在 core Form 类型的基础上:\n1. 将字段类型 F 绑定为本地 Field<ComponentName, D>\n2. 将底层表单实例绑定为 Vant 的 FormInstance\n3. 额外包含 formPopup 对象,用于管理弹出层表单",
102
+ "description": "表单实例类型\n在 core Form 类型的基础上,将字段类型 F 绑定为本地 Field<ComponentName, D>,\n将底层表单实例 I 绑定为 Vant 的 FormInstance,使 formRef 获得完整的类型提示。\n额外包含 formPopup 对象,用于管理弹出层表单。\n1. `setFormData(path, value)` - 设置指定路径的值<br>\n2. `setFormData(path, prev => newVal)` - 函数式更新<br>\n3. `setFormData({ ... })` - 批量覆盖整个表单",
102
103
  "typeParams": [
103
104
  {
104
105
  "name": "D"
@@ -106,6 +107,9 @@
106
107
  {
107
108
  "name": "F"
108
109
  }
110
+ ],
111
+ "examples": [
112
+ "```ts\ninterface User { name: string; age: number }\nconst form: Form<User> = useForm({ name: '张三', age: 25 })\n\nform.formData.name // 直接读写响应式数据\nform.getFormData('name') // 通过路径读取\nform.setFormData('name', '李四') // 更新数据\nform.formRef.value?.validate() // 访问底层 Form 实例\nform.formPopup.open('address') // 打开弹出层表单\n```"
109
113
  ]
110
114
  },
111
115
  {
@@ -113,14 +117,15 @@
113
117
  "type": "function",
114
118
  "package": "@qin-ui/vant-pro",
115
119
  "signature": "export function useForm<D extends Data = Data>(\n initFormData?: ExtendWithAny<DeepPartial<D>>,\n initFields?: Field<ComponentName, D>[],\n root?: boolean\n): Form<D, Field<ComponentName, D>>;",
116
- "description": "创建 @qin-ui/vant-pro 表单实例的 Hook\n基于 core useForm 封装,额外提供了 formPopup 用于移动端弹窗表单。",
120
+ "description": "创建表单实例的 Hook\n基于 `@qin-ui/pro-components-core` `useForm`,将泛型参数绑定为 Vant 的本地类型:\n- 字段类型 F -> `Field<ComponentName, D>`(支持 Vant 组件类型推导)\n- 表单实例 -> Vant 的 `FormInstance`(使 formRef 获得完整的类型提示)\n在 core useForm 基础上额外提供 formPopup,用于移动端弹窗表单场景。\n表单实例组合了四个子模块的能力:\n- **useFormData**:表单数据管理(响应式数据、读写、批量更新)\n- **useFields**:字段配置管理(增删改查字段配置,支持嵌套)\n- **useFormRef**:底层 Form 组件实例引用\n- **useFormPopup**:弹出层表单管理(Vant 专属)",
121
+ "returns": "{Form<D>} 表单实例,包含数据操作、字段操作、ref 操作和弹出层管理",
117
122
  "typeParams": [
118
123
  {
119
124
  "name": "D"
120
125
  }
121
126
  ],
122
127
  "examples": [
123
- "```ts\ninterface User { name: string; age: number }\n\nconst form = useForm<User>(\n{ name: '张三' },\n[\n{ path: 'name', label: '姓名', component: 'field' },\n]\n)\n\n// 打开弹出层表单\nform.formPopup.open('address')\nform.formPopup.close()\n```"
128
+ "```ts\ninterface User { name: string; age: number }\n\n// 方式一:同时传入初始数据和字段\nconst form = useForm<User>(\n{ name: '张三', age: 25 },\n[\n{ path: 'name', label: '姓名', component: 'field' },\n],\ntrue\n)\n\n// 方式二:仅设置 root 标识\nconst form = useForm<User>(true)\n\n// 使用\nconst { formData, formRef, fields, setFormData, formPopup } = form\nsetFormData('name', '李四')\nformPopup.open('address') // 打开弹出层表单\n```"
124
129
  ]
125
130
  },
126
131
  {
@@ -152,11 +157,11 @@
152
157
  "name": "useFormRef",
153
158
  "type": "function",
154
159
  "package": "@qin-ui/vant-pro",
155
- "signature": "export const useFormRef = _useFormRef as",
156
- "description": "类型安全的 re-export。将 core useFormRef 的泛型参数绑定为 Vant 的 FormInstance",
157
- "returns": "{Function} .setFormRef(inst) - 设置表单组件实例",
160
+ "signature": "export function useFormRef(): UseFormRefReturn<FormInstance>",
161
+ "description": "表单组件实例引用 Hook\n基于 `@qin-ui/pro-components-core` 的 `useFormRef`,将泛型参数绑定为 Vant 的 `FormInstance`,\n使 formRef 获取到完整的 Vant Form 组件 API 类型提示(如 `validate()`、`resetValidation()` 等)。\n`formRef` 由 ProForm 组件内部自动通过 `setFormRef` 绑定,无需手动调用。\n- `formRef` — Vant Form 组件实例的响应式引用(`Ref<FormInstance | undefined>`)\n- `setFormRef(inst)` — 设置 Form 组件实例,由 ProForm 内部自动调用",
162
+ "returns": "表单组件实例引用管理对象:",
158
163
  "examples": [
159
- "```ts\nconst { formRef, setFormRef } = useFormRef()\nformRef.value?.submit()\n```"
164
+ "```ts\nconst { formRef, setFormRef } = useFormRef()\n\n// formRef 由 ProForm 自动绑定,可直接使用\nawait formRef.value?.validate()\nformRef.value?.resetValidation()\nformRef.value?.scrollToField('username')\n```"
160
165
  ]
161
166
  }
162
167
  ]