jianghu-ui 1.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.
Files changed (112) hide show
  1. package/README.md +376 -0
  2. package/dist/jianghu-ui.css +2318 -0
  3. package/dist/jianghu-ui.js +2 -0
  4. package/dist/jianghu-ui.js.LICENSE.txt +1 -0
  5. package/package.json +56 -0
  6. package/src/Design.stories.mdx +195 -0
  7. package/src/Introduction.stories.mdx +148 -0
  8. package/src/components/JhAddressSelect/JhAddressSelect.md +250 -0
  9. package/src/components/JhAddressSelect/JhAddressSelect.stories.js +282 -0
  10. package/src/components/JhAddressSelect/JhAddressSelect.vue +261 -0
  11. package/src/components/JhCard/JhCard.md +246 -0
  12. package/src/components/JhCard/JhCard.stories.js +688 -0
  13. package/src/components/JhCard/JhCard.vue +604 -0
  14. package/src/components/JhCheckCard/JhCheckCard.md +245 -0
  15. package/src/components/JhCheckCard/JhCheckCard.stories.js +750 -0
  16. package/src/components/JhCheckCard/JhCheckCard.vue +476 -0
  17. package/src/components/JhConfirmDialog/JhConfirmDialog.md +70 -0
  18. package/src/components/JhConfirmDialog/JhConfirmDialog.stories.js +550 -0
  19. package/src/components/JhConfirmDialog/JhConfirmDialog.vue +181 -0
  20. package/src/components/JhDateRangePicker/JhDateRangePicker.md +56 -0
  21. package/src/components/JhDateRangePicker/JhDateRangePicker.stories.js +320 -0
  22. package/src/components/JhDateRangePicker/JhDateRangePicker.vue +307 -0
  23. package/src/components/JhDescriptions/JhDescriptions.md +724 -0
  24. package/src/components/JhDescriptions/JhDescriptions.stories.js +858 -0
  25. package/src/components/JhDescriptions/JhDescriptions.vue +933 -0
  26. package/src/components/JhDraggable/JhDraggable.md +66 -0
  27. package/src/components/JhDraggable/JhDraggable.stories.js +161 -0
  28. package/src/components/JhDraggable/JhDraggable.vue +254 -0
  29. package/src/components/JhDrawer/JhDrawer.md +68 -0
  30. package/src/components/JhDrawer/JhDrawer.stories.js +478 -0
  31. package/src/components/JhDrawer/JhDrawer.vue +281 -0
  32. package/src/components/JhDrawerForm/JhDrawerForm.md +69 -0
  33. package/src/components/JhDrawerForm/JhDrawerForm.stories.js +492 -0
  34. package/src/components/JhDrawerForm/JhDrawerForm.vue +297 -0
  35. package/src/components/JhEditableTable/JhEditableTable.md +507 -0
  36. package/src/components/JhEditableTable/JhEditableTable.stories.js +615 -0
  37. package/src/components/JhEditableTable/JhEditableTable.vue +685 -0
  38. package/src/components/JhFileInput/JhFileInput.md +56 -0
  39. package/src/components/JhFileInput/JhFileInput.stories.js +103 -0
  40. package/src/components/JhFileInput/JhFileInput.vue +253 -0
  41. package/src/components/JhForm/JhForm.md +676 -0
  42. package/src/components/JhForm/JhForm.stories.js +1375 -0
  43. package/src/components/JhForm/JhForm.vue +657 -0
  44. package/src/components/JhFormField/JhFormField.stories.js +217 -0
  45. package/src/components/JhFormField/JhFormField.vue +439 -0
  46. package/src/components/JhFormFields/JhFormFields.md +647 -0
  47. package/src/components/JhFormFields/JhFormFields.stories.js +922 -0
  48. package/src/components/JhFormFields/JhFormFields.vue +998 -0
  49. package/src/components/JhFormList/JhFormList.md +303 -0
  50. package/src/components/JhFormList/JhFormList.stories.js +661 -0
  51. package/src/components/JhFormList/JhFormList.vue +1127 -0
  52. package/src/components/JhJsonEditor/JhJsonEditor.md +54 -0
  53. package/src/components/JhJsonEditor/JhJsonEditor.stories.js +157 -0
  54. package/src/components/JhJsonEditor/JhJsonEditor.vue +178 -0
  55. package/src/components/JhLayout/JhLayout.md +580 -0
  56. package/src/components/JhLayout/JhLayout.stories.js +414 -0
  57. package/src/components/JhLayout/JhLayout.vue +387 -0
  58. package/src/components/JhList/JhList.md +441 -0
  59. package/src/components/JhList/JhList.stories.js +524 -0
  60. package/src/components/JhList/JhList.vue +571 -0
  61. package/src/components/JhMarkdownEditor/JhMarkdownEditor.md +56 -0
  62. package/src/components/JhMarkdownEditor/JhMarkdownEditor.stories.js +191 -0
  63. package/src/components/JhMarkdownEditor/JhMarkdownEditor.vue +188 -0
  64. package/src/components/JhMask/JhMask.md +62 -0
  65. package/src/components/JhMask/JhMask.stories.js +270 -0
  66. package/src/components/JhMask/JhMask.vue +123 -0
  67. package/src/components/JhMenu/JhMenu.md +85 -0
  68. package/src/components/JhMenu/JhMenu.stories.js +384 -0
  69. package/src/components/JhMenu/JhMenu.vue +545 -0
  70. package/src/components/JhModal/JhModal.md +68 -0
  71. package/src/components/JhModal/JhModal.stories.js +562 -0
  72. package/src/components/JhModal/JhModal.vue +235 -0
  73. package/src/components/JhModalForm/JhModalForm.md +69 -0
  74. package/src/components/JhModalForm/JhModalForm.stories.js +592 -0
  75. package/src/components/JhModalForm/JhModalForm.vue +298 -0
  76. package/src/components/JhPageContainer/JhPageContainer.md +409 -0
  77. package/src/components/JhPageContainer/JhPageContainer.stories.js +209 -0
  78. package/src/components/JhPageContainer/JhPageContainer.vue +72 -0
  79. package/src/components/JhQueryFilter/JhQueryFilter.md +77 -0
  80. package/src/components/JhQueryFilter/JhQueryFilter.stories.js +684 -0
  81. package/src/components/JhQueryFilter/JhQueryFilter.vue +429 -0
  82. package/src/components/JhScene/JhScene.md +64 -0
  83. package/src/components/JhScene/JhScene.stories.js +317 -0
  84. package/src/components/JhScene/JhScene.vue +376 -0
  85. package/src/components/JhStatisticCard/JhStatisticCard.md +363 -0
  86. package/src/components/JhStatisticCard/JhStatisticCard.stories.js +847 -0
  87. package/src/components/JhStatisticCard/JhStatisticCard.vue +459 -0
  88. package/src/components/JhStepsForm/JhStepsForm.md +666 -0
  89. package/src/components/JhStepsForm/JhStepsForm.stories.js +1224 -0
  90. package/src/components/JhStepsForm/JhStepsForm.vue +749 -0
  91. package/src/components/JhTable/JhTable.md +730 -0
  92. package/src/components/JhTable/JhTable.stories.js +1444 -0
  93. package/src/components/JhTable/JhTable.vue +2298 -0
  94. package/src/components/JhTableAttachment/JhTableAttachment.md +70 -0
  95. package/src/components/JhTableAttachment/JhTableAttachment.stories.js +198 -0
  96. package/src/components/JhTableAttachment/JhTableAttachment.vue +264 -0
  97. package/src/components/JhToast/JhToast.md +67 -0
  98. package/src/components/JhToast/JhToast.stories.js +386 -0
  99. package/src/components/JhToast/JhToast.vue +239 -0
  100. package/src/components/JhTreeSelect/JhTreeSelect.md +82 -0
  101. package/src/components/JhTreeSelect/JhTreeSelect.stories.js +391 -0
  102. package/src/components/JhTreeSelect/JhTreeSelect.vue +727 -0
  103. package/src/components/JhWaterMark/JhWaterMark.md +190 -0
  104. package/src/components/JhWaterMark/JhWaterMark.stories.js +675 -0
  105. package/src/components/JhWaterMark/JhWaterMark.vue +351 -0
  106. package/src/components/README.md +52 -0
  107. package/src/index.js +135 -0
  108. package/src/style/globalCSSJHV4.css +348 -0
  109. package/src/style/globalCSSVuetifyV4.css +637 -0
  110. package/src/style/storybook.css +4 -0
  111. package/src/tailwind.css +3 -0
  112. package/src/utils/vuetify.js +31 -0
@@ -0,0 +1,657 @@
1
+ <template>
2
+ <v-form
3
+ :ref="formRef"
4
+ :lazy-validation="lazyValidation"
5
+ :class="formClasses"
6
+ v-bind="mergedFormProps"
7
+ v-on="formListeners"
8
+ >
9
+ <jh-form-fields
10
+ v-model="formData"
11
+ :fields="normalizedFields"
12
+ :layout="internalLayout"
13
+ :show-labels="showLabels"
14
+ :label-width="labelWidth"
15
+ :label-align="labelAlign"
16
+ :show-required-mark="showRequiredMark"
17
+ :readonly="readonly"
18
+ :disabled="disabled"
19
+ :default-dense="defaultDense"
20
+ :default-filled="defaultFilled"
21
+ :default-outlined="defaultOutlined"
22
+ :default-single-line="defaultSingleLine"
23
+ :default-cols-md="defaultColsMd"
24
+ :hide-details="hideDetails"
25
+ :label-class="labelClass"
26
+ :input-class="inputClass"
27
+ :row-class="rowClass"
28
+ :validation-rules="validationRules"
29
+ :row-props="gridRowProps"
30
+ @field-input="handleFieldInput"
31
+ @field-change="handleFieldChange"
32
+ @field-blur="handleFieldBlur"
33
+ >
34
+ <template v-for="field in slotFields" v-slot:[`field-${field.key}`]="slotProps">
35
+ <slot :name="`field-${field.key}`" v-bind="slotProps"></slot>
36
+ </template>
37
+ </jh-form-fields>
38
+
39
+ <template v-if="isGridLayout">
40
+ <v-row class="jh-form-grid-actions-row" v-bind="rowProps">
41
+ <v-col cols="12" class="jh-form-actions-col">
42
+ <slot name="actions" :formData="formData" :validate="validate" :resetForm="resetForm"></slot>
43
+ </v-col>
44
+ </v-row>
45
+ </template>
46
+ <template v-else>
47
+ <slot name="actions" :formData="formData" :validate="validate" :resetForm="resetForm"></slot>
48
+ </template>
49
+ </v-form>
50
+ </template>
51
+
52
+ <script>
53
+ import JhFormFields from '../JhFormFields/JhFormFields.vue';
54
+
55
+ export default {
56
+ name: 'JhForm',
57
+ inheritAttrs: false,
58
+
59
+ components: {
60
+ JhFormFields,
61
+ },
62
+
63
+ props: {
64
+ // 表单字段配置
65
+ fields: {
66
+ type: Array,
67
+ default: () => [],
68
+ },
69
+
70
+ // 初始表单数据
71
+ initialData: {
72
+ type: Object,
73
+ default: () => ({}),
74
+ },
75
+
76
+ // 表单引用名称
77
+ formRef: {
78
+ type: String,
79
+ default: 'jhForm',
80
+ },
81
+
82
+ // 懒加载验证
83
+ lazyValidation: {
84
+ type: Boolean,
85
+ default: true,
86
+ },
87
+
88
+ // 表单布局模式: 'horizontal' | 'vertical' | 'inline' | 'grid'
89
+ layout: {
90
+ type: String,
91
+ default: 'vertical',
92
+ validator: (v) => ['horizontal', 'vertical', 'inline', 'grid'].includes(v),
93
+ },
94
+
95
+ // 是否显示标签
96
+ showLabels: {
97
+ type: Boolean,
98
+ default: true,
99
+ },
100
+
101
+ // 标签位置 ('top' | 'left') - 已废弃,使用 layout 替代
102
+ labelPosition: {
103
+ type: String,
104
+ default: 'top',
105
+ validator: (v) => ['top', 'left'].includes(v),
106
+ },
107
+
108
+ // 标签宽度 (horizontal 布局时生效)
109
+ labelWidth: {
110
+ type: [Number, String],
111
+ default: 'auto',
112
+ },
113
+
114
+ // 标签对齐方式 (horizontal 布局时生效)
115
+ labelAlign: {
116
+ type: String,
117
+ default: 'right',
118
+ validator: (v) => ['left', 'right', 'center'].includes(v),
119
+ },
120
+
121
+ // 是否显示必填标记
122
+ showRequiredMark: {
123
+ type: Boolean,
124
+ default: true,
125
+ },
126
+
127
+ // 只读模式
128
+ readonly: {
129
+ type: Boolean,
130
+ default: false,
131
+ },
132
+
133
+ // 禁用模式
134
+ disabled: {
135
+ type: Boolean,
136
+ default: false,
137
+ },
138
+
139
+ // 默认输入框样式
140
+ defaultDense: {
141
+ type: Boolean,
142
+ default: true,
143
+ },
144
+
145
+ defaultFilled: {
146
+ type: Boolean,
147
+ default: true,
148
+ },
149
+
150
+ defaultOutlined: {
151
+ type: Boolean,
152
+ default: false,
153
+ },
154
+
155
+ defaultSingleLine: {
156
+ type: Boolean,
157
+ default: true,
158
+ },
159
+
160
+ // 默认列宽 (md)
161
+ defaultColsMd: {
162
+ type: Number,
163
+ default: 6,
164
+ },
165
+
166
+ // 隐藏详情信息
167
+ hideDetails: {
168
+ type: [Boolean, String],
169
+ default: false,
170
+ },
171
+
172
+ // 自定义标签样式类
173
+ labelClass: {
174
+ type: String,
175
+ default: 'jh-input-label',
176
+ },
177
+
178
+ // 自定义输入框样式类
179
+ inputClass: {
180
+ type: String,
181
+ default: 'jh-v-input',
182
+ },
183
+
184
+ // 自定义行样式类
185
+ rowClass: {
186
+ type: String,
187
+ default: '',
188
+ },
189
+
190
+ // 验证规则集合
191
+ validationRules: {
192
+ type: Object,
193
+ default: () => ({
194
+ require: [v => !!v || '必填'],
195
+ email: [v => !v || /.+@.+\..+/.test(v) || '邮箱格式不正确'],
196
+ phone: [v => !v || /^1[3-9]\d{9}$/.test(v) || '手机号格式不正确'],
197
+ number: [v => !v || !isNaN(v) || '请输入数字'],
198
+ integer: [v => !v || Number.isInteger(Number(v)) || '请输入整数'],
199
+ }),
200
+ },
201
+
202
+ // 提交按钮配置
203
+ submitter: {
204
+ type: [Object, Boolean],
205
+ default: undefined,
206
+ },
207
+
208
+ // 提交成功回调
209
+ onFinish: {
210
+ type: Function,
211
+ default: undefined,
212
+ },
213
+
214
+ // 提交失败回调
215
+ onFinishFailed: {
216
+ type: Function,
217
+ default: undefined,
218
+ },
219
+
220
+ // 日期格式化
221
+ dateFormatter: {
222
+ type: [String, Function, Boolean],
223
+ default: 'YYYY-MM-DD',
224
+ },
225
+
226
+ // 忽略 null/undefined 值
227
+ omitNil: {
228
+ type: Boolean,
229
+ default: true,
230
+ },
231
+
232
+ // Grid 模式配置
233
+ grid: {
234
+ type: Boolean,
235
+ default: false,
236
+ },
237
+
238
+ // Grid 列配置
239
+ colProps: {
240
+ type: Object,
241
+ default: () => ({}),
242
+ },
243
+
244
+ // Grid 行配置
245
+ rowProps: {
246
+ type: Object,
247
+ default: () => ({}),
248
+ },
249
+ },
250
+
251
+ data() {
252
+ return {
253
+ formData: {},
254
+ };
255
+ },
256
+
257
+ computed: {
258
+ // 表单样式类
259
+ formClasses() {
260
+ return {
261
+ 'jh-form': true,
262
+ [`jh-form--${this.layout}`]: true,
263
+ 'jh-form--readonly': this.readonly,
264
+ 'jh-form--disabled': this.disabled,
265
+ };
266
+ },
267
+
268
+ // 是否启用 Grid 布局
269
+ isGridLayout() {
270
+ return this.grid || this.layout === 'grid';
271
+ },
272
+
273
+ // 需要转交给 JhFormFields 的字段配置
274
+ normalizedFields() {
275
+ if (!this.isGridLayout) {
276
+ return this.fields;
277
+ }
278
+
279
+ return this.fields.map(field => {
280
+ if (field.type === 'group') {
281
+ return { ...field };
282
+ }
283
+
284
+ const bindings = this.getColBindings(field);
285
+ const colConfig = {};
286
+
287
+ if (bindings.cols !== undefined) colConfig.xs = bindings.cols;
288
+ if (bindings.sm !== undefined) colConfig.sm = bindings.sm;
289
+ if (bindings.md !== undefined) colConfig.md = bindings.md;
290
+ if (bindings.lg !== undefined) colConfig.lg = bindings.lg;
291
+ if (bindings.xl !== undefined) colConfig.xl = bindings.xl;
292
+
293
+ if (!Object.keys(colConfig).length) {
294
+ return { ...field };
295
+ }
296
+
297
+ const existing = field.cols && typeof field.cols === 'object' ? field.cols : {};
298
+ return {
299
+ ...field,
300
+ cols: {
301
+ ...existing,
302
+ ...colConfig,
303
+ },
304
+ };
305
+ });
306
+ },
307
+
308
+ internalLayout() {
309
+ return this.isGridLayout ? 'vertical' : this.layout;
310
+ },
311
+
312
+ slotFields() {
313
+ return this.fields.filter(field => field.type === 'slot');
314
+ },
315
+
316
+ gridRowProps() {
317
+ return this.isGridLayout ? (this.rowProps || {}) : {};
318
+ },
319
+ // 合并透传属性,只排除组件内部明确处理的属性
320
+ mergedFormProps() {
321
+ // 只排除组件内部明确处理的属性,其他所有属性都透传给 v-form
322
+ const excludedAttrs = [
323
+ 'class', 'style',
324
+ // 这些属性在组件内部有特殊处理
325
+ 'lazy-validation', 'lazyValidation',
326
+ // JhForm 特有的 props(不在 v-form 中)
327
+ 'fields', 'initialData', 'formRef', 'layout', 'showLabels',
328
+ 'labelPosition', 'labelWidth', 'labelAlign', 'showRequiredMark',
329
+ 'readonly', 'disabled', 'defaultDense', 'defaultFilled', 'defaultOutlined',
330
+ 'defaultSingleLine', 'defaultColsMd', 'hideDetails', 'labelClass',
331
+ 'inputClass', 'rowClass', 'validationRules', 'submitter', 'onFinish',
332
+ 'onFinishFailed', 'dateFormatter', 'omitNil', 'grid', 'colProps', 'rowProps'
333
+ ];
334
+
335
+ const { class: cls, style, ...rest } = this.$attrs || {};
336
+ const filteredAttrs = {};
337
+
338
+ Object.keys(rest).forEach(key => {
339
+ const keyKebab = key.replace(/([A-Z])/g, '-$1').toLowerCase();
340
+ // 只排除明确处理的属性,其他都透传
341
+ if (!excludedAttrs.includes(key) && !excludedAttrs.includes(keyKebab)) {
342
+ filteredAttrs[key] = rest[key];
343
+ }
344
+ });
345
+
346
+ return filteredAttrs;
347
+ },
348
+ // 透传所有事件,只排除组件内部明确处理的事件
349
+ formListeners() {
350
+ // 只排除组件内部明确处理的事件,其他所有事件都透传给 v-form
351
+ const excludedEvents = [
352
+ // JhForm 特有的事件(不在 v-form 中)
353
+ 'submit', 'reset', 'validate', 'input', 'change', 'blur', 'field-change'
354
+ ];
355
+
356
+ const listeners = { ...this.$listeners || {} };
357
+ const filteredListeners = {};
358
+
359
+ Object.keys(listeners).forEach(key => {
360
+ // 只排除明确处理的事件,其他都透传
361
+ if (!excludedEvents.includes(key)) {
362
+ filteredListeners[key] = listeners[key];
363
+ }
364
+ });
365
+
366
+ return filteredListeners;
367
+ }
368
+ },
369
+
370
+ watch: {
371
+ initialData: {
372
+ handler(val) {
373
+ this.formData = { ...val };
374
+ },
375
+ immediate: true,
376
+ deep: true,
377
+ },
378
+ },
379
+
380
+ mounted() {
381
+ // 初始化表单数据
382
+ this.initFormData();
383
+ },
384
+
385
+ methods: {
386
+ // 初始化表单数据
387
+ initFormData() {
388
+ const data = { ...this.initialData };
389
+
390
+ // 从 fields 中提取默认值
391
+ this.fields.forEach(field => {
392
+ if (field.defaultValue !== undefined && data[field.key] === undefined) {
393
+ data[field.key] = field.defaultValue;
394
+ }
395
+ });
396
+
397
+ this.formData = data;
398
+ },
399
+
400
+ // Grid 模式下合并列配置
401
+ getColBindings(field) {
402
+ const bindings = { ...(this.colProps || {}), ...(field.colProps || {}) };
403
+
404
+ // 兼容字段 cols 写法
405
+ if (field.cols) {
406
+ if (typeof field.cols === 'object') {
407
+ Object.assign(bindings, field.cols);
408
+ } else {
409
+ bindings.cols = field.cols;
410
+ }
411
+ }
412
+
413
+ const span = field.colSpan !== undefined ? field.colSpan : bindings.span;
414
+ const mappedCols = span !== undefined ? this.mapGridSpan(span) : null;
415
+
416
+ if (mappedCols !== null && !('cols' in bindings || 'sm' in bindings || 'md' in bindings || 'lg' in bindings || 'xl' in bindings)) {
417
+ bindings.md = mappedCols;
418
+ }
419
+
420
+ delete bindings.span;
421
+
422
+ if (!('cols' in bindings || 'sm' in bindings || 'md' in bindings || 'lg' in bindings || 'xl' in bindings)) {
423
+ bindings.md = this.mapGridSpan(this.colProps.span || 8);
424
+ }
425
+
426
+ return bindings;
427
+ },
428
+
429
+ mapGridSpan(span) {
430
+ const safeSpan = Number(span) || 0;
431
+ const mapped = Math.round((safeSpan / 24) * 12);
432
+ return Math.max(1, Math.min(12, mapped || 1));
433
+ },
434
+
435
+ handleFieldInput({ key, value }) {
436
+ this.$emit('input', key, value, this.formData);
437
+ this.$emit('field-change', { key, value, formData: this.formData });
438
+ },
439
+
440
+ handleFieldChange({ key, value }) {
441
+ this.$emit('change', key, value, this.formData);
442
+ this.$emit('field-change', { key, value, formData: this.formData });
443
+ },
444
+
445
+ handleFieldBlur({ key, value }) {
446
+ this.$emit('blur', key, value, this.formData);
447
+ },
448
+
449
+ // 更新字段值(供插槽使用)
450
+ updateField(key, value) {
451
+ this.$set(this.formData, key, value);
452
+ this.handleFieldChange({ key, value });
453
+ },
454
+
455
+ // 获取表单引用(供父组件调用) - 与 v-form 保持一致
456
+ getForm() {
457
+ return this.$refs[this.formRef];
458
+ },
459
+
460
+ // 获取表单数据
461
+ getFormData() {
462
+ return { ...this.formData };
463
+ },
464
+
465
+ // 设置表单数据
466
+ setFieldsValue(values) {
467
+ this.formData = { ...this.formData, ...values };
468
+ },
469
+
470
+ // 设置单个字段值
471
+ setFieldValue(key, value) {
472
+ this.$set(this.formData, key, value);
473
+ },
474
+
475
+ // 重置表单 - 与 v-form 的 reset() 方法保持一致
476
+ reset() {
477
+ const form = this.$refs[this.formRef];
478
+ if (form) {
479
+ form.reset();
480
+ }
481
+ this.initFormData();
482
+ this.$emit('reset', this.formData);
483
+ },
484
+
485
+ // 重置表单(别名,保持向后兼容)
486
+ resetForm() {
487
+ this.reset();
488
+ },
489
+
490
+ // 重置表单验证 - 与 v-form 的 resetValidation() 方法保持一致
491
+ resetValidation() {
492
+ const form = this.$refs[this.formRef];
493
+ if (form) {
494
+ form.resetValidation();
495
+ }
496
+ },
497
+
498
+ // 验证表单 - 与 v-form 的 validate() 方法保持一致
499
+ async validate() {
500
+ const form = this.$refs[this.formRef];
501
+ if (form) {
502
+ const isValid = await form.validate();
503
+ this.$emit('validate', isValid, this.formData);
504
+ return isValid;
505
+ }
506
+ return true;
507
+ },
508
+
509
+ // 验证单个字段 - 与 v-form 的 validate() 方法保持一致
510
+ async validateField(fieldName) {
511
+ const form = this.$refs[this.formRef];
512
+ if (form && form.$refs && form.$refs[fieldName]) {
513
+ const field = form.$refs[fieldName];
514
+ if (field && typeof field.validate === 'function') {
515
+ return await field.validate();
516
+ }
517
+ }
518
+ return true;
519
+ },
520
+
521
+ // 提交表单
522
+ async submit() {
523
+ const isValid = await this.validate();
524
+ if (isValid) {
525
+ const transformedData = this.getTransformedData();
526
+ this.$emit('submit', transformedData);
527
+
528
+ // 调用 onFinish 回调
529
+ if (this.onFinish) {
530
+ try {
531
+ await this.onFinish(transformedData);
532
+ } catch (error) {
533
+ console.error('Form submit error:', error);
534
+ }
535
+ }
536
+ } else {
537
+ // 调用 onFinishFailed 回调
538
+ if (this.onFinishFailed) {
539
+ this.onFinishFailed(this.formData);
540
+ }
541
+ }
542
+ return isValid;
543
+ },
544
+
545
+ // 获取转换后的数据
546
+ getTransformedData() {
547
+ const data = { ...this.formData };
548
+
549
+ // 应用字段级别的 transform
550
+ this.fields.forEach(field => {
551
+ if (field.key && field.transform && typeof field.transform === 'function') {
552
+ data[field.key] = field.transform(data[field.key], data);
553
+ }
554
+ });
555
+
556
+ // 忽略 null/undefined 值
557
+ if (this.omitNil) {
558
+ Object.keys(data).forEach(key => {
559
+ if (data[key] === null || data[key] === undefined || data[key] === '') {
560
+ delete data[key];
561
+ }
562
+ });
563
+ }
564
+
565
+ return data;
566
+ },
567
+
568
+ // 获取字段的依赖值
569
+ getDependenciesValues(dependencies) {
570
+ if (!dependencies || !Array.isArray(dependencies)) return [];
571
+ return dependencies.map(key => this.formData[key]);
572
+ },
573
+
574
+ // 检查依赖是否变化
575
+ checkDependenciesChanged(field, oldValues, newValues) {
576
+ if (!field.dependencies) return false;
577
+
578
+ for (let i = 0; i < field.dependencies.length; i++) {
579
+ if (oldValues[i] !== newValues[i]) {
580
+ return true;
581
+ }
582
+ }
583
+ return false;
584
+ },
585
+ },
586
+ };
587
+ </script>
588
+
589
+ <style scoped>
590
+ /* 表单布局样式 */
591
+ .jh-form {
592
+ width: 100%;
593
+ }
594
+
595
+ /* 水平布局 */
596
+ .jh-form--horizontal .jh-field-label--horizontal {
597
+ padding-top: 0;
598
+ line-height: 1.5;
599
+ }
600
+
601
+ /* 行内布局 */
602
+ .jh-form--inline .v-input {
603
+ margin-bottom: 0 !important;
604
+ }
605
+
606
+ /* 只读模式 */
607
+ .jh-form--readonly .jh-form-readonly-text {
608
+ padding: 8px 0;
609
+ min-height: 40px;
610
+ color: rgba(0, 0, 0, 0.87);
611
+ }
612
+
613
+ /* 字段标签 */
614
+ .jh-field-label {
615
+
616
+ }
617
+
618
+ .jh-field-label--horizontal {
619
+ padding-right: 12px;
620
+ }
621
+
622
+ .jh-field-label--vertical {
623
+ display: block;
624
+ }
625
+
626
+ /* 表单分组标题 */
627
+ .jh-form-group-title {
628
+ margin-top: 8px;
629
+ margin-bottom: 16px;
630
+ }
631
+
632
+ .jh-form-group-title h3 {
633
+ color: rgba(0, 0, 0, 0.85);
634
+ font-weight: 500;
635
+ }
636
+
637
+ /* 字段包装器 */
638
+ .jh-field-wrapper {
639
+ width: 100%;
640
+ }
641
+
642
+ /* 字段输入区域 */
643
+ .jh-field-input {
644
+ width: 100%;
645
+ }
646
+
647
+ /* 只读文本 */
648
+ .jh-form-readonly-text {
649
+ word-break: break-word;
650
+ }
651
+
652
+ /* 额外提示信息 */
653
+ .jh-field-extra {
654
+ margin-top: -8px;
655
+ line-height: 1.5;
656
+ }
657
+ </style>