perf: dialog combine with form
This commit is contained in:
parent
1acb4d7e8f
commit
34aefb64ab
|
@ -382,7 +382,9 @@ export default {
|
||||||
dialog: 'Dialog',
|
dialog: 'Dialog',
|
||||||
dialogDes: 'Secondary packaging of Dialog components based on ElementPlus',
|
dialogDes: 'Secondary packaging of Dialog components based on ElementPlus',
|
||||||
open: 'Open',
|
open: 'Open',
|
||||||
close: 'Close'
|
close: 'Close',
|
||||||
|
combineWithForm: 'Combine with form',
|
||||||
|
submit: 'Submit'
|
||||||
},
|
},
|
||||||
imageViewerDemo: {
|
imageViewerDemo: {
|
||||||
open: 'Open',
|
open: 'Open',
|
||||||
|
|
|
@ -379,7 +379,9 @@ export default {
|
||||||
dialog: '弹窗',
|
dialog: '弹窗',
|
||||||
dialogDes: '基于 ElementPlus 的 Dialog 组件二次封装',
|
dialogDes: '基于 ElementPlus 的 Dialog 组件二次封装',
|
||||||
open: '打开',
|
open: '打开',
|
||||||
close: '关闭'
|
close: '关闭',
|
||||||
|
combineWithForm: '与表单结合',
|
||||||
|
submit: '提交'
|
||||||
},
|
},
|
||||||
imageViewerDemo: {
|
imageViewerDemo: {
|
||||||
open: '打开',
|
open: '打开',
|
||||||
|
|
|
@ -3,11 +3,120 @@ import { ContentWrap } from '@/components/ContentWrap'
|
||||||
import { Dialog } from '@/components/Dialog'
|
import { Dialog } from '@/components/Dialog'
|
||||||
import { ElButton } from 'element-plus'
|
import { ElButton } from 'element-plus'
|
||||||
import { useI18n } from '@/hooks/web/useI18n'
|
import { useI18n } from '@/hooks/web/useI18n'
|
||||||
import { ref } from 'vue'
|
import { ref, reactive, unref } from 'vue'
|
||||||
|
import { Form, FormExpose } from '@/components/Form'
|
||||||
|
import { useValidator } from '@/hooks/web/useValidator'
|
||||||
|
import { getDictOneApi } from '@/api/common'
|
||||||
|
|
||||||
|
const { required } = useValidator()
|
||||||
|
|
||||||
const { t } = useI18n()
|
const { t } = useI18n()
|
||||||
|
|
||||||
const dialogVisible = ref(false)
|
const dialogVisible = ref(false)
|
||||||
|
|
||||||
|
const dialogVisible2 = ref(false)
|
||||||
|
|
||||||
|
const schema = reactive<FormSchema[]>([
|
||||||
|
{
|
||||||
|
field: 'field1',
|
||||||
|
label: t('formDemo.input'),
|
||||||
|
component: 'Input',
|
||||||
|
formItemProps: {
|
||||||
|
rules: [required()]
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
field: 'field2',
|
||||||
|
label: t('formDemo.select'),
|
||||||
|
component: 'Select',
|
||||||
|
componentProps: {
|
||||||
|
options: [
|
||||||
|
{
|
||||||
|
label: 'option1',
|
||||||
|
value: '1'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: 'option2',
|
||||||
|
value: '2'
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
field: 'field3',
|
||||||
|
label: t('formDemo.radio'),
|
||||||
|
component: 'Radio',
|
||||||
|
componentProps: {
|
||||||
|
options: [
|
||||||
|
{
|
||||||
|
label: 'option-1',
|
||||||
|
value: '1'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: 'option-2',
|
||||||
|
value: '2'
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
field: 'field4',
|
||||||
|
label: t('formDemo.checkbox'),
|
||||||
|
component: 'Checkbox',
|
||||||
|
value: [],
|
||||||
|
componentProps: {
|
||||||
|
options: [
|
||||||
|
{
|
||||||
|
label: 'option-1',
|
||||||
|
value: '1'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: 'option-2',
|
||||||
|
value: '2'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: 'option-3',
|
||||||
|
value: '3'
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
field: 'field5',
|
||||||
|
component: 'DatePicker',
|
||||||
|
label: t('formDemo.datePicker'),
|
||||||
|
componentProps: {
|
||||||
|
type: 'date'
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
field: 'field6',
|
||||||
|
component: 'TimeSelect',
|
||||||
|
label: t('formDemo.timeSelect')
|
||||||
|
}
|
||||||
|
])
|
||||||
|
|
||||||
|
const getDictOne = async () => {
|
||||||
|
const res = await getDictOneApi()
|
||||||
|
if (res) {
|
||||||
|
schema[1].componentProps!.options = res.data
|
||||||
|
}
|
||||||
|
}
|
||||||
|
getDictOne()
|
||||||
|
|
||||||
|
const formRef = ref<FormExpose>()
|
||||||
|
|
||||||
|
const formSubmit = () => {
|
||||||
|
unref(formRef)
|
||||||
|
?.getElFormRef()
|
||||||
|
?.validate((valid) => {
|
||||||
|
if (valid) {
|
||||||
|
console.log('submit success')
|
||||||
|
} else {
|
||||||
|
console.log('submit fail')
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
|
@ -15,11 +124,24 @@ const dialogVisible = ref(false)
|
||||||
<ElButton type="primary" @click="dialogVisible = !dialogVisible">
|
<ElButton type="primary" @click="dialogVisible = !dialogVisible">
|
||||||
{{ t('dialogDemo.open') }}
|
{{ t('dialogDemo.open') }}
|
||||||
</ElButton>
|
</ElButton>
|
||||||
|
|
||||||
|
<ElButton type="primary" @click="dialogVisible2 = !dialogVisible2">
|
||||||
|
{{ t('dialogDemo.combineWithForm') }}
|
||||||
|
</ElButton>
|
||||||
|
|
||||||
<Dialog v-model="dialogVisible" :title="t('dialogDemo.dialog')">
|
<Dialog v-model="dialogVisible" :title="t('dialogDemo.dialog')">
|
||||||
<div v-for="v in 10000" :key="v">{{ v }}</div>
|
<div v-for="v in 10000" :key="v">{{ v }}</div>
|
||||||
<template #footer>
|
<template #footer>
|
||||||
<ElButton @click="dialogVisible = false">{{ t('dialogDemo.close') }}</ElButton>
|
<ElButton @click="dialogVisible = false">{{ t('dialogDemo.close') }}</ElButton>
|
||||||
</template>
|
</template>
|
||||||
</Dialog>
|
</Dialog>
|
||||||
|
|
||||||
|
<Dialog v-model="dialogVisible2" :title="t('dialogDemo.dialog')">
|
||||||
|
<Form ref="formRef" :schema="schema" />
|
||||||
|
<template #footer>
|
||||||
|
<ElButton type="primary" @click="formSubmit">{{ t('dialogDemo.submit') }}</ElButton>
|
||||||
|
<ElButton @click="dialogVisible2 = false">{{ t('dialogDemo.close') }}</ElButton>
|
||||||
|
</template>
|
||||||
|
</Dialog>
|
||||||
</ContentWrap>
|
</ContentWrap>
|
||||||
</template>
|
</template>
|
||||||
|
|
Loading…
Reference in New Issue