style: 优化 GiForm 表单使用代码

This commit is contained in:
2025-03-04 22:27:54 +08:00
parent 25da3019a3
commit d1e5ecf81d
14 changed files with 45 additions and 59 deletions

View File

@@ -143,6 +143,7 @@ const getComponentBindProps = (item: ColumnItem) => {
// 组件默认配置映射表 // 组件默认配置映射表
const ConfigMap = new Map<ColumnItem['type'], Partial<ColumnItem['props'] & { placeholder: string }>>([ const ConfigMap = new Map<ColumnItem['type'], Partial<ColumnItem['props'] & { placeholder: string }>>([
['input', { allowClear: true, placeholder: `请输入${item.label}`, maxLength: 255, showWordLimit: true }], ['input', { allowClear: true, placeholder: `请输入${item.label}`, maxLength: 255, showWordLimit: true }],
['input-password', { placeholder: `请输入${item.label}` }],
['input-number', { placeholder: `请输入${item.label}` }], ['input-number', { placeholder: `请输入${item.label}` }],
['textarea', { allowClear: false, placeholder: `请输入${item.label}`, maxLength: 200, showWordLimit: true, autoSize: { minRows: 3, maxRows: 5 } }], ['textarea', { allowClear: false, placeholder: `请输入${item.label}`, maxLength: 200, showWordLimit: true, autoSize: { minRows: 3, maxRows: 5 } }],
['input-tag', { allowClear: true, placeholder: `请输入${item.label}` }], ['input-tag', { allowClear: true, placeholder: `请输入${item.label}` }],

View File

@@ -3,6 +3,7 @@ import type { VNode } from 'vue'
export type ColumnItemType = export type ColumnItemType =
| 'input' | 'input'
| 'input-password'
| 'input-number' | 'input-number'
| 'input-tag' | 'input-tag'
| 'textarea' | 'textarea'
@@ -29,6 +30,7 @@ export type ColumnItemType =
export type ComponentProps = export type ComponentProps =
& A.InputInstance['$props'] & A.InputInstance['$props']
& A.InputPasswordInstance['$props']
& A.InputNumberInstance['$props'] & A.InputNumberInstance['$props']
& A.InputTagInstance['$props'] & A.InputTagInstance['$props']
& A.TextareaInstance['$props'] & A.TextareaInstance['$props']

View File

@@ -149,11 +149,10 @@ const formColumns: ColumnItem[] = reactive([
label: '作者名称', label: '作者名称',
field: 'author', field: 'author',
type: 'input', type: 'input',
required: true,
props: { props: {
maxLength: 100, maxLength: 100,
showWordLimit: true,
}, },
rules: [{ required: true, message: '请输入作者名称' }],
}, },
{ {
label: '业务名称', label: '业务名称',
@@ -162,7 +161,6 @@ const formColumns: ColumnItem[] = reactive([
props: { props: {
placeholder: '自定义业务名称,例如:用户', placeholder: '自定义业务名称,例如:用户',
maxLength: 50, maxLength: 50,
showWordLimit: true,
}, },
rules: [{ required: true, message: '请输入业务名称' }], rules: [{ required: true, message: '请输入业务名称' }],
}, },
@@ -184,7 +182,6 @@ const formColumns: ColumnItem[] = reactive([
props: { props: {
placeholder: '项目模块包名例如top.continew.admin.system', placeholder: '项目模块包名例如top.continew.admin.system',
maxLength: 60, maxLength: 60,
showWordLimit: true,
}, },
rules: [{ required: true, message: '请输入模块包名' }], rules: [{ required: true, message: '请输入模块包名' }],
}, },
@@ -195,7 +192,6 @@ const formColumns: ColumnItem[] = reactive([
props: { props: {
placeholder: '数据库表前缀例如sys_', placeholder: '数据库表前缀例如sys_',
maxLength: 20, maxLength: 20,
showWordLimit: true,
}, },
}, },
{ {

View File

@@ -42,7 +42,10 @@ const columns: ColumnItem[] = reactive([
field: 'name', field: 'name',
type: 'input', type: 'input',
span: 24, span: 24,
rules: [{ required: true, message: '请输入名称' }], required: true,
props: {
maxLength: 100,
},
}, },
{ {
label: '失效时间', label: '失效时间',
@@ -59,10 +62,6 @@ const columns: ColumnItem[] = reactive([
field: 'description', field: 'description',
type: 'textarea', type: 'textarea',
span: 24, span: 24,
props: {
maxLength: 200,
autoSize: { minRows: 3, maxRows: 5 },
},
}, },
{ {
label: '状态', label: '状态',

View File

@@ -59,6 +59,9 @@ const columns: ColumnItem[] = reactive([
field: 'phone', field: 'phone',
type: 'input', type: 'input',
span: 24, span: 24,
props: {
showWordLimit: false,
},
rules: [ rules: [
{ required: true, message: '请输入手机号' }, { required: true, message: '请输入手机号' },
{ match: Regexp.Phone, message: '请输入正确的手机号' }, { match: Regexp.Phone, message: '请输入正确的手机号' },

View File

@@ -53,21 +53,20 @@ const columns: ColumnItem[] = reactive([
label: '终端 Key', label: '终端 Key',
field: 'clientKey', field: 'clientKey',
type: 'input', type: 'input',
rules: [{ required: true, message: '请输入终端 Key' }],
span: 24, span: 24,
disabled: () => { required: true,
return isUpdate.value props: {
maxLength: 32,
}, },
disabled: () => isUpdate.value,
}, },
{ {
label: '终端秘钥', label: '终端秘钥',
field: 'clientSecret', field: 'clientSecret',
type: 'input', type: 'input',
rules: [{ required: true, message: '请输入终端秘钥' }],
span: 24, span: 24,
disabled: () => { required: true,
return isUpdate.value disabled: () => isUpdate.value,
},
slots: { slots: {
append: () => ( append: () => (
<a-button onClick={handleGenerate}> <a-button onClick={handleGenerate}>
@@ -83,12 +82,12 @@ const columns: ColumnItem[] = reactive([
label: '认证类型', label: '认证类型',
field: 'authType', field: 'authType',
type: 'select', type: 'select',
required: true,
props: { props: {
options: auth_type_enum, options: auth_type_enum,
multiple: true, multiple: true,
maxTagCount: 2, maxTagCount: 2,
}, },
rules: [{ required: true, message: '请选择认证类型' }],
}, },
{ {
label: '终端类型', label: '终端类型',
@@ -97,7 +96,6 @@ const columns: ColumnItem[] = reactive([
props: { props: {
options: client_type, options: client_type,
}, },
rules: [{ required: true, message: '请选择终端类型' }],
}, },
{ {
label: () => ( label: () => (
@@ -141,11 +139,11 @@ const columns: ColumnItem[] = reactive([
label: '状态', label: '状态',
field: 'status', field: 'status',
type: 'radio-group', type: 'radio-group',
required: true,
props: { props: {
type: 'button', type: 'button',
options: DisEnableStatusList, options: DisEnableStatusList,
}, },
rules: [{ required: true, message: '请选择状态' }],
}, },
]) ])

View File

@@ -103,10 +103,6 @@ const columns: ColumnItem[] = reactive([
field: 'description', field: 'description',
type: 'textarea', type: 'textarea',
span: 24, span: 24,
props: {
maxLength: 200,
autoSize: { minRows: 3, maxRows: 5 },
},
}, },
{ {
label: '状态', label: '状态',

View File

@@ -53,14 +53,20 @@ const columns: ColumnItem[] = reactive([
field: 'label', field: 'label',
type: 'input', type: 'input',
span: 24, span: 24,
rules: [{ required: true, message: '请输入标签' }], required: true,
props: {
maxLength: 30,
},
}, },
{ {
label: '值', label: '值',
field: 'value', field: 'value',
type: 'input', type: 'input',
span: 24, span: 24,
rules: [{ required: true, message: '请输入值' }], required: true,
props: {
maxLength: 30,
},
}, },
{ {
label: '标签颜色', label: '标签颜色',
@@ -83,10 +89,6 @@ const columns: ColumnItem[] = reactive([
field: 'description', field: 'description',
type: 'textarea', type: 'textarea',
span: 24, span: 24,
props: {
maxLength: 200,
autoSize: { minRows: 3, maxRows: 5 },
},
}, },
{ {
label: '状态', label: '状态',

View File

@@ -40,15 +40,20 @@ const columns: ColumnItem[] = reactive([
field: 'name', field: 'name',
type: 'input', type: 'input',
span: 24, span: 24,
rules: [{ required: true, message: '请输入名称', required: true,
}], props: {
maxLength: 30,
},
}, },
{ {
label: '编码', label: '编码',
field: 'code', field: 'code',
type: 'input', type: 'input',
span: 24, span: 24,
rules: [{ required: true, message: '请输入编码' }], required: true,
props: {
maxLength: 30,
},
disabled: () => isUpdate.value, disabled: () => isUpdate.value,
}, },
{ {
@@ -56,10 +61,6 @@ const columns: ColumnItem[] = reactive([
field: 'description', field: 'description',
type: 'textarea', type: 'textarea',
span: 24, span: 24,
props: {
maxLength: 200,
autoSize: { minRows: 3, maxRows: 5 },
},
}, },
]) ])

View File

@@ -12,10 +12,10 @@
<fieldset> <fieldset>
<legend>基础信息</legend> <legend>基础信息</legend>
<a-form-item label="名称" field="name"> <a-form-item label="名称" field="name">
<a-input v-model.trim="form.name" placeholder="请输入名称" /> <a-input v-model.trim="form.name" placeholder="请输入名称" max-length="30" show-word-limit />
</a-form-item> </a-form-item>
<a-form-item label="编码" field="code"> <a-form-item label="编码" field="code">
<a-input v-model.trim="form.code" placeholder="请输入编码" :disabled="isUpdate" /> <a-input v-model.trim="form.code" placeholder="请输入编码" max-length="30" show-word-limit :disabled="isUpdate" />
</a-form-item> </a-form-item>
<a-form-item label="排序" field="sort"> <a-form-item label="排序" field="sort">
<a-input-number v-model="form.sort" placeholder="请输入排序" :min="1" mode="button" /> <a-input-number v-model="form.sort" placeholder="请输入排序" :min="1" mode="button" />

View File

@@ -135,9 +135,6 @@ const columns: ColumnItem[] = reactive([
field: 'description', field: 'description',
type: 'textarea', type: 'textarea',
span: 24, span: 24,
props: {
maxLength: 200,
},
}, },
{ {
label: '状态', label: '状态',

View File

@@ -48,36 +48,32 @@ const columns: ColumnItem[] = reactive([
field: 'username', field: 'username',
type: 'input', type: 'input',
span: 24, span: 24,
required: true,
props: { props: {
maxLength: 64, maxLength: 64,
showWordLimit: true,
}, },
rules: [{ required: true, message: '请输入用户名' }],
}, },
{ {
label: '昵称', label: '昵称',
field: 'nickname', field: 'nickname',
type: 'input', type: 'input',
span: 24, span: 24,
required: true,
props: { props: {
maxLength: 30, maxLength: 30,
showWordLimit: true,
}, },
rules: [{ required: true, message: '请输入昵称' }],
}, },
{ {
label: '密码', label: '密码',
field: 'password', field: 'password',
type: 'input-password', type: 'input-password',
span: 24, span: 24,
required: true,
props: { props: {
maxLength: 32, maxLength: 32,
showWordLimit: true, showWordLimit: true,
}, },
rules: [{ required: true, message: '请输入密码' }], hide: () => isUpdate.value,
hide: () => {
return isUpdate.value
},
}, },
{ {
label: '手机号码', label: '手机号码',
@@ -111,6 +107,7 @@ const columns: ColumnItem[] = reactive([
field: 'deptId', field: 'deptId',
type: 'tree-select', type: 'tree-select',
span: 24, span: 24,
required: true,
props: { props: {
data: deptList, data: deptList,
allowClear: true, allowClear: true,
@@ -123,31 +120,25 @@ const columns: ColumnItem[] = reactive([
return false return false
}, },
}, },
rules: [{ required: true, message: '请选择所属部门' }],
}, },
{ {
label: '角色', label: '角色',
field: 'roleIds', field: 'roleIds',
type: 'select', type: 'select',
span: 24, span: 24,
required: true,
props: { props: {
options: roleList, options: roleList,
multiple: true, multiple: true,
allowClear: true, allowClear: true,
allowSearch: true, allowSearch: true,
}, },
rules: [{ required: true, message: '请选择角色' }],
}, },
{ {
label: '描述', label: '描述',
field: 'description', field: 'description',
type: 'textarea', type: 'textarea',
span: 24, span: 24,
props: {
maxLength: 200,
showWordLimit: true,
autoSize: { minRows: 3, maxRows: 5 },
},
}, },
{ {
label: '状态', label: '状态',

View File

@@ -33,7 +33,7 @@ const formRef = ref<InstanceType<typeof GiForm>>()
const [form, resetForm] = useResetReactive({}) const [form, resetForm] = useResetReactive({})
const columns: ColumnItem[] = reactive([ const columns: ColumnItem[] = reactive([
{ label: '密码', field: 'newPassword', type: 'input-password', span: 24, rules: [{ required: true, message: '请输入密码' }] }, { label: '密码', field: 'newPassword', type: 'input-password', span: 24, required: true },
]) ])
// 重置 // 重置

View File

@@ -39,13 +39,13 @@ const columns: ColumnItem[] = reactive([
field: 'roleIds', field: 'roleIds',
type: 'select', type: 'select',
span: 24, span: 24,
required: true,
props: { props: {
options: roleList, options: roleList,
multiple: true, multiple: true,
allowClear: true, allowClear: true,
allowSearch: { retainInputValue: true }, allowSearch: { retainInputValue: true },
}, },
rules: [{ required: true, message: '请选择角色' }],
}, },
]) ])