# GridFrom **Repository Path**: wanghenan/grid-from ## Basic Information - **Project Name**: GridFrom - **Description**: 基于vue3、and design vue 技术栈实现表格样式表单 - **Primary Language**: JavaScript - **License**: Apache-2.0 - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2026-03-05 - **Last Updated**: 2026-03-05 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # GridForm > 基于 Vue 3 + Ant Design Vue 4 开发的表格样式通用表单组件,支持单列、多列、单元格横向合并(`span`)、纵向合并(`rowSpan`)及无标签(`noLabel`)等灵活布局,内置多种输入控件、表单校验与焦点高亮效果。 --- ## 效果预览 ### 示例一:单列布局 ![单列布局](./public/preview-demo1.png) ### 示例二:两列布局 + span 横向合并 ![两列布局横向合并](./public/preview-demo2.png) ### 示例三:三列布局 + 多种控件类型 ![三列布局多控件](./public/preview-demo3.png) ### 示例四:rowSpan 纵向合并 + noLabel 无标签字段 ![纵向合并与无标签](./public/preview-demo4.png) ### 示例五:后端校验错误注入 ![后端错误注入](./public/preview-demo5.png) ### 校验错误提示效果 #### 前端必填校验错误 ![前端校验错误](./public/error-validation.png) #### 后端错误注入(模拟服务端返回) ![后端错误注入](./public/error-backend.png) --- ## 技术栈 | 技术 | 版本 | 说明 | |---|---|---| | [Vue 3](https://vuejs.org/) | ^3.5 | Composition API + ` ``` --- ### 示例二:两列布局 + `span` 横向合并 ```vue ``` --- ### 示例三:`rowSpan` 纵向合并 + `noLabel` 无标签字段 ```vue ``` --- ### 示例四:后端错误注入 ```vue ``` --- ## 字段配置(field)说明 | 属性 | 类型 | 默认值 | 说明 | |---|---|---|---| | `name` | String | — | 字段键名(必填,唯一) | | `label` | String | — | 标签文字 | | `type` | String | `input` | 控件类型,见下表 | | `required` | Boolean | `false` | 是否必填 | | `requiredMessage` | String | — | 自定义必填错误提示 | | `validator` | Function | — | 自定义校验 `(value) => errMsg \| null` | | `placeholder` | String | — | 输入框占位提示 | | `disabled` | Boolean | `false` | 是否禁用 | | `defaultValue` | any | — | 重置时的默认值 | | `options` | Array | — | select / radio / checkbox 选项 `[{label, value}]` | | `rows` | Number | `4` | textarea 行数 | | `min / max / step / precision` | Number | — | number 控件参数 | | `format` | String | `YYYY-MM-DD` | date / date-range 格式 | | `mode` | String | — | select 多选模式 `'multiple' \| 'tags'` | | `maxlength` | Number | — | input / textarea 最大字符数 | | **`span`** | Number | `1` | 横向合并:占几个逻辑列宽 | | **`rowSpan`** | Number | `1` | 纵向合并:内容列跨几行 | | **`noLabel`** | Boolean | `false` | 不渲染标签列,内容自动补满 | | `labelWidth` | String | — | 单字段标签宽度(覆盖组件级设置) | | `labelSpan` | Number | — | 标签列物理跨列数(高级) | | `contentColSpan` | Number | — | 内容列物理跨列数(高级) | ### 支持的控件类型 | type | 控件 | |---|---| | `input`(默认) | 单行文本输入框 | | `textarea` | 多行文本输入框 | | `number` | 数字输入框 | | `select` | 下拉选择框 | | `date` | 日期选择器 | | `date-range` | 日期范围选择器 | | `radio` | 单选按钮组 | | `checkbox` | 多选框组 | | `switch` | 开关 | | `text` | 纯文本展示(只读) | --- ## 组件 Props | Prop | 类型 | 默认值 | 说明 | |---|---|---|---| | `title` | String | `''` | 表单标题行 | | `columns` | Number | `2` | 每行列数 | | `fields` | Array | `[]` | 字段配置数组 | | `modelValue` | Object | `{}` | 表单数据(v-model) | | `width` | String | `'100%'` | 表格宽度 | | `labelWidth` | String | `'100px'` | 标签列宽度 | --- ## 暴露方法(ref 调用) | 方法 | 说明 | 返回值 | |---|---|---| | `validate()` | 执行表单校验 | `Boolean` | | `clearValidate()` | 清除所有校验错误 | — | | `resetFields()` | 重置表单数据为默认值 | — | | `setErrors(map)` | 注入外部错误 `{ fieldName: errMsg }` | — | | `formData` | 当前表单数据(ref) | `Ref` | --- ## 本地开发 ```bash # 克隆仓库 git clone https://gitee.com/wanghenan/grid-from.git cd grid-from # 安装依赖 npm install # 启动开发服务器 npm run dev # 构建 npm run build ``` --- ## License [MIT](./LICENSE)