# 动态表单组件 - 快速开始 ## 1. 基础使用 ### 最简单的例子 ```vue ``` ## 2. 添加验证 ```vue ``` ## 3. 字段联动 ```vue ``` ## 4. 处理表单提交 ```vue ``` ## 5. 使用Composable ```vue ``` ## 6. 加载设备类型字段 ```vue ``` ## 7. 常用字段类型示例 ```typescript const fields = [ // 单行文本 { id: '1', name: 'title', label: '标题', fieldType: 'text', required: true }, // 多行文本 { id: '2', name: 'description', label: '描述', fieldType: 'textarea', rows: 4 }, // 数字 { id: '3', name: 'price', label: '价格', fieldType: 'number', validationRules: { min: 0, max: 999999 } }, // 日期 { id: '4', name: 'birthday', label: '生日', fieldType: 'date' }, // 下拉选择 { id: '5', name: 'gender', label: '性别', fieldType: 'select', options: [ { label: '男', value: 'male' }, { label: '女', value: 'female' } ] }, // 多选 { id: '6', name: 'hobbies', label: '爱好', fieldType: 'multiselect', options: [ { label: '读书', value: 'reading' }, { label: '运动', value: 'sports' }, { label: '音乐', value: 'music' } ] }, // 开关 { id: '7', name: 'isActive', label: '是否激活', fieldType: 'boolean', defaultValue: false } ] ``` ## 8. 布局控制 ```typescript const fields = [ // 半行 { id: '1', name: 'firstName', label: '名', fieldType: 'text', span: 12 // 占12列(半行) }, // 半行 { id: '2', name: 'lastName', label: '姓', fieldType: 'text', span: 12 // 占12列(半行) }, // 整行 { id: '3', name: 'address', label: '地址', fieldType: 'text', span: 24 // 占24列(整行) } ] ``` ## 9. 自定义验证 ```typescript const fields = [ { id: '1', name: 'password', label: '密码', fieldType: 'text', required: true, validationRules: { custom: (value) => { if (value.length < 8) { return '密码长度不能少于8位' } if (!/[A-Z]/.test(value)) { return '密码必须包含大写字母' } if (!/[0-9]/.test(value)) { return '密码必须包含数字' } return true } } } ] ``` ## 10. 完整示例 ```vue ``` ## 更多资源 - [完整文档](./DYNAMIC_FORM_COMPONENTS_README.md) - [开发总结](./DYNAMIC_FORM_DEVELOPMENT_SUMMARY.md) - [示例代码](./src/views/examples/DynamicFormExample.vue)