king-design-analyzer 1.0.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 (92) hide show
  1. package/README.md +151 -0
  2. package/components/affix.json +178 -0
  3. package/components/az.json +86 -0
  4. package/components/badge.json +162 -0
  5. package/components/billtypes.json +90 -0
  6. package/components/breadcrumb.json +220 -0
  7. package/components/button.json +511 -0
  8. package/components/card.json +334 -0
  9. package/components/cardcontent.json +144 -0
  10. package/components/carousel.json +207 -0
  11. package/components/cascader.json +373 -0
  12. package/components/checkbox.json +298 -0
  13. package/components/code.json +318 -0
  14. package/components/collapse.json +358 -0
  15. package/components/copy.json +220 -0
  16. package/components/datepicker.json +529 -0
  17. package/components/descriptions.json +309 -0
  18. package/components/dialog.json +460 -0
  19. package/components/divider.json +287 -0
  20. package/components/drawer.json +563 -0
  21. package/components/dropdown.json +407 -0
  22. package/components/editable.json +331 -0
  23. package/components/ellipsis.json +218 -0
  24. package/components/form.json +638 -0
  25. package/components/grid.json +377 -0
  26. package/components/icon.json +442 -0
  27. package/components/input.json +821 -0
  28. package/components/layoutcontent.json +210 -0
  29. package/components/menu.json +482 -0
  30. package/components/message.json +345 -0
  31. package/components/pagination.json +444 -0
  32. package/components/paginationplus.json +74 -0
  33. package/components/popover.json +456 -0
  34. package/components/progress.json +354 -0
  35. package/components/protable.json +132 -0
  36. package/components/radio.json +246 -0
  37. package/components/region.json +115 -0
  38. package/components/select.json +676 -0
  39. package/components/slider.json +422 -0
  40. package/components/spin.json +232 -0
  41. package/components/spinner.json +441 -0
  42. package/components/status.json +75 -0
  43. package/components/steps.json +292 -0
  44. package/components/switch.json +357 -0
  45. package/components/table.json +1057 -0
  46. package/components/tablecolumnid.json +217 -0
  47. package/components/tabs.json +363 -0
  48. package/components/tag.json +504 -0
  49. package/components/timepicker.json +447 -0
  50. package/components/tip.json +322 -0
  51. package/components/tooltip.json +416 -0
  52. package/components/tour.json +395 -0
  53. package/components/transfer.json +414 -0
  54. package/components/tree.json +480 -0
  55. package/components/treeselect.json +478 -0
  56. package/components/upload.json +499 -0
  57. package/components/virtuallist.json +178 -0
  58. package/dist/ast/index.d.mts +71 -0
  59. package/dist/ast/index.d.ts +71 -0
  60. package/dist/ast/index.js +15 -0
  61. package/dist/ast/index.mjs +2 -0
  62. package/dist/chunk-4BUGNH4F.mjs +62 -0
  63. package/dist/chunk-5H7N2A5X.mjs +1 -0
  64. package/dist/chunk-5IF32MBB.js +603 -0
  65. package/dist/chunk-ARWRNWDW.js +219 -0
  66. package/dist/chunk-C3L4IXJC.mjs +577 -0
  67. package/dist/chunk-GNVCC37B.js +102 -0
  68. package/dist/chunk-N4UIA6DN.js +68 -0
  69. package/dist/chunk-RAMIBZAU.mjs +216 -0
  70. package/dist/chunk-RNQHI7YG.js +64 -0
  71. package/dist/chunk-TB6BF5TJ.mjs +99 -0
  72. package/dist/chunk-UX7KGX45.mjs +66 -0
  73. package/dist/chunk-YTEYDSDW.js +2 -0
  74. package/dist/full/index.d.mts +29 -0
  75. package/dist/full/index.d.ts +29 -0
  76. package/dist/full/index.js +16 -0
  77. package/dist/full/index.mjs +3 -0
  78. package/dist/index.d.mts +5 -0
  79. package/dist/index.d.ts +5 -0
  80. package/dist/index.js +43 -0
  81. package/dist/index.mjs +6 -0
  82. package/dist/runtime/index.d.mts +14 -0
  83. package/dist/runtime/index.d.ts +14 -0
  84. package/dist/runtime/index.js +15 -0
  85. package/dist/runtime/index.mjs +2 -0
  86. package/dist/sfcCompiler-m51JOfWs.d.mts +22 -0
  87. package/dist/sfcCompiler-m51JOfWs.d.ts +22 -0
  88. package/dist/static/index.d.mts +14 -0
  89. package/dist/static/index.d.ts +14 -0
  90. package/dist/static/index.js +19 -0
  91. package/dist/static/index.mjs +2 -0
  92. package/package.json +88 -0
@@ -0,0 +1,638 @@
1
+ {
2
+ "id": "form",
3
+ "name": "Form",
4
+ "displayName": "表单",
5
+ "category": "form",
6
+ "description": "用于数据采集和验证的表单组件,支持多种布局方式、丰富的内置验证规则、自定义验证规则,以及表单项的统一管理。",
7
+ "importStatement": "import { Form, FormItem } from '@king-design/vue';",
8
+ "props": [
9
+ {
10
+ "name": "labelWidth",
11
+ "description": "定义所有子孙 FormItem 组件的 label 宽度",
12
+ "type": {
13
+ "raw": "string | number",
14
+ "kind": "union"
15
+ },
16
+ "required": false,
17
+ "default": "undefined",
18
+ "usageExample": "<Form :labelWidth=\"120\">"
19
+ },
20
+ {
21
+ "name": "layout",
22
+ "description": "指定表单布局方式",
23
+ "type": {
24
+ "raw": "\"horizontal\" | \"vertical\" | \"inline\"",
25
+ "kind": "union",
26
+ "unionTypes": [
27
+ "horizontal",
28
+ "vertical",
29
+ "inline"
30
+ ]
31
+ },
32
+ "required": false,
33
+ "default": "\"horizontal\"",
34
+ "allowedValues": [
35
+ {
36
+ "value": "horizontal",
37
+ "label": "水平布局,label 在左,表单项在右",
38
+ "isDefault": true
39
+ },
40
+ {
41
+ "value": "vertical",
42
+ "label": "垂直布局,label 在上,表单项在下"
43
+ },
44
+ {
45
+ "value": "inline",
46
+ "label": "内联布局,所有表单项在一行显示"
47
+ }
48
+ ],
49
+ "usageExample": "<Form layout=\"vertical\">"
50
+ },
51
+ {
52
+ "name": "starOnRequired",
53
+ "description": "当 FormItem 必填时,是否在 label 前面展示 *",
54
+ "type": {
55
+ "raw": "boolean",
56
+ "kind": "boolean"
57
+ },
58
+ "required": false,
59
+ "default": "false",
60
+ "usageExample": "<Form starOnRequired>"
61
+ },
62
+ {
63
+ "name": "size",
64
+ "description": "定义表单之间的间隔大小",
65
+ "type": {
66
+ "raw": "\"default\" | \"small\" | \"mini\"",
67
+ "kind": "union",
68
+ "unionTypes": [
69
+ "default",
70
+ "small",
71
+ "mini"
72
+ ]
73
+ },
74
+ "required": false,
75
+ "default": "\"default\"",
76
+ "allowedValues": [
77
+ {
78
+ "value": "default",
79
+ "label": "默认间隔",
80
+ "isDefault": true
81
+ },
82
+ {
83
+ "value": "small",
84
+ "label": "小间隔"
85
+ },
86
+ {
87
+ "value": "mini",
88
+ "label": "迷你间隔"
89
+ }
90
+ ],
91
+ "usageExample": "<Form size=\"small\">"
92
+ }
93
+ ],
94
+ "events": [
95
+ {
96
+ "name": "submit",
97
+ "vueEventName": "@submit",
98
+ "description": "当表单提交并且所有规则都验证通过时触发",
99
+ "payload": [
100
+ {
101
+ "name": "event",
102
+ "type": "Event",
103
+ "description": "原生表单提交事件对象"
104
+ }
105
+ ],
106
+ "usageExample": "<Form @submit=\"handleSubmit\">",
107
+ "handlerExample": "const handleSubmit = (e: Event) => {\n console.log('表单验证通过,提交中...');\n};"
108
+ }
109
+ ],
110
+ "methods": [
111
+ {
112
+ "name": "validate",
113
+ "description": "验证表单所有规则",
114
+ "params": [],
115
+ "returnType": "Promise<boolean>",
116
+ "usageExample": "const formRef = ref<InstanceType<typeof Form>>();\n\nconst handleSubmit = async () => {\n const valid = await formRef.value?.validate();\n if (valid) {\n console.log('验证通过');\n }\n};"
117
+ },
118
+ {
119
+ "name": "reset",
120
+ "description": "重置表单验证状态",
121
+ "params": [],
122
+ "returnType": "void",
123
+ "usageExample": "formRef.value?.reset();"
124
+ },
125
+ {
126
+ "name": "getFirstInvalidFormItem",
127
+ "description": "获取第一条出错的 FormItem",
128
+ "params": [],
129
+ "returnType": "FormItem",
130
+ "usageExample": "const firstError = formRef.value?.getFirstInvalidFormItem();"
131
+ },
132
+ {
133
+ "name": "getAllInvalidFormItems",
134
+ "description": "获取所有校验失败的 FormItem",
135
+ "params": [],
136
+ "returnType": "FormItem[]",
137
+ "usageExample": "const allErrors = formRef.value?.getAllInvalidFormItems();"
138
+ }
139
+ ],
140
+ "staticMethods": [
141
+ {
142
+ "name": "addMethod",
143
+ "description": "添加全局验证规则,在所有 FormItem 中可以通过规则名使用",
144
+ "params": [
145
+ {
146
+ "name": "name",
147
+ "type": "string",
148
+ "description": "规则名称,不能重复"
149
+ },
150
+ {
151
+ "name": "method",
152
+ "type": "(value: any, param: any) => boolean | string | Promise<boolean | string>",
153
+ "description": "验证函数,返回 true 表示验证通过,false 或字符串表示失败"
154
+ },
155
+ {
156
+ "name": "message",
157
+ "type": "string | ((value: any, param: any) => string)",
158
+ "description": "验证失败时的错误提示文案",
159
+ "optional": true
160
+ },
161
+ {
162
+ "name": "className",
163
+ "type": "string | ((value: any, param: any) => string)",
164
+ "description": "验证失败时添加的类名",
165
+ "optional": true
166
+ }
167
+ ],
168
+ "returnType": "void",
169
+ "usageExample": "Form.addMethod('phone', (value: string) => {\n return /^1[3-9]\\d{9}$/.test(value) || '请输入正确的手机号';\n});"
170
+ }
171
+ ],
172
+ "builtinRules": [
173
+ {
174
+ "name": "required",
175
+ "description": "必须填写",
176
+ "usage": ":rules=\"{required: true}\""
177
+ },
178
+ {
179
+ "name": "digits",
180
+ "description": "请输入数字",
181
+ "usage": ":rules=\"{digits: true}\""
182
+ },
183
+ {
184
+ "name": "email",
185
+ "description": "请输入正确的邮箱地址",
186
+ "usage": ":rules=\"{email: true}\""
187
+ },
188
+ {
189
+ "name": "url",
190
+ "description": "请输入正确的网址",
191
+ "usage": ":rules=\"{url: true}\""
192
+ },
193
+ {
194
+ "name": "date",
195
+ "description": "请输入正确的日期",
196
+ "usage": ":rules=\"{date: true}\""
197
+ },
198
+ {
199
+ "name": "dateISO",
200
+ "description": "请输入正确的日期(YYYY-MM-DD)",
201
+ "usage": ":rules=\"{dateISO: true}\""
202
+ },
203
+ {
204
+ "name": "number",
205
+ "description": "请输入正确的数",
206
+ "usage": ":rules=\"{number: true}\""
207
+ },
208
+ {
209
+ "name": "maxLength",
210
+ "description": "最多输入/选择 n 项",
211
+ "usage": ":rules=\"{maxLength: 10}\""
212
+ },
213
+ {
214
+ "name": "minLength",
215
+ "description": "最少输入/选择 n 项",
216
+ "usage": ":rules=\"{minLength: 2}\""
217
+ },
218
+ {
219
+ "name": "rangeLength",
220
+ "description": "长度范围验证",
221
+ "usage": ":rules=\"{rangeLength: [2, 10]}\""
222
+ },
223
+ {
224
+ "name": "max",
225
+ "description": "请输入不大于 n 的数",
226
+ "usage": ":rules=\"{max: 100}\""
227
+ },
228
+ {
229
+ "name": "min",
230
+ "description": "请输入不小于 n 的数",
231
+ "usage": ":rules=\"{min: 0}\""
232
+ },
233
+ {
234
+ "name": "range",
235
+ "description": "请输入 min 到 max 之间的数",
236
+ "usage": ":rules=\"{range: [0, 100]}\""
237
+ },
238
+ {
239
+ "name": "step",
240
+ "description": "请输入步长为 n 的数",
241
+ "usage": ":rules=\"{step: 5}\""
242
+ },
243
+ {
244
+ "name": "equal",
245
+ "description": "两次输入不一致",
246
+ "usage": ":rules=\"{equal: password}\""
247
+ }
248
+ ],
249
+ "subComponents": [
250
+ {
251
+ "name": "FormItem",
252
+ "description": "表单项组件,用于包裹表单控件并提供验证功能",
253
+ "props": [
254
+ {
255
+ "name": "value",
256
+ "description": "指定需要验证的数据",
257
+ "type": {
258
+ "raw": "any",
259
+ "kind": "custom"
260
+ },
261
+ "required": false,
262
+ "default": "undefined",
263
+ "usageExample": "<FormItem :value=\"model.username\" :rules=\"{required: true}\">"
264
+ },
265
+ {
266
+ "name": "rules",
267
+ "description": "指定验证规则,可使用内置规则或自定义规则",
268
+ "type": {
269
+ "raw": "Record<string, any>",
270
+ "kind": "object"
271
+ },
272
+ "required": false,
273
+ "default": "undefined",
274
+ "usageExample": "<FormItem :rules=\"{required: true, email: true, maxLength: 50}\">"
275
+ },
276
+ {
277
+ "name": "messages",
278
+ "description": "指定验证失败时错误提示文案,key 为规则名",
279
+ "type": {
280
+ "raw": "Record<string, string | ((value: any, param: any) => string)>",
281
+ "kind": "object"
282
+ },
283
+ "required": false,
284
+ "default": "undefined",
285
+ "usageExample": "<FormItem :messages=\"{required: '此项必填', email: '邮箱格式不正确'}\">"
286
+ },
287
+ {
288
+ "name": "classNames",
289
+ "description": "指定验证失败时添加的 className,key 为规则名",
290
+ "type": {
291
+ "raw": "Record<string, string | ((value: any, param: any) => string)>",
292
+ "kind": "object"
293
+ },
294
+ "required": false,
295
+ "default": "undefined",
296
+ "usageExample": "<FormItem :classNames=\"{required: 'error-required'}\">"
297
+ },
298
+ {
299
+ "name": "errorClassName",
300
+ "description": "指定验证失败时统一添加的 className,不管是哪个规则导致的失败",
301
+ "type": {
302
+ "raw": "string",
303
+ "kind": "string"
304
+ },
305
+ "required": false,
306
+ "default": "undefined",
307
+ "usageExample": "<FormItem errorClassName=\"form-error\">"
308
+ },
309
+ {
310
+ "name": "label",
311
+ "description": "指定表单每一项前面展示的标题",
312
+ "type": {
313
+ "raw": "string",
314
+ "kind": "string"
315
+ },
316
+ "required": false,
317
+ "default": "undefined",
318
+ "usageExample": "<FormItem label=\"用户名\">"
319
+ },
320
+ {
321
+ "name": "htmlFor",
322
+ "description": "指定 label 的 for 属性,用于关联表单控件",
323
+ "type": {
324
+ "raw": "string",
325
+ "kind": "string"
326
+ },
327
+ "required": false,
328
+ "default": "undefined",
329
+ "usageExample": "<FormItem label=\"用户名\" htmlFor=\"username\">"
330
+ },
331
+ {
332
+ "name": "hideLabel",
333
+ "description": "是否隐藏 label,默认会展示 label,即使该属性为空,也会展示占位元素",
334
+ "type": {
335
+ "raw": "boolean",
336
+ "kind": "boolean"
337
+ },
338
+ "required": false,
339
+ "default": "false",
340
+ "usageExample": "<FormItem hideLabel>"
341
+ },
342
+ {
343
+ "name": "fluid",
344
+ "description": "FormItem 的宽度默认是被子元素撑开的,添加该属性可以渲染 100% 的宽度",
345
+ "type": {
346
+ "raw": "boolean",
347
+ "kind": "boolean"
348
+ },
349
+ "required": false,
350
+ "default": "false",
351
+ "usageExample": "<FormItem fluid>"
352
+ },
353
+ {
354
+ "name": "validateOnStart",
355
+ "description": "是否组件一渲染就开始验证,而不是等用户输入完成再验证",
356
+ "type": {
357
+ "raw": "boolean",
358
+ "kind": "boolean"
359
+ },
360
+ "required": false,
361
+ "default": "false",
362
+ "usageExample": "<FormItem validateOnStart>"
363
+ }
364
+ ],
365
+ "slots": [
366
+ {
367
+ "name": "label",
368
+ "description": "扩展前面的标题label"
369
+ },
370
+ {
371
+ "name": "content",
372
+ "description": "扩展后面的内容,也可以使用children代替"
373
+ },
374
+ {
375
+ "name": "append",
376
+ "description": "往后面追加的内容"
377
+ }
378
+ ]
379
+ }
380
+ ],
381
+ "typeDefinitions": [
382
+ {
383
+ "name": "Method",
384
+ "definition": "type Method = (value: any, param: any) => boolean | string | Promise<boolean | string>",
385
+ "description": "验证函数类型,返回 true 表示验证通过,false 或字符串表示失败"
386
+ },
387
+ {
388
+ "name": "Message",
389
+ "definition": "type Message = string | ((value: any, param: any) => string)",
390
+ "description": "错误提示文案类型,可以是字符串或返回字符串的函数"
391
+ },
392
+ {
393
+ "name": "ClassName",
394
+ "definition": "type ClassName = string | ((value: any, param: any) => string)",
395
+ "description": "错误类名类型,可以是字符串或返回字符串的函数"
396
+ }
397
+ ],
398
+ "examples": [
399
+ {
400
+ "id": "form_basic",
401
+ "title": "基础表单验证",
402
+ "description": "基本的表单验证用法",
403
+ "difficulty": "medium",
404
+ "code": "<script setup lang=\"ts\">\nimport { ref, reactive } from 'vue';\nimport { Form, FormItem, Input, Button, Message } from '@king-design/vue';\n\nconst form = ref<InstanceType<typeof Form>>();\nconst model = reactive({\n username: '',\n email: ''\n});\n\nconst handleSubmit = async () => {\n if (await form.value?.validate()) {\n Message.success('验证通过');\n }\n};\n</script>\n<template>\n <Form ref=\"form\" @submit=\"handleSubmit\">\n <FormItem label=\"用户名\" :value=\"model.username\" :rules=\"{required: true}\">\n <Input v-model=\"model.username\" />\n </FormItem>\n <FormItem label=\"邮箱\" :value=\"model.email\" :rules=\"{required: true, email: true}\">\n <Input v-model=\"model.email\" />\n </FormItem>\n <FormItem>\n <Button type=\"primary\" htmlType=\"submit\">提交</Button>\n </FormItem>\n </Form>\n</template>",
405
+ "tags": [
406
+ "basic",
407
+ "validation",
408
+ "required",
409
+ "email"
410
+ ],
411
+ "usedProps": [
412
+ "label",
413
+ "value",
414
+ "rules"
415
+ ],
416
+ "usedEvents": [
417
+ "submit"
418
+ ],
419
+ "usedMethods": [
420
+ "validate"
421
+ ],
422
+ "scenario": "创建一个带有用户名和邮箱验证的基础表单"
423
+ },
424
+ {
425
+ "id": "form_layout_vertical",
426
+ "title": "垂直布局表单",
427
+ "description": "使用垂直布局的表单",
428
+ "difficulty": "easy",
429
+ "code": "<script setup lang=\"ts\">\nimport { reactive } from 'vue';\nimport { Form, FormItem, Input } from '@king-design/vue';\n\nconst model = reactive({\n name: ''\n});\n</script>\n<template>\n <Form layout=\"vertical\">\n <FormItem label=\"姓名\" :value=\"model.name\" :rules=\"{required: true}\">\n <Input v-model=\"model.name\" />\n </FormItem>\n </Form>\n</template>",
430
+ "tags": [
431
+ "layout",
432
+ "vertical"
433
+ ],
434
+ "usedProps": [
435
+ "layout",
436
+ "label",
437
+ "value",
438
+ "rules"
439
+ ],
440
+ "usedEvents": [],
441
+ "usedMethods": [],
442
+ "scenario": "创建垂直布局的表单,label 显示在输入框上方"
443
+ },
444
+ {
445
+ "id": "form_layout_inline",
446
+ "title": "内联布局表单",
447
+ "description": "使用内联布局的搜索表单",
448
+ "difficulty": "easy",
449
+ "code": "<script setup lang=\"ts\">\nimport { reactive } from 'vue';\nimport { Form, FormItem, Input, Button } from '@king-design/vue';\n\nconst model = reactive({\n keyword: ''\n});\n</script>\n<template>\n <Form layout=\"inline\">\n <FormItem label=\"关键词\">\n <Input v-model=\"model.keyword\" placeholder=\"请输入\" />\n </FormItem>\n <FormItem>\n <Button type=\"primary\">搜索</Button>\n </FormItem>\n </Form>\n</template>",
450
+ "tags": [
451
+ "layout",
452
+ "inline",
453
+ "search"
454
+ ],
455
+ "usedProps": [
456
+ "layout"
457
+ ],
458
+ "usedEvents": [],
459
+ "usedMethods": [],
460
+ "scenario": "创建内联布局的搜索表单,所有表单项在一行显示"
461
+ },
462
+ {
463
+ "id": "form_custom_rule",
464
+ "title": "自定义验证规则",
465
+ "description": "添加自定义的手机号验证规则",
466
+ "difficulty": "medium",
467
+ "code": "<script setup lang=\"ts\">\nimport { onMounted, reactive } from 'vue';\nimport { Form, FormItem, Input } from '@king-design/vue';\n\nconst model = reactive({\n phone: ''\n});\n\nonMounted(() => {\n Form.addMethod('phone', (value: string) => {\n return /^1[3-9]\\d{9}$/.test(value) || '请输入正确的手机号';\n });\n});\n</script>\n<template>\n <Form>\n <FormItem label=\"手机号\" :value=\"model.phone\" :rules=\"{required: true, phone: true}\">\n <Input v-model=\"model.phone\" />\n </FormItem>\n </Form>\n</template>",
468
+ "tags": [
469
+ "custom",
470
+ "validation",
471
+ "addMethod",
472
+ "phone"
473
+ ],
474
+ "usedProps": [
475
+ "label",
476
+ "value",
477
+ "rules"
478
+ ],
479
+ "usedEvents": [],
480
+ "usedMethods": [],
481
+ "scenario": "使用 Form.addMethod 添加自定义的手机号验证规则"
482
+ },
483
+ {
484
+ "id": "form_password_confirm",
485
+ "title": "密码确认验证",
486
+ "description": "使用 equal 规则实现密码确认",
487
+ "difficulty": "medium",
488
+ "code": "<script setup lang=\"ts\">\nimport { reactive } from 'vue';\nimport { Form, FormItem, Input } from '@king-design/vue';\n\nconst model = reactive({\n password: '',\n confirmPassword: ''\n});\n</script>\n<template>\n <Form>\n <FormItem label=\"密码\" :value=\"model.password\" :rules=\"{required: true}\">\n <Input type=\"password\" v-model=\"model.password\" />\n </FormItem>\n <FormItem label=\"确认密码\" :value=\"model.confirmPassword\" \n :rules=\"{required: true, equal: model.password}\">\n <Input type=\"password\" v-model=\"model.confirmPassword\" />\n </FormItem>\n </Form>\n</template>",
489
+ "tags": [
490
+ "password",
491
+ "equal",
492
+ "confirm"
493
+ ],
494
+ "usedProps": [
495
+ "label",
496
+ "value",
497
+ "rules"
498
+ ],
499
+ "usedEvents": [],
500
+ "usedMethods": [],
501
+ "scenario": "创建密码和确认密码字段,验证两次输入是否一致"
502
+ },
503
+ {
504
+ "id": "form_custom_messages",
505
+ "title": "自定义错误提示",
506
+ "description": "自定义验证失败时的错误提示文案",
507
+ "difficulty": "easy",
508
+ "code": "<script setup lang=\"ts\">\nimport { reactive } from 'vue';\nimport { Form, FormItem, Input } from '@king-design/vue';\n\nconst model = reactive({\n email: ''\n});\n</script>\n<template>\n <Form>\n <FormItem label=\"邮箱\" :value=\"model.email\" \n :rules=\"{required: true, email: true}\"\n :messages=\"{required: '邮箱不能为空', email: '邮箱格式不正确'}\">\n <Input v-model=\"model.email\" />\n </FormItem>\n </Form>\n</template>",
509
+ "tags": [
510
+ "messages",
511
+ "custom",
512
+ "error"
513
+ ],
514
+ "usedProps": [
515
+ "label",
516
+ "value",
517
+ "rules",
518
+ "messages"
519
+ ],
520
+ "usedEvents": [],
521
+ "usedMethods": [],
522
+ "scenario": "自定义表单验证失败时显示的错误提示文案"
523
+ },
524
+ {
525
+ "id": "form_reset",
526
+ "title": "重置表单",
527
+ "description": "重置表单验证状态",
528
+ "difficulty": "easy",
529
+ "code": "<script setup lang=\"ts\">\nimport { ref, reactive } from 'vue';\nimport { Form, FormItem, Input, Button } from '@king-design/vue';\n\nconst form = ref<InstanceType<typeof Form>>();\nconst model = reactive({\n name: ''\n});\n\nconst handleReset = () => {\n form.value?.reset();\n model.name = '';\n};\n</script>\n<template>\n <Form ref=\"form\">\n <FormItem label=\"姓名\" :value=\"model.name\" :rules=\"{required: true}\">\n <Input v-model=\"model.name\" />\n </FormItem>\n <FormItem>\n <Button @click=\"handleReset\">重置</Button>\n </FormItem>\n </Form>\n</template>",
530
+ "tags": [
531
+ "reset",
532
+ "clear"
533
+ ],
534
+ "usedProps": [
535
+ "label",
536
+ "value",
537
+ "rules"
538
+ ],
539
+ "usedEvents": [],
540
+ "usedMethods": [
541
+ "reset"
542
+ ],
543
+ "scenario": "重置表单的验证状态和数据"
544
+ },
545
+ {
546
+ "id": "form_star_required",
547
+ "title": "必填项显示星号",
548
+ "description": "在必填项 label 前显示红色星号",
549
+ "difficulty": "easy",
550
+ "code": "<script setup lang=\"ts\">\nimport { reactive } from 'vue';\nimport { Form, FormItem, Input } from '@king-design/vue';\n\nconst model = reactive({\n name: '',\n nickname: ''\n});\n</script>\n<template>\n <Form starOnRequired>\n <FormItem label=\"姓名\" :value=\"model.name\" :rules=\"{required: true}\">\n <Input v-model=\"model.name\" />\n </FormItem>\n <FormItem label=\"昵称\">\n <Input v-model=\"model.nickname\" />\n </FormItem>\n </Form>\n</template>",
551
+ "tags": [
552
+ "starOnRequired",
553
+ "required",
554
+ "asterisk"
555
+ ],
556
+ "usedProps": [
557
+ "starOnRequired",
558
+ "label",
559
+ "value",
560
+ "rules"
561
+ ],
562
+ "usedEvents": [],
563
+ "usedMethods": [],
564
+ "scenario": "在必填表单项的 label 前显示红色星号标记"
565
+ }
566
+ ],
567
+ "commonMistakes": [
568
+ {
569
+ "id": "form_missing_value",
570
+ "description": "FormItem 配置了 rules 但未绑定 value",
571
+ "wrongCode": "<FormItem label=\"用户名\" :rules=\"{required: true}\">\n <Input v-model=\"model.username\" />\n</FormItem>",
572
+ "correctCode": "<FormItem label=\"用户名\" :value=\"model.username\" :rules=\"{required: true}\">\n <Input v-model=\"model.username\" />\n</FormItem>",
573
+ "explanation": "使用验证规则时,必须通过 :value 属性绑定需要验证的数据,否则验证不会生效",
574
+ "relatedProps": [
575
+ "value",
576
+ "rules"
577
+ ]
578
+ },
579
+ {
580
+ "id": "form_layout_typo",
581
+ "description": "使用不存在的 layout 值",
582
+ "wrongCode": "<Form layout=\"flex\">",
583
+ "correctCode": "<Form layout=\"horizontal\">",
584
+ "explanation": "Form 的 layout 只支持 horizontal, vertical, inline 三种值",
585
+ "relatedProps": [
586
+ "layout"
587
+ ]
588
+ },
589
+ {
590
+ "id": "form_rules_format",
591
+ "description": "rules 格式错误",
592
+ "wrongCode": "<FormItem :rules=\"'required'\">",
593
+ "correctCode": "<FormItem :rules=\"{required: true}\">",
594
+ "explanation": "rules 必须是对象格式,key 为规则名,value 为规则参数(通常为 true 或具体值)",
595
+ "relatedProps": [
596
+ "rules"
597
+ ]
598
+ },
599
+ {
600
+ "id": "form_validate_sync",
601
+ "description": "validate 方法未使用 await",
602
+ "wrongCode": "const valid = form.value?.validate();\nif (valid) { /* ... */ }",
603
+ "correctCode": "const valid = await form.value?.validate();\nif (valid) { /* ... */ }",
604
+ "explanation": "validate() 返回 Promise,必须使用 await 或 .then() 获取验证结果",
605
+ "relatedProps": []
606
+ }
607
+ ],
608
+ "searchKeywords": [
609
+ "表单",
610
+ "form",
611
+ "验证",
612
+ "validation",
613
+ "FormItem",
614
+ "校验",
615
+ "必填",
616
+ "required",
617
+ "规则",
618
+ "rules",
619
+ "提交",
620
+ "submit"
621
+ ],
622
+ "useCases": [
623
+ "用户登录/注册表单",
624
+ "数据采集表单",
625
+ "搜索筛选表单",
626
+ "设置配置表单",
627
+ "多步骤表单向导",
628
+ "弹窗内的表单"
629
+ ],
630
+ "relatedComponents": [
631
+ "FormItem",
632
+ "Input",
633
+ "Select",
634
+ "Checkbox",
635
+ "Radio",
636
+ "Button"
637
+ ]
638
+ }