<template>
|
<ElDialog
|
:title="dialogTitle"
|
:model-value="visible"
|
width="820px"
|
align-center
|
@update:model-value="handleCancel"
|
@closed="handleClosed"
|
>
|
<ArtForm
|
ref="formRef"
|
v-model="form"
|
:items="formItems"
|
:rules="rules"
|
:span="12"
|
:gutter="20"
|
label-width="100px"
|
:show-reset="false"
|
:show-submit="false"
|
/>
|
|
<template #footer>
|
<span class="dialog-footer">
|
<ElButton @click="handleCancel">{{ t('common.cancel') }}</ElButton>
|
<ElButton type="primary" @click="handleSubmit">{{ t('common.confirm') }}</ElButton>
|
</span>
|
</template>
|
</ElDialog>
|
</template>
|
|
<script setup>
|
import { useI18n } from 'vue-i18n'
|
import ArtForm from '@/components/core/forms/art-form/index.vue'
|
import { buildDictTypeDialogModel, createDictTypeFormState } from '../dictTypePage.helpers'
|
|
const props = defineProps({
|
visible: { type: Boolean, default: false },
|
dictTypeData: { type: Object, default: () => ({}) }
|
})
|
|
const emit = defineEmits(['update:visible', 'submit'])
|
const formRef = ref()
|
const form = reactive(createDictTypeFormState())
|
const { t } = useI18n()
|
|
const isEdit = computed(() => Boolean(form.id))
|
const dialogTitle = computed(() =>
|
isEdit.value ? t('pages.system.dictType.dialog.titleEdit') : t('pages.system.dictType.dialog.titleCreate')
|
)
|
|
const rules = computed(() => ({
|
code: [{ required: true, message: t('pages.system.dictType.validation.code'), trigger: 'blur' }],
|
name: [{ required: true, message: t('pages.system.dictType.validation.name'), trigger: 'blur' }]
|
}))
|
|
const formItems = computed(() => [
|
{
|
label: t('table.code'),
|
key: 'code',
|
type: 'input',
|
props: {
|
clearable: true,
|
placeholder: t('pages.system.dictType.placeholders.code')
|
}
|
},
|
{
|
label: t('table.name'),
|
key: 'name',
|
type: 'input',
|
props: {
|
clearable: true,
|
placeholder: t('pages.system.dictType.placeholders.name')
|
}
|
},
|
{
|
label: t('table.status'),
|
key: 'status',
|
type: 'select',
|
props: {
|
options: [
|
{ label: t('common.status.normal'), value: 1 },
|
{ label: t('common.status.frozen'), value: 0 }
|
],
|
placeholder: t('pages.system.dictType.placeholders.status')
|
}
|
},
|
{
|
label: t('pages.system.dictType.table.description'),
|
key: 'description',
|
type: 'input',
|
span: 24,
|
props: {
|
type: 'textarea',
|
rows: 3,
|
placeholder: t('pages.system.dictType.placeholders.description')
|
}
|
},
|
{
|
label: t('table.memo'),
|
key: 'memo',
|
type: 'input',
|
span: 24,
|
props: {
|
type: 'textarea',
|
rows: 3,
|
placeholder: t('pages.system.dictType.placeholders.memo')
|
}
|
}
|
])
|
|
function resetForm() {
|
Object.assign(form, createDictTypeFormState())
|
formRef.value?.clearValidate?.()
|
}
|
|
function loadFormData() {
|
Object.assign(form, buildDictTypeDialogModel(props.dictTypeData))
|
}
|
|
async function handleSubmit() {
|
if (!formRef.value) return
|
try {
|
await formRef.value.validate()
|
emit('submit', { ...form })
|
} catch {
|
return
|
}
|
}
|
|
function handleCancel() {
|
emit('update:visible', false)
|
}
|
|
function handleClosed() {
|
resetForm()
|
}
|
|
watch(
|
() => props.visible,
|
(visible) => {
|
if (visible) {
|
loadFormData()
|
nextTick(() => formRef.value?.clearValidate?.())
|
}
|
},
|
{ immediate: true }
|
)
|
|
watch(
|
() => props.dictTypeData,
|
() => {
|
if (props.visible) {
|
loadFormData()
|
}
|
},
|
{ deep: true }
|
)
|
</script>
|