♻️ 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,21 +104,30 @@ const onCancel = () => {
}; };
// //
const onSubmit = () => { const onSubmit = () => {
if (dataForm.id) { dicDialogFormRef.value.validate((valid: boolean) => {
putItemObj(dataForm).then(() => { if (!valid) {
closeDialog(); // return false
emit('refresh'); }
}).catch(err => { if (dataForm.id) {
useMessage().error(err.msg) putItemObj(dataForm).then(() => {
}) closeDialog(); //
} else { emit('refresh');
addItemObj(dataForm).then(() => { }).catch(err => {
closeDialog(); // useMessage().error(err.msg)
emit('refresh'); })
}).catch(err => { } else {
useMessage().error(err.msg) addItemObj(dataForm).then(() => {
}) closeDialog(); //
} emit('refresh');
}).catch(err => {
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,21 +94,27 @@ const onCancel = () => {
}; };
// //
const onSubmit = () => { const onSubmit = () => {
if (dataForm.id) { dicDialogFormRef.value.validate((valid: boolean) => {
putObj(dataForm).then(() => { if (!valid) {
closeDialog(); // return false
emit('refresh'); }
}).catch(err => { if (dataForm.id) {
useMessage().error(err.msg) putObj(dataForm).then(() => {
}) closeDialog(); //
}else{ emit('refresh');
addObj(dataForm).then(() => { }).catch(err => {
closeDialog(); // useMessage().error(err.msg)
emit('refresh'); })
}).catch(err => { }else{
useMessage().error(err.msg) addObj(dataForm).then(() => {
}) closeDialog(); //
} emit('refresh');
}).catch(err => {
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(",")