1
0
mirror of https://github.com/zclzone/vue-naive-admin.git synced 2026-01-22 23:50:22 +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]
}