♻️ Refactoring code. 增加字典管理和参数管理表单校验

This commit is contained in:
aeizzz 2023-02-10 09:18:56 +08:00
parent 117ba1832e
commit 8b0bb1af7e
5 changed files with 75 additions and 41 deletions

View File

@ -30,7 +30,7 @@
<el-table-column :label="t('client.clientId')" prop="clientId" show-overflow-tooltip/> <el-table-column :label="t('client.clientId')" prop="clientId" show-overflow-tooltip/>
<el-table-column :label="t('client.clientSecret')" prop="clientSecret" show-overflow-tooltip/> <el-table-column :label="t('client.clientSecret')" prop="clientSecret" show-overflow-tooltip/>
<el-table-column :label="t('client.scope')" prop="scope" show-overflow-tooltip/> <el-table-column :label="t('client.scope')" prop="scope" show-overflow-tooltip/>
<el-table-column :label="t('client.authorizedGrantTypes')" prop="authorizedGrantTypes" show-overflow-tooltip> <el-table-column :label="t('client.authorizedGrantTypes')" prop="authorizedGrantTypes" show-overflow-tooltip width="600px">
<template #default="scope"> <template #default="scope">
<dict-tag :options="grant_types" :value="scope.row.authorizedGrantTypes"></dict-tag> <dict-tag :options="grant_types" :value="scope.row.authorizedGrantTypes"></dict-tag>
</template> </template>

View File

@ -1,7 +1,7 @@
<template> <template>
<div class="system-dic-dialog-container"> <div class="system-dic-dialog-container">
<el-dialog v-model="visible" :title="dataForm.id ? $t('common.editBtn') : $t('common.addBtn')" width="60%"> <el-dialog v-model="visible" :title="dataForm.id ? $t('common.editBtn') : $t('common.addBtn')" width="60%">
<el-form ref="dicDialogFormRef" :model="dataForm" label-width="90px" size="default"> <el-form ref="dicDialogFormRef" :model="dataForm" label-width="90px" size="default" :rules="dataRules">
<el-row :gutter="35"> <el-row :gutter="35">
<el-col :lg="12" :md="12" :sm="12" :xl="12" :xs="24" class="mb20" v-if="dataForm.id"> <el-col :lg="12" :md="12" :sm="12" :xl="12" :xs="24" class="mb20" v-if="dataForm.id">
<el-form-item label="类型" prop="dictType"> <el-form-item label="类型" prop="dictType">
@ -28,7 +28,7 @@
<el-input-number v-model="dataForm.sortOrder" placeholder="请输入排序" clearable></el-input-number> <el-input-number v-model="dataForm.sortOrder" placeholder="请输入排序" clearable></el-input-number>
</el-form-item> </el-form-item>
</el-col> </el-col>
<el-col :lg="12" :md="12" :sm="12" :xl="12" :xs="24" class="mb20"> <el-col :span="24" class="mb20">
<el-form-item label="备注信息" prop="remarks"> <el-form-item label="备注信息" prop="remarks">
<el-input v-model="dataForm.remarks" type="textarea" placeholder="请输入字典描述" maxlength="150"></el-input> <el-input v-model="dataForm.remarks" type="textarea" placeholder="请输入字典描述" maxlength="150"></el-input>
</el-form-item> </el-form-item>
@ -69,7 +69,12 @@ const dataForm = reactive({
}) })
const dataRules = reactive({}) const dataRules = reactive({
value: [{ required: true, message: '数据值不能为空', trigger: 'blur' }],
label: [{ required: true, message: '标签不能为空', trigger: 'blur' }],
description: [{ required: true, message: '描述不能为空', trigger: 'blur' }],
sortOrder: [{ required: true, message: '排序不能为空', trigger: 'blur' }],
})
// //
@ -99,6 +104,10 @@ const onCancel = () => {
}; };
// //
const onSubmit = () => { const onSubmit = () => {
dicDialogFormRef.value.validate((valid: boolean) => {
if (!valid) {
return false
}
if (dataForm.id) { if (dataForm.id) {
putItemObj(dataForm).then(() => { putItemObj(dataForm).then(() => {
closeDialog(); // closeDialog(); //
@ -114,6 +123,11 @@ const onSubmit = () => {
useMessage().error(err.msg) useMessage().error(err.msg)
}) })
} }
})
}; };
// //
defineExpose({ defineExpose({

View File

@ -1,7 +1,7 @@
<template> <template>
<div class="system-dic-dialog-container"> <div class="system-dic-dialog-container">
<el-dialog v-model="visible" :title="dataForm.id ? $t('common.editBtn') : $t('common.addBtn')" width="60%"> <el-dialog v-model="visible" :title="dataForm.id ? $t('common.editBtn') : $t('common.addBtn')" width="60%">
<el-form ref="dicDialogFormRef" :model="dataForm" label-width="90px" size="default"> <el-form ref="dicDialogFormRef" :model="dataForm" label-width="90px" size="default" :rules="dataRules">
<el-row :gutter="35"> <el-row :gutter="35">
<el-col :lg="12" :md="12" :sm="12" :xl="12" :xs="24" class="mb20"> <el-col :lg="12" :md="12" :sm="12" :xl="12" :xs="24" class="mb20">
<el-form-item label="类型" prop="dictType"> <el-form-item label="类型" prop="dictType">
@ -56,12 +56,16 @@ const dataForm = reactive({
id: '', id: '',
dictType: '', dictType: '',
description: '', description: '',
systemFlag: '', systemFlag: '0',
remarks: '', remarks: '',
}) })
const dataRules = reactive({}) const dataRules = reactive({
dictType: [{ required: true, message: '类型不能为空', trigger: 'blur' }],
systemFlag: [{ required: true, message: '字典类型不能为空', trigger: 'blur' }],
description: [{ required: true, message: '描述不能为空', trigger: 'blur' }],
})
// //
@ -90,6 +94,10 @@ const onCancel = () => {
}; };
// //
const onSubmit = () => { const onSubmit = () => {
dicDialogFormRef.value.validate((valid: boolean) => {
if (!valid) {
return false
}
if (dataForm.id) { if (dataForm.id) {
putObj(dataForm).then(() => { putObj(dataForm).then(() => {
closeDialog(); // closeDialog(); //
@ -105,6 +113,8 @@ const onSubmit = () => {
useMessage().error(err.msg) useMessage().error(err.msg)
}) })
} }
})
}; };
// //
defineExpose({ defineExpose({

View File

@ -88,14 +88,21 @@ const form = reactive({
publicName: '', publicName: '',
publicKey: '', publicKey: '',
publicValue: '', publicValue: '',
status: '', status: '0',
validateCode: '', validateCode: '',
publicType: '', publicType: '',
systemFlag: '', systemFlag: '0',
}); });
// //
const dataRules = ref({}) const dataRules = reactive({
publicName: [{ required: true, message: '名称不能为空', trigger: 'blur' }],
publicKey: [{ required: true, message: '参数键不能为空', trigger: 'blur' }],
publicValue: [{ required: true, message: '参数值不能为空', trigger: 'blur' }],
status: [{ required: true, message: '状态不能为空', trigger: 'blur' }],
validateCode: [{ required: true, message: '编码不能为空', trigger: 'blur' }],
publicType: [{ required: true, message: '类型不能为空', trigger: 'blur' }],
})
// //
const openDialog = (id: string) => { const openDialog = (id: string) => {

View File

@ -64,7 +64,9 @@ const form = reactive({
}); });
const dataRules = reactive({ const dataRules = reactive({
name: [{ required: true, message: '套餐名称不能为空', trigger: 'blur' }],
status: [{ required: true, message: '套餐状态不能为空', trigger: 'blur' }],
menuIds: [{ required: true, message: '套餐菜单不能为空', trigger: 'blur' }]
}) })
const menuData = ref<any[]>([]) const menuData = ref<any[]>([])
@ -101,6 +103,7 @@ const onSubmit = () => {
loading.value = true loading.value = true
dataFormRef.value.validate((valid: boolean) => { dataFormRef.value.validate((valid: boolean) => {
if (!valid) { if (!valid) {
loading.value = false
return false return false
} }
form.menuIds = [...menuTreeRef.value.getCheckedKeys(),...menuTreeRef.value.getHalfCheckedKeys()].join(",") form.menuIds = [...menuTreeRef.value.getCheckedKeys(),...menuTreeRef.value.getHalfCheckedKeys()].join(",")