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:
parent
c8616ebbf3
commit
144845073a
@ -57,7 +57,7 @@ export const useCrud = ({ name, initForm = {}, doCreate, doDelete, doUpdate, ref
|
|||||||
if (!action && !['edit', 'add'].includes(modalAction.value)) {
|
if (!action && !['edit', 'add'].includes(modalAction.value)) {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
if (!(await validation())) return false
|
await validation()
|
||||||
const actions = {
|
const actions = {
|
||||||
add: {
|
add: {
|
||||||
api: () => doCreate(modalForm.value),
|
api: () => doCreate(modalForm.value),
|
||||||
|
@ -9,14 +9,6 @@
|
|||||||
export const useForm = (initFormData = {}) => {
|
export const useForm = (initFormData = {}) => {
|
||||||
const formRef = ref(null)
|
const formRef = ref(null)
|
||||||
const formModel = ref({ ...initFormData })
|
const formModel = ref({ ...initFormData })
|
||||||
async function validation() {
|
|
||||||
try {
|
|
||||||
await formRef.value?.validate()
|
|
||||||
return true
|
|
||||||
} catch (error) {
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
}
|
|
||||||
const rules = {
|
const rules = {
|
||||||
required: {
|
required: {
|
||||||
required: true,
|
required: true,
|
||||||
@ -24,5 +16,8 @@ export const useForm = (initFormData = {}) => {
|
|||||||
trigger: ['blur', 'change'],
|
trigger: ['blur', 'change'],
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
const validation = () => {
|
||||||
|
return formRef.value?.validate()
|
||||||
|
}
|
||||||
return [formRef, formModel, validation, rules]
|
return [formRef, formModel, validation, rules]
|
||||||
}
|
}
|
||||||
|
@ -177,7 +177,7 @@ function handleOpen(options = {}) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async function onSave() {
|
async function onSave() {
|
||||||
if (!(await validation())) return
|
await validation()
|
||||||
okLoading.value = true
|
okLoading.value = true
|
||||||
try {
|
try {
|
||||||
if (!modalForm.value.parentId) modalForm.value.parentId = null
|
if (!modalForm.value.parentId) modalForm.value.parentId = null
|
||||||
|
@ -113,7 +113,7 @@ const [pwdModalRef] = useModal()
|
|||||||
const [pwdFormRef, pwdForm, pwdValidation] = useForm()
|
const [pwdFormRef, pwdForm, pwdValidation] = useForm()
|
||||||
|
|
||||||
async function handlePwdSave() {
|
async function handlePwdSave() {
|
||||||
if (!(await pwdValidation())) return false
|
await pwdValidation()
|
||||||
await api.changePassword(pwdForm.value)
|
await api.changePassword(pwdForm.value)
|
||||||
$message.success('密码修改成功')
|
$message.success('密码修改成功')
|
||||||
userStore.getUserInfo()
|
userStore.getUserInfo()
|
||||||
@ -145,7 +145,7 @@ const [profileFormRef, profileForm, profileValidation] = useForm({
|
|||||||
email: userStore.userInfo?.email,
|
email: userStore.userInfo?.email,
|
||||||
})
|
})
|
||||||
async function handleProfileSave() {
|
async function handleProfileSave() {
|
||||||
if (!(await profileValidation())) return false
|
await profileValidation()
|
||||||
await api.updateProfile(profileForm.value)
|
await api.updateProfile(profileForm.value)
|
||||||
$message.success('资料修改成功')
|
$message.success('资料修改成功')
|
||||||
userStore.getUserInfo()
|
userStore.getUserInfo()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user