refactor(GiForm): 优化 GiForm 代码

This commit is contained in:
2024-12-10 22:24:11 +08:00
parent f64a7163e5
commit ef4b6b99c6

View File

@@ -109,49 +109,39 @@ const colVShow = (index: number) => {
// 组件的默认props配置 // 组件的默认props配置
const getComponentBindProps = (item: ColumnsItem) => { const getComponentBindProps = (item: ColumnsItem) => {
const obj: Partial<ColumnsItem['props'] & { placeholder: string }> = {} const obj: Partial<ColumnsItem['props'] & { placeholder: string }> = {}
if (item.type === 'input') { switch (item.type) {
obj.allowClear = true case 'input':
obj.placeholder = `请输入${item.label}` case 'input-password':
} case 'input-number':
if (item.type === 'input-password') { obj.allowClear = true
obj.allowClear = true obj.placeholder = `请输入${item.label}`
obj.placeholder = `请输入${item.label}` break
} case 'textarea':
if (item.type === 'input-number') { obj.placeholder = `请输入${item.label}`
obj.allowClear = true obj.maxLength = 200
obj.placeholder = `请输入${item.label}` break
} case 'select':
if (item.type === 'textarea') { case 'cascader':
obj.placeholder = `请输入${item.label}` obj.allowClear = true
obj.maxLength = 200 obj.placeholder = `请选择${item.label}`
} obj.options = dicData[item.field] || item.options
if (item.type === 'select') { break
obj.allowClear = true case 'tree-select':
obj.placeholder = `请选择${item.label}` obj.allowClear = true
obj.options = dicData[item.field] || item.options obj.placeholder = `请选择${item.label}`
} obj.data = dicData[item.field] || item.data
if (item.type === 'cascader') { break
obj.allowClear = true case 'radio-group':
obj.placeholder = `请选择${item.label}` case 'checkbox-group':
obj.options = dicData[item.field] || item.options obj.options = dicData[item.field] || item.options
} break
if (item.type === 'tree-select') { case 'date-picker':
obj.allowClear = true obj.placeholder = '请选择日期'
obj.placeholder = `请选择${item.label}` break
obj.data = dicData[item.field] || item.data case 'time-picker':
} obj.allowClear = true
if (item.type === 'radio-group') { obj.placeholder = `请选择时间`
obj.options = dicData[item.field] || item.options break
}
if (item.type === 'checkbox-group') {
obj.options = dicData[item.field] || item.options
}
if (item.type === 'date-picker') {
obj.placeholder = '请选择日期'
}
if (item.type === 'time-picker') {
obj.allowClear = true
obj.placeholder = `请选择时间`
} }
return { ...obj, ...item.props } return { ...obj, ...item.props }
} }