jianghu-ui 1.0.5 → 1.0.7
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/dist/jianghu-ui.css +186 -115
- package/dist/jianghu-ui.js +1 -1
- package/package.json +1 -1
- package/src/components/JhAddressSelect/JhAddressSelect.vue +6 -6
- package/src/components/JhDrawer/JhDrawer.stories.js +6 -6
- package/src/components/JhDrawerForm/JhDrawerForm.vue +1 -1
- package/src/components/JhForm/JhForm.stories.js +114 -95
- package/src/components/JhForm/JhForm.vue +148 -21
- package/src/components/JhFormFields/JhFormFields.vue +33 -14
- package/src/components/JhModal/JhModal.stories.js +6 -6
- package/src/components/JhModal/JhModal.vue +1 -1
- package/src/components/JhModalForm/JhModalForm.vue +1 -1
- package/src/components/JhTable/JhTable.stories.js +192 -154
- package/src/components/JhTable/JhTable.vue +122 -26
- package/src/style/globalCSSVuetifyV4.css +1 -2
- package/src/components/JhAddressSelect/JhAddressSelect.md +0 -267
- package/src/components/JhCard/JhCard.md +0 -246
- package/src/components/JhCheckCard/JhCheckCard.md +0 -245
- package/src/components/JhConfirmDialog/JhConfirmDialog.md +0 -70
- package/src/components/JhDateRangePicker/JhDateRangePicker.md +0 -56
- package/src/components/JhDescriptions/JhDescriptions.md +0 -724
- package/src/components/JhDraggable/JhDraggable.md +0 -66
- package/src/components/JhDrawer/JhDrawer.md +0 -68
- package/src/components/JhDrawerForm/JhDrawerForm.md +0 -69
- package/src/components/JhEditableTable/JhEditableTable.md +0 -507
- package/src/components/JhFileInput/JhFileInput.md +0 -56
- package/src/components/JhForm/JhForm.md +0 -676
- package/src/components/JhFormFields/JhFormFields.md +0 -647
- package/src/components/JhFormList/JhFormList.md +0 -303
- package/src/components/JhJsonEditor/JhJsonEditor.md +0 -54
- package/src/components/JhLayout/JhLayout.md +0 -580
- package/src/components/JhList/JhList.md +0 -441
- package/src/components/JhMarkdownEditor/JhMarkdownEditor.md +0 -56
- package/src/components/JhMask/JhMask.md +0 -62
- package/src/components/JhMenu/JhMenu.md +0 -85
- package/src/components/JhModal/JhModal.md +0 -68
- package/src/components/JhModalForm/JhModalForm.md +0 -69
- package/src/components/JhPageContainer/JhPageContainer.md +0 -409
- package/src/components/JhQueryFilter/JhQueryFilter.md +0 -77
- package/src/components/JhScene/JhScene.md +0 -64
- package/src/components/JhStatisticCard/JhStatisticCard.md +0 -363
- package/src/components/JhStepsForm/JhStepsForm.md +0 -666
- package/src/components/JhTable/JhTable.md +0 -730
- package/src/components/JhTableAttachment/JhTableAttachment.md +0 -70
- package/src/components/JhToast/JhToast.md +0 -67
- package/src/components/JhTreeSelect/JhTreeSelect.md +0 -82
- package/src/components/JhWaterMark/JhWaterMark.md +0 -190
- package/src/components/README.md +0 -52
|
@@ -1,676 +0,0 @@
|
|
|
1
|
-
# JhForm - 高级表单组件
|
|
2
|
-
|
|
3
|
-
JhForm 是一个功能强大的表单组件,参考 Ant Design ProComponents Form 设计,在 Vuetify 的基础上增加了更多语法糖和布局设置,帮助快速开发表单。
|
|
4
|
-
|
|
5
|
-
## ✨ 特性
|
|
6
|
-
|
|
7
|
-
- 🎯 **多种字段类型** - 支持 text、textarea、number、select、autocomplete、date、time、switch、checkbox、radio 等
|
|
8
|
-
- 📐 **灵活布局** - 支持 horizontal、vertical、inline、grid 四种布局模式
|
|
9
|
-
- 🔄 **字段联动** - 支持字段的显示/隐藏、启用/禁用联动
|
|
10
|
-
- 📦 **字段分组** - 支持表单字段分组展示
|
|
11
|
-
- ✅ **表单验证** - 内置常用验证规则,支持自定义验证
|
|
12
|
-
- 🎨 **样式定制** - 支持 filled、outlined、dense 等多种样式
|
|
13
|
-
- 📱 **响应式** - 支持响应式栅格布局
|
|
14
|
-
- 🔧 **数据转换** - 支持提交时数据转换(transform)
|
|
15
|
-
- 💡 **提示信息** - 支持 tooltip 和 extra 额外提示
|
|
16
|
-
- 🎭 **只读模式** - 支持表单只读展示
|
|
17
|
-
|
|
18
|
-
## 📦 安装
|
|
19
|
-
|
|
20
|
-
```javascript
|
|
21
|
-
import JhForm from '@/components/JhForm/JhForm.vue';
|
|
22
|
-
```
|
|
23
|
-
|
|
24
|
-
## 🔨 基础用法
|
|
25
|
-
|
|
26
|
-
### 简单示例
|
|
27
|
-
|
|
28
|
-
```vue
|
|
29
|
-
<template>
|
|
30
|
-
<JhForm
|
|
31
|
-
:fields="fields"
|
|
32
|
-
:initialData="formData"
|
|
33
|
-
@submit="handleSubmit"
|
|
34
|
-
>
|
|
35
|
-
<template #actions="{ validate, resetForm }">
|
|
36
|
-
<v-btn @click="resetForm">重置</v-btn>
|
|
37
|
-
<v-btn color="primary" @click="validate">提交</v-btn>
|
|
38
|
-
</template>
|
|
39
|
-
</JhForm>
|
|
40
|
-
</template>
|
|
41
|
-
|
|
42
|
-
<script>
|
|
43
|
-
export default {
|
|
44
|
-
data() {
|
|
45
|
-
return {
|
|
46
|
-
fields: [
|
|
47
|
-
{
|
|
48
|
-
key: 'username',
|
|
49
|
-
label: '用户名',
|
|
50
|
-
type: 'text',
|
|
51
|
-
placeholder: '请输入用户名',
|
|
52
|
-
required: true,
|
|
53
|
-
},
|
|
54
|
-
{
|
|
55
|
-
key: 'email',
|
|
56
|
-
label: '邮箱',
|
|
57
|
-
type: 'text',
|
|
58
|
-
placeholder: '请输入邮箱',
|
|
59
|
-
rules: 'email',
|
|
60
|
-
},
|
|
61
|
-
],
|
|
62
|
-
formData: {
|
|
63
|
-
username: '',
|
|
64
|
-
email: '',
|
|
65
|
-
},
|
|
66
|
-
};
|
|
67
|
-
},
|
|
68
|
-
methods: {
|
|
69
|
-
handleSubmit(data) {
|
|
70
|
-
console.log('提交数据:', data);
|
|
71
|
-
},
|
|
72
|
-
},
|
|
73
|
-
};
|
|
74
|
-
</script>
|
|
75
|
-
```
|
|
76
|
-
|
|
77
|
-
## 📋 API
|
|
78
|
-
|
|
79
|
-
### Props
|
|
80
|
-
|
|
81
|
-
| 参数 | 说明 | 类型 | 默认值 |
|
|
82
|
-
|------|------|------|--------|
|
|
83
|
-
| fields | 表单字段配置数组 | `Array<FieldConfig>` | `[]` |
|
|
84
|
-
| initialData | 初始表单数据 | `Object` | `{}` |
|
|
85
|
-
| layout | 表单布局模式 | `'horizontal' \| 'vertical' \| 'inline' \| 'grid'` | `'vertical'` |
|
|
86
|
-
| showLabels | 是否显示标签 | `Boolean` | `true` |
|
|
87
|
-
| labelWidth | 标签宽度(horizontal 布局) | `Number \| String` | `'auto'` |
|
|
88
|
-
| labelAlign | 标签对齐方式 | `'left' \| 'right' \| 'center'` | `'right'` |
|
|
89
|
-
| showRequiredMark | 是否显示必填标记 | `Boolean` | `true` |
|
|
90
|
-
| readonly | 只读模式 | `Boolean` | `false` |
|
|
91
|
-
| disabled | 禁用模式 | `Boolean` | `false` |
|
|
92
|
-
| defaultDense | 默认紧凑模式 | `Boolean` | `true` |
|
|
93
|
-
| defaultFilled | 默认填充样式 | `Boolean` | `true` |
|
|
94
|
-
| defaultOutlined | 默认轮廓样式 | `Boolean` | `false` |
|
|
95
|
-
| defaultColsMd | 默认列宽(md 断点) | `Number` | `6` |
|
|
96
|
-
| hideDetails | 隐藏详情信息 | `Boolean \| String` | `false` |
|
|
97
|
-
| onFinish | 提交成功回调 | `Function` | - |
|
|
98
|
-
| onFinishFailed | 提交失败回调 | `Function` | - |
|
|
99
|
-
| omitNil | 忽略 null/undefined 值 | `Boolean` | `true` |
|
|
100
|
-
| grid | Grid 模式 | `Boolean` | `false` |
|
|
101
|
-
| colProps | Grid 列配置 | `Object` | `{}` |
|
|
102
|
-
| rowProps | Grid 行配置(透传 `v-row`) | `Object` | `{}` |
|
|
103
|
-
|
|
104
|
-
### FieldConfig 字段配置
|
|
105
|
-
|
|
106
|
-
| 参数 | 说明 | 类型 | 默认值 |
|
|
107
|
-
|------|------|------|--------|
|
|
108
|
-
| key | 字段唯一标识 | `String` | - |
|
|
109
|
-
| label | 字段标签 | `String` | - |
|
|
110
|
-
| type | 字段类型 | `String` | `'text'` |
|
|
111
|
-
| placeholder | 占位符 | `String` | - |
|
|
112
|
-
| required | 是否必填 | `Boolean` | `false` |
|
|
113
|
-
| rules | 验证规则 | `Array \| String` | - |
|
|
114
|
-
| defaultValue | 默认值 | `Any` | - |
|
|
115
|
-
| cols | 响应式列宽配置 | `Number \| Object` | - |
|
|
116
|
-
| colSpan | Grid 模式 24 栏列宽 | `Number` | - |
|
|
117
|
-
| colProps | 字段级列配置(优先级高于全局) | `Object` | - |
|
|
118
|
-
| visible | 是否可见 | `Boolean \| Function` | `true` |
|
|
119
|
-
| disabled | 是否禁用 | `Boolean \| Function` | `false` |
|
|
120
|
-
| readonly | 是否只读 | `Boolean \| Function` | `false` |
|
|
121
|
-
| tooltip | 提示信息 | `String` | - |
|
|
122
|
-
| extra | 额外提示信息 | `String` | - |
|
|
123
|
-
| transform | 提交时数据转换函数 | `Function` | - |
|
|
124
|
-
| dependencies | 依赖字段数组 | `Array<String>` | - |
|
|
125
|
-
| layout | 字段布局(覆盖全局) | `String` | - |
|
|
126
|
-
| labelWidth | 标签宽度(覆盖全局) | `Number \| String` | - |
|
|
127
|
-
| labelAlign | 标签对齐(覆盖全局) | `String` | - |
|
|
128
|
-
|
|
129
|
-
### 字段类型 (type)
|
|
130
|
-
|
|
131
|
-
- **text** - 文本输入框
|
|
132
|
-
- **textarea** - 文本域
|
|
133
|
-
- **number** - 数字输入框
|
|
134
|
-
- **select** - 下拉选择框
|
|
135
|
-
- **autocomplete** - 自动完成
|
|
136
|
-
- **date** - 日期选择器
|
|
137
|
-
- **time** - 时间选择器
|
|
138
|
-
- **switch** - 开关
|
|
139
|
-
- **checkbox** - 复选框
|
|
140
|
-
- **radio** - 单选按钮组
|
|
141
|
-
- **slot** - 自定义插槽
|
|
142
|
-
- **group** - 分组标题
|
|
143
|
-
|
|
144
|
-
### Events
|
|
145
|
-
|
|
146
|
-
| 事件名 | 说明 | 回调参数 |
|
|
147
|
-
|--------|------|----------|
|
|
148
|
-
| submit | 表单提交 | `(data: Object)` |
|
|
149
|
-
| reset | 表单重置 | `(data: Object)` |
|
|
150
|
-
| validate | 表单验证 | `(isValid: Boolean, data: Object)` |
|
|
151
|
-
| input | 字段输入 | `(key: String, value: Any, formData: Object)` |
|
|
152
|
-
| change | 字段改变 | `(key: String, value: Any, formData: Object)` |
|
|
153
|
-
| blur | 字段失焦 | `(key: String, value: Any, formData: Object)` |
|
|
154
|
-
| field-change | 字段变化(统一事件) | `{ key, value, formData }` |
|
|
155
|
-
|
|
156
|
-
### Methods
|
|
157
|
-
|
|
158
|
-
| 方法名 | 说明 | 参数 | 返回值 |
|
|
159
|
-
|--------|------|------|--------|
|
|
160
|
-
| getFormData | 获取表单数据 | - | `Object` |
|
|
161
|
-
| setFieldsValue | 设置多个字段值 | `(values: Object)` | - |
|
|
162
|
-
| setFieldValue | 设置单个字段值 | `(key: String, value: Any)` | - |
|
|
163
|
-
| validate | 验证表单 | - | `Promise<Boolean>` |
|
|
164
|
-
| resetForm | 重置表单 | - | - |
|
|
165
|
-
| resetValidation | 重置验证 | - | - |
|
|
166
|
-
| submit | 提交表单 | - | `Promise<Boolean>` |
|
|
167
|
-
| getTransformedData | 获取转换后的数据 | - | `Object` |
|
|
168
|
-
|
|
169
|
-
### Slots
|
|
170
|
-
|
|
171
|
-
| 插槽名 | 说明 | 参数 |
|
|
172
|
-
|--------|------|------|
|
|
173
|
-
| actions | 表单操作区域 | `{ formData, validate, resetForm }` |
|
|
174
|
-
| field-{key} | 自定义字段(type='slot') | `{ field, formData, updateField }` |
|
|
175
|
-
|
|
176
|
-
## 🎯 使用示例
|
|
177
|
-
|
|
178
|
-
### 1. 水平布局
|
|
179
|
-
|
|
180
|
-
```vue
|
|
181
|
-
<JhForm
|
|
182
|
-
:fields="fields"
|
|
183
|
-
layout="horizontal"
|
|
184
|
-
labelWidth="120"
|
|
185
|
-
labelAlign="right"
|
|
186
|
-
/>
|
|
187
|
-
```
|
|
188
|
-
|
|
189
|
-
### 2. 行内布局(搜索表单)
|
|
190
|
-
|
|
191
|
-
```vue
|
|
192
|
-
<JhForm
|
|
193
|
-
:fields="searchFields"
|
|
194
|
-
layout="inline"
|
|
195
|
-
>
|
|
196
|
-
<template #actions="{ validate, resetForm }">
|
|
197
|
-
<v-btn color="primary" @click="validate">查询</v-btn>
|
|
198
|
-
<v-btn text @click="resetForm">重置</v-btn>
|
|
199
|
-
</template>
|
|
200
|
-
</JhForm>
|
|
201
|
-
```
|
|
202
|
-
|
|
203
|
-
### Grid 栅格布局
|
|
204
|
-
```vue
|
|
205
|
-
<JhForm
|
|
206
|
-
layout="grid"
|
|
207
|
-
:grid="true"
|
|
208
|
-
:col-props="{ span: 8, lg: 6 }"
|
|
209
|
-
:row-props="{ dense: true }"
|
|
210
|
-
:fields="[
|
|
211
|
-
{ type: 'group', title: '项目信息' },
|
|
212
|
-
{ key: 'projectCode', label: '编号', type: 'text', colSpan: 6 },
|
|
213
|
-
{ key: 'projectName', label: '名称', type: 'text', colSpan: 12 },
|
|
214
|
-
{ key: 'owner', label: '负责人', type: 'text' },
|
|
215
|
-
{ key: 'status', label: '状态', type: 'select', colProps: { md: 3 }, options: statusOptions }
|
|
216
|
-
]"
|
|
217
|
-
>
|
|
218
|
-
<template #actions="{ validate, resetForm }">
|
|
219
|
-
<v-btn text @click="resetForm">重置</v-btn>
|
|
220
|
-
<v-btn color="primary" @click="validate">提交</v-btn>
|
|
221
|
-
</template>
|
|
222
|
-
</JhForm>
|
|
223
|
-
```
|
|
224
|
-
- `colSpan` 采用 24 栏语义(8=三等分、12=半行),JhForm 会自动映射到 Vuetify 12 栅格。
|
|
225
|
-
- `colProps` 与 `rowProps` 可继续覆盖断点与 `v-row` 属性,actions 会在 Grid 模式下占满最后一行保持对齐。
|
|
226
|
-
|
|
227
|
-
### 3. 字段分组
|
|
228
|
-
|
|
229
|
-
```javascript
|
|
230
|
-
fields: [
|
|
231
|
-
{ type: 'group', title: '基本信息', divider: false },
|
|
232
|
-
{ key: 'username', label: '用户名', type: 'text' },
|
|
233
|
-
{ key: 'email', label: '邮箱', type: 'text' },
|
|
234
|
-
|
|
235
|
-
{ type: 'group', title: '账户设置', divider: true, description: '设置账户相关信息' },
|
|
236
|
-
{ key: 'role', label: '角色', type: 'select', options: [...] },
|
|
237
|
-
]
|
|
238
|
-
```
|
|
239
|
-
|
|
240
|
-
### 4. 字段联动
|
|
241
|
-
|
|
242
|
-
```javascript
|
|
243
|
-
fields: [
|
|
244
|
-
{
|
|
245
|
-
key: 'userType',
|
|
246
|
-
label: '用户类型',
|
|
247
|
-
type: 'radio',
|
|
248
|
-
options: [
|
|
249
|
-
{ text: '个人用户', value: 'personal' },
|
|
250
|
-
{ text: '企业用户', value: 'company' },
|
|
251
|
-
],
|
|
252
|
-
},
|
|
253
|
-
{
|
|
254
|
-
key: 'personalName',
|
|
255
|
-
label: '姓名',
|
|
256
|
-
type: 'text',
|
|
257
|
-
// 根据 userType 动态显示
|
|
258
|
-
visible: (formData) => formData.userType === 'personal',
|
|
259
|
-
},
|
|
260
|
-
{
|
|
261
|
-
key: 'companyName',
|
|
262
|
-
label: '公司名称',
|
|
263
|
-
type: 'text',
|
|
264
|
-
visible: (formData) => formData.userType === 'company',
|
|
265
|
-
},
|
|
266
|
-
{
|
|
267
|
-
key: 'remarks',
|
|
268
|
-
label: '备注',
|
|
269
|
-
type: 'textarea',
|
|
270
|
-
// 根据条件动态禁用
|
|
271
|
-
disabled: (formData) => !formData.agreeTerms,
|
|
272
|
-
},
|
|
273
|
-
]
|
|
274
|
-
```
|
|
275
|
-
|
|
276
|
-
### 5. 数据转换
|
|
277
|
-
|
|
278
|
-
```javascript
|
|
279
|
-
fields: [
|
|
280
|
-
{
|
|
281
|
-
key: 'price',
|
|
282
|
-
label: '价格',
|
|
283
|
-
type: 'number',
|
|
284
|
-
// 提交时转换为分
|
|
285
|
-
transform: (value) => value * 100,
|
|
286
|
-
},
|
|
287
|
-
{
|
|
288
|
-
key: 'tags',
|
|
289
|
-
label: '标签',
|
|
290
|
-
type: 'select',
|
|
291
|
-
multiple: true,
|
|
292
|
-
// 提交时转换为逗号分隔的字符串
|
|
293
|
-
transform: (value) => Array.isArray(value) ? value.join(',') : value,
|
|
294
|
-
},
|
|
295
|
-
]
|
|
296
|
-
```
|
|
297
|
-
|
|
298
|
-
### 6. 提示信息
|
|
299
|
-
|
|
300
|
-
```javascript
|
|
301
|
-
fields: [
|
|
302
|
-
{
|
|
303
|
-
key: 'password',
|
|
304
|
-
label: '密码',
|
|
305
|
-
type: 'text',
|
|
306
|
-
tooltip: '密码长度至少8位,包含字母和数字',
|
|
307
|
-
extra: '建议使用强密码以保护账户安全',
|
|
308
|
-
props: { type: 'password' },
|
|
309
|
-
},
|
|
310
|
-
]
|
|
311
|
-
```
|
|
312
|
-
|
|
313
|
-
### 7. 响应式布局
|
|
314
|
-
|
|
315
|
-
```javascript
|
|
316
|
-
fields: [
|
|
317
|
-
{
|
|
318
|
-
key: 'field1',
|
|
319
|
-
label: '字段1',
|
|
320
|
-
type: 'text',
|
|
321
|
-
cols: {
|
|
322
|
-
xs: 12, // 手机端全宽
|
|
323
|
-
sm: 6, // 平板端半宽
|
|
324
|
-
md: 4, // 桌面端1/3宽
|
|
325
|
-
lg: 3, // 大屏1/4宽
|
|
326
|
-
},
|
|
327
|
-
},
|
|
328
|
-
]
|
|
329
|
-
```
|
|
330
|
-
|
|
331
|
-
### 8. 自定义字段
|
|
332
|
-
|
|
333
|
-
```vue
|
|
334
|
-
<JhForm :fields="fields">
|
|
335
|
-
<template #field-customField="{ field, formData, updateField }">
|
|
336
|
-
<v-slider
|
|
337
|
-
:value="formData[field.key]"
|
|
338
|
-
@input="updateField(field.key, $event)"
|
|
339
|
-
min="0"
|
|
340
|
-
max="100"
|
|
341
|
-
/>
|
|
342
|
-
</template>
|
|
343
|
-
</JhForm>
|
|
344
|
-
```
|
|
345
|
-
|
|
346
|
-
```javascript
|
|
347
|
-
fields: [
|
|
348
|
-
{
|
|
349
|
-
key: 'customField',
|
|
350
|
-
label: '自定义字段',
|
|
351
|
-
type: 'slot',
|
|
352
|
-
},
|
|
353
|
-
]
|
|
354
|
-
```
|
|
355
|
-
|
|
356
|
-
### 9. 提交处理
|
|
357
|
-
|
|
358
|
-
```vue
|
|
359
|
-
<JhForm
|
|
360
|
-
:fields="fields"
|
|
361
|
-
:onFinish="handleFinish"
|
|
362
|
-
:onFinishFailed="handleFinishFailed"
|
|
363
|
-
:omitNil="true"
|
|
364
|
-
/>
|
|
365
|
-
```
|
|
366
|
-
|
|
367
|
-
```javascript
|
|
368
|
-
methods: {
|
|
369
|
-
async handleFinish(values) {
|
|
370
|
-
console.log('提交成功:', values);
|
|
371
|
-
// 调用 API
|
|
372
|
-
await this.$api.submit(values);
|
|
373
|
-
},
|
|
374
|
-
handleFinishFailed(values) {
|
|
375
|
-
console.log('验证失败:', values);
|
|
376
|
-
},
|
|
377
|
-
}
|
|
378
|
-
```
|
|
379
|
-
|
|
380
|
-
### 10. 只读模式
|
|
381
|
-
|
|
382
|
-
```vue
|
|
383
|
-
<JhForm
|
|
384
|
-
:fields="fields"
|
|
385
|
-
:initialData="userData"
|
|
386
|
-
readonly
|
|
387
|
-
/>
|
|
388
|
-
```
|
|
389
|
-
|
|
390
|
-
## 🎨 样式定制
|
|
391
|
-
|
|
392
|
-
### 全局样式
|
|
393
|
-
|
|
394
|
-
```vue
|
|
395
|
-
<JhForm
|
|
396
|
-
:fields="fields"
|
|
397
|
-
defaultDense
|
|
398
|
-
defaultFilled
|
|
399
|
-
inputClass="custom-input"
|
|
400
|
-
labelClass="custom-label"
|
|
401
|
-
/>
|
|
402
|
-
```
|
|
403
|
-
|
|
404
|
-
### 字段级样式
|
|
405
|
-
|
|
406
|
-
```javascript
|
|
407
|
-
fields: [
|
|
408
|
-
{
|
|
409
|
-
key: 'field1',
|
|
410
|
-
label: '字段1',
|
|
411
|
-
type: 'text',
|
|
412
|
-
dense: false, // 覆盖全局 dense
|
|
413
|
-
filled: false, // 覆盖全局 filled
|
|
414
|
-
outlined: true, // 使用轮廓样式
|
|
415
|
-
colClass: 'px-2', // 自定义列样式
|
|
416
|
-
},
|
|
417
|
-
]
|
|
418
|
-
```
|
|
419
|
-
|
|
420
|
-
## 📝 验证规则
|
|
421
|
-
|
|
422
|
-
### 内置规则
|
|
423
|
-
|
|
424
|
-
- `require` - 必填
|
|
425
|
-
- `email` - 邮箱格式
|
|
426
|
-
- `phone` - 手机号格式
|
|
427
|
-
- `number` - 数字
|
|
428
|
-
- `integer` - 整数
|
|
429
|
-
|
|
430
|
-
### 使用方式
|
|
431
|
-
|
|
432
|
-
```javascript
|
|
433
|
-
// 方式1: 字符串(使用内置规则)
|
|
434
|
-
{ key: 'email', rules: 'email' }
|
|
435
|
-
|
|
436
|
-
// 方式2: 多个内置规则
|
|
437
|
-
{ key: 'field', rules: 'require|email' }
|
|
438
|
-
|
|
439
|
-
// 方式3: 数组(自定义规则)
|
|
440
|
-
{
|
|
441
|
-
key: 'age',
|
|
442
|
-
rules: [
|
|
443
|
-
v => !!v || '年龄必填',
|
|
444
|
-
v => v >= 18 || '年龄必须大于18岁',
|
|
445
|
-
],
|
|
446
|
-
}
|
|
447
|
-
|
|
448
|
-
// 方式4: required 快捷方式
|
|
449
|
-
{ key: 'username', required: true }
|
|
450
|
-
```
|
|
451
|
-
|
|
452
|
-
### 自定义验证规则集
|
|
453
|
-
|
|
454
|
-
```vue
|
|
455
|
-
<JhForm
|
|
456
|
-
:fields="fields"
|
|
457
|
-
:validationRules="customRules"
|
|
458
|
-
/>
|
|
459
|
-
```
|
|
460
|
-
|
|
461
|
-
```javascript
|
|
462
|
-
data() {
|
|
463
|
-
return {
|
|
464
|
-
customRules: {
|
|
465
|
-
require: [v => !!v || '必填'],
|
|
466
|
-
email: [v => !v || /.+@.+\..+/.test(v) || '邮箱格式不正确'],
|
|
467
|
-
idCard: [v => !v || /^\d{18}$/.test(v) || '身份证号格式不正确'],
|
|
468
|
-
},
|
|
469
|
-
};
|
|
470
|
-
}
|
|
471
|
-
```
|
|
472
|
-
|
|
473
|
-
## 🔧 高级特性
|
|
474
|
-
|
|
475
|
-
### 混合布局
|
|
476
|
-
|
|
477
|
-
可以为单个字段指定不同的布局:
|
|
478
|
-
|
|
479
|
-
```javascript
|
|
480
|
-
fields: [
|
|
481
|
-
{
|
|
482
|
-
key: 'title',
|
|
483
|
-
label: '标题',
|
|
484
|
-
type: 'text',
|
|
485
|
-
cols: { md: 12 },
|
|
486
|
-
},
|
|
487
|
-
{
|
|
488
|
-
key: 'category',
|
|
489
|
-
label: '分类',
|
|
490
|
-
type: 'select',
|
|
491
|
-
layout: 'horizontal', // 单独使用水平布局
|
|
492
|
-
labelWidth: 100,
|
|
493
|
-
cols: { md: 6 },
|
|
494
|
-
},
|
|
495
|
-
]
|
|
496
|
-
```
|
|
497
|
-
|
|
498
|
-
### 字段依赖
|
|
499
|
-
|
|
500
|
-
```javascript
|
|
501
|
-
fields: [
|
|
502
|
-
{
|
|
503
|
-
key: 'country',
|
|
504
|
-
label: '国家',
|
|
505
|
-
type: 'select',
|
|
506
|
-
options: [...],
|
|
507
|
-
},
|
|
508
|
-
{
|
|
509
|
-
key: 'province',
|
|
510
|
-
label: '省份',
|
|
511
|
-
type: 'select',
|
|
512
|
-
dependencies: ['country'], // 声明依赖
|
|
513
|
-
// options 可以根据 country 动态变化
|
|
514
|
-
},
|
|
515
|
-
]
|
|
516
|
-
```
|
|
517
|
-
|
|
518
|
-
## 📚 完整示例
|
|
519
|
-
|
|
520
|
-
```vue
|
|
521
|
-
<template>
|
|
522
|
-
<v-container>
|
|
523
|
-
<JhForm
|
|
524
|
-
ref="jhForm"
|
|
525
|
-
:fields="fields"
|
|
526
|
-
:initialData="formData"
|
|
527
|
-
layout="vertical"
|
|
528
|
-
:defaultColsMd="6"
|
|
529
|
-
:onFinish="handleSubmit"
|
|
530
|
-
:onFinishFailed="handleError"
|
|
531
|
-
@field-change="handleFieldChange"
|
|
532
|
-
>
|
|
533
|
-
<template #actions="{ validate, resetForm }">
|
|
534
|
-
<v-row class="mt-4">
|
|
535
|
-
<v-col cols="12" class="text-right">
|
|
536
|
-
<v-btn class="mr-2" @click="resetForm">重置</v-btn>
|
|
537
|
-
<v-btn color="success" @click="validate">提交</v-btn>
|
|
538
|
-
</v-col>
|
|
539
|
-
</v-row>
|
|
540
|
-
</template>
|
|
541
|
-
</JhForm>
|
|
542
|
-
</v-container>
|
|
543
|
-
</template>
|
|
544
|
-
|
|
545
|
-
<script>
|
|
546
|
-
import JhForm from '@/components/JhForm/JhForm.vue';
|
|
547
|
-
|
|
548
|
-
export default {
|
|
549
|
-
components: { JhForm },
|
|
550
|
-
|
|
551
|
-
data() {
|
|
552
|
-
return {
|
|
553
|
-
formData: {
|
|
554
|
-
userType: 'personal',
|
|
555
|
-
},
|
|
556
|
-
|
|
557
|
-
fields: [
|
|
558
|
-
// 基本信息分组
|
|
559
|
-
{ type: 'group', title: '基本信息' },
|
|
560
|
-
{
|
|
561
|
-
key: 'username',
|
|
562
|
-
label: '用户名',
|
|
563
|
-
type: 'text',
|
|
564
|
-
placeholder: '请输入用户名',
|
|
565
|
-
required: true,
|
|
566
|
-
tooltip: '用户名用于登录系统',
|
|
567
|
-
},
|
|
568
|
-
{
|
|
569
|
-
key: 'email',
|
|
570
|
-
label: '邮箱',
|
|
571
|
-
type: 'text',
|
|
572
|
-
placeholder: '请输入邮箱',
|
|
573
|
-
rules: 'email',
|
|
574
|
-
extra: '用于接收系统通知',
|
|
575
|
-
},
|
|
576
|
-
{
|
|
577
|
-
key: 'phone',
|
|
578
|
-
label: '手机号',
|
|
579
|
-
type: 'text',
|
|
580
|
-
placeholder: '请输入手机号',
|
|
581
|
-
rules: 'phone',
|
|
582
|
-
},
|
|
583
|
-
|
|
584
|
-
// 用户类型
|
|
585
|
-
{ type: 'group', title: '用户信息', divider: true },
|
|
586
|
-
{
|
|
587
|
-
key: 'userType',
|
|
588
|
-
label: '用户类型',
|
|
589
|
-
type: 'radio',
|
|
590
|
-
options: [
|
|
591
|
-
{ text: '个人用户', value: 'personal' },
|
|
592
|
-
{ text: '企业用户', value: 'company' },
|
|
593
|
-
],
|
|
594
|
-
defaultValue: 'personal',
|
|
595
|
-
cols: { md: 12 },
|
|
596
|
-
},
|
|
597
|
-
|
|
598
|
-
// 个人用户字段
|
|
599
|
-
{
|
|
600
|
-
key: 'realName',
|
|
601
|
-
label: '真实姓名',
|
|
602
|
-
type: 'text',
|
|
603
|
-
placeholder: '请输入真实姓名',
|
|
604
|
-
required: true,
|
|
605
|
-
visible: (formData) => formData.userType === 'personal',
|
|
606
|
-
},
|
|
607
|
-
|
|
608
|
-
// 企业用户字段
|
|
609
|
-
{
|
|
610
|
-
key: 'companyName',
|
|
611
|
-
label: '公司名称',
|
|
612
|
-
type: 'text',
|
|
613
|
-
placeholder: '请输入公司名称',
|
|
614
|
-
required: true,
|
|
615
|
-
visible: (formData) => formData.userType === 'company',
|
|
616
|
-
},
|
|
617
|
-
|
|
618
|
-
// 其他信息
|
|
619
|
-
{ type: 'group', title: '其他信息', divider: true },
|
|
620
|
-
{
|
|
621
|
-
key: 'bio',
|
|
622
|
-
label: '个人简介',
|
|
623
|
-
type: 'textarea',
|
|
624
|
-
placeholder: '请输入个人简介',
|
|
625
|
-
rows: 4,
|
|
626
|
-
cols: { md: 12 },
|
|
627
|
-
},
|
|
628
|
-
],
|
|
629
|
-
};
|
|
630
|
-
},
|
|
631
|
-
|
|
632
|
-
methods: {
|
|
633
|
-
async handleSubmit(values) {
|
|
634
|
-
console.log('提交数据:', values);
|
|
635
|
-
// 调用 API
|
|
636
|
-
try {
|
|
637
|
-
await this.$api.submitForm(values);
|
|
638
|
-
this.$message.success('提交成功');
|
|
639
|
-
} catch (error) {
|
|
640
|
-
this.$message.error('提交失败');
|
|
641
|
-
}
|
|
642
|
-
},
|
|
643
|
-
|
|
644
|
-
handleError(values) {
|
|
645
|
-
console.log('验证失败:', values);
|
|
646
|
-
this.$message.warning('请检查表单');
|
|
647
|
-
},
|
|
648
|
-
|
|
649
|
-
handleFieldChange({ key, value, formData }) {
|
|
650
|
-
console.log('字段变化:', key, value);
|
|
651
|
-
},
|
|
652
|
-
},
|
|
653
|
-
};
|
|
654
|
-
</script>
|
|
655
|
-
```
|
|
656
|
-
|
|
657
|
-
## 🎯 最佳实践
|
|
658
|
-
|
|
659
|
-
1. **使用字段分组** - 将相关字段分组,提高表单可读性
|
|
660
|
-
2. **合理使用布局** - 根据场景选择合适的布局模式
|
|
661
|
-
3. **添加提示信息** - 使用 tooltip 和 extra 提供必要的提示
|
|
662
|
-
4. **字段联动** - 使用 visible 和 disabled 函数实现动态表单
|
|
663
|
-
5. **数据转换** - 使用 transform 在提交时转换数据格式
|
|
664
|
-
6. **响应式设计** - 使用 cols 配置实现响应式布局
|
|
665
|
-
7. **验证规则** - 合理使用内置规则和自定义规则
|
|
666
|
-
8. **只读模式** - 详情页面使用只读模式展示数据
|
|
667
|
-
|
|
668
|
-
## 🔗 相关组件
|
|
669
|
-
|
|
670
|
-
- [JhFormList](../JhFormList) - 动态表单列表
|
|
671
|
-
- [JhTable](../JhTable) - 高级表格
|
|
672
|
-
- [JhDialog](../JhDialog) - 对话框
|
|
673
|
-
|
|
674
|
-
## 📄 License
|
|
675
|
-
|
|
676
|
-
MIT
|