-
Notifications
You must be signed in to change notification settings - Fork 7.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: improve element plus form component (#5072)
- Loading branch information
Showing
6 changed files
with
213 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
{ | ||
"title": "演示", | ||
"elementPlus": "Element Plus", | ||
"form": "表单演示", | ||
"vben": { | ||
"title": "项目", | ||
"about": "关于", | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,143 @@ | ||
<script lang="ts" setup> | ||
import { h } from 'vue'; | ||
import { Page } from '@vben/common-ui'; | ||
import { ElButton, ElCard, ElCheckbox, ElMessage } from 'element-plus'; | ||
import { useVbenForm } from '#/adapter/form'; | ||
const [Form, formApi] = useVbenForm({ | ||
commonConfig: { | ||
// 所有表单项 | ||
componentProps: { | ||
class: 'w-full', | ||
}, | ||
}, | ||
layout: 'horizontal', | ||
// 大屏一行显示3个,中屏一行显示2个,小屏一行显示1个 | ||
wrapperClass: 'grid-cols-1 md:grid-cols-2 lg:grid-cols-3', | ||
handleSubmit: (values) => { | ||
ElMessage.success(`表单数据:${JSON.stringify(values)}`); | ||
}, | ||
schema: [ | ||
{ | ||
component: 'Input', | ||
fieldName: 'string', | ||
label: 'String', | ||
}, | ||
{ | ||
component: 'InputNumber', | ||
fieldName: 'number', | ||
label: 'Number', | ||
}, | ||
{ | ||
component: 'RadioGroup', | ||
fieldName: 'radio', | ||
label: 'Radio', | ||
componentProps: { | ||
options: [ | ||
{ value: 'A', label: 'A' }, | ||
{ value: 'B', label: 'B' }, | ||
{ value: 'C', label: 'C' }, | ||
{ value: 'D', label: 'D' }, | ||
{ value: 'E', label: 'E' }, | ||
], | ||
}, | ||
}, | ||
{ | ||
component: 'RadioGroup', | ||
fieldName: 'radioButton', | ||
label: 'RadioButton', | ||
componentProps: { | ||
isButton: true, | ||
options: ['A', 'B', 'C', 'D', 'E', 'F'].map((v) => ({ | ||
value: v, | ||
label: `选项${v}`, | ||
})), | ||
}, | ||
}, | ||
{ | ||
component: 'CheckboxGroup', | ||
fieldName: 'checkbox', | ||
label: 'Checkbox', | ||
componentProps: { | ||
options: ['A', 'B', 'C'].map((v) => ({ value: v, label: `选项${v}` })), | ||
}, | ||
}, | ||
{ | ||
component: 'CheckboxGroup', | ||
fieldName: 'checkbox1', | ||
label: 'Checkbox1', | ||
renderComponentContent: () => { | ||
return { | ||
default: () => { | ||
return ['A', 'B', 'C', 'D'].map((v) => | ||
h(ElCheckbox, { label: v, value: v }), | ||
); | ||
}, | ||
}; | ||
}, | ||
}, | ||
{ | ||
component: 'CheckboxGroup', | ||
fieldName: 'checkbotton', | ||
label: 'CheckBotton', | ||
componentProps: { | ||
isButton: true, | ||
options: [ | ||
{ value: 'A', label: '选项A' }, | ||
{ value: 'B', label: '选项B' }, | ||
{ value: 'C', label: '选项C' }, | ||
], | ||
}, | ||
}, | ||
{ | ||
component: 'DatePicker', | ||
fieldName: 'date', | ||
label: 'Date', | ||
}, | ||
{ | ||
component: 'Select', | ||
fieldName: 'select', | ||
label: 'Select', | ||
componentProps: { | ||
options: [ | ||
{ value: 'A', label: '选项A' }, | ||
{ value: 'B', label: '选项B' }, | ||
{ value: 'C', label: '选项C' }, | ||
], | ||
}, | ||
}, | ||
], | ||
}); | ||
function setFormValues() { | ||
formApi.setValues({ | ||
string: 'string', | ||
number: 123, | ||
radio: 'B', | ||
radioButton: 'C', | ||
checkbox: ['A', 'C'], | ||
checkbotton: ['B', 'C'], | ||
checkbox1: ['A', 'B'], | ||
date: new Date(), | ||
select: 'B', | ||
}); | ||
} | ||
</script> | ||
<template> | ||
<Page | ||
description="我们重新包装了CheckboxGroup、RadioGroup、Select,可以通过options属性传入选项属性数组以自动生成选项" | ||
title="表单演示" | ||
> | ||
<ElCard> | ||
<template #header> | ||
<div class="flex items-center"> | ||
<span class="flex-auto">基础表单演示</span> | ||
<ElButton type="primary" @click="setFormValues">设置表单值</ElButton> | ||
</div> | ||
</template> | ||
<Form /> | ||
</ElCard> | ||
</Page> | ||
</template> |