1
0
mirror of https://github.com/zclzone/vue-naive-admin.git synced 2025-05-01 06:39:01 +08:00

fix: 表单校验失败会关闭弹窗问题

This commit is contained in:
zclzone 2023-12-14 17:01:53 +08:00
parent c8616ebbf3
commit 144845073a
4 changed files with 7 additions and 12 deletions

View File

@ -57,7 +57,7 @@ export const useCrud = ({ name, initForm = {}, doCreate, doDelete, doUpdate, ref
if (!action && !['edit', 'add'].includes(modalAction.value)) {
return false
}
if (!(await validation())) return false
await validation()
const actions = {
add: {
api: () => doCreate(modalForm.value),

View File

@ -9,14 +9,6 @@
export const useForm = (initFormData = {}) => {
const formRef = ref(null)
const formModel = ref({ ...initFormData })
async function validation() {
try {
await formRef.value?.validate()
return true
} catch (error) {
return false
}
}
const rules = {
required: {
required: true,
@ -24,5 +16,8 @@ export const useForm = (initFormData = {}) => {
trigger: ['blur', 'change'],
},
}
const validation = () => {
return formRef.value?.validate()
}
return [formRef, formModel, validation, rules]
}

View File

@ -177,7 +177,7 @@ function handleOpen(options = {}) {
}
async function onSave() {
if (!(await validation())) return
await validation()
okLoading.value = true
try {
if (!modalForm.value.parentId) modalForm.value.parentId = null

View File

@ -113,7 +113,7 @@ const [pwdModalRef] = useModal()
const [pwdFormRef, pwdForm, pwdValidation] = useForm()
async function handlePwdSave() {
if (!(await pwdValidation())) return false
await pwdValidation()
await api.changePassword(pwdForm.value)
$message.success('密码修改成功')
userStore.getUserInfo()
@ -145,7 +145,7 @@ const [profileFormRef, profileForm, profileValidation] = useForm({
email: userStore.userInfo?.email,
})
async function handleProfileSave() {
if (!(await profileValidation())) return false
await profileValidation()
await api.updateProfile(profileForm.value)
$message.success('资料修改成功')
userStore.getUserInfo()