1
0
mirror of synced 2025-11-06 04:20:54 +08:00

新增编辑保存添加校验

This commit is contained in:
qianlishi
2025-01-11 21:35:14 +08:00
parent 8ed1cab563
commit d885f21642
3 changed files with 21 additions and 6 deletions

View File

@@ -1,5 +1,5 @@
<template>
<basicModal @register="register" @onOk='handleSubmit' @onClose="close">
<basicModal @register="register" @onOk='validateForm(formElRef, handleSubmit)' @onClose="close">
<n-form
class="form"
v-bind="getBindValue"
@@ -79,6 +79,7 @@
import { DialogType, DialogTitle } from '@/enums/common'
import { JsqSelect } from '@/components/Base/Jsq-select';
import type { FormInst } from 'naive-ui'
import { useMessage } from 'naive-ui'
import { isFunction, isNullOrUnDef } from '@/utils/is';
@@ -96,7 +97,7 @@
const defaultFormModel = ref<any>({});
const formModel = reactive<Recordable>({})
const dialogType = ref<DialogType>(DialogType.ADD)
const formElRef = ref()
const formElRef = ref<FormInst | null>(null)
const rowData = ref<object>({})
const getBindValue = computed(() => ({ ...attrs} as Recordable));
@@ -145,6 +146,19 @@
handleClose()
}
// 校验
const validateForm = (formRefName: FormInst | null, callback: () => void) => {
formRefName?.validate((errors) => {
if (!errors) {
callback()
}
else {
console.log(errors)
messages.error('验证失败')
}
})
}
const handleClose = () => {
resetFields()
closeModal()

View File

@@ -3,7 +3,7 @@
* @Author: qianlishi
* @Date: 2024-12-30 18:16:00
* @LastEditors: qianlishi
* @LastEditTime: 2025-01-03 00:30:16
* @LastEditTime: 2025-01-11 20:18:56
*/
import { selectProps } from 'naive-ui';
@@ -24,5 +24,5 @@ export const basicProps = {
size: {
type: String,
default: 'small'
}
},
};

View File

@@ -3,7 +3,7 @@
* @Author: qianlishi
* @Date: 2025-01-03 01:01:14
* @LastEditors: qianlishi
* @LastEditTime: 2025-01-10 16:49:28
* @LastEditTime: 2025-01-11 21:34:22
*/
import { computed, h } from 'vue';
import { cloneDeep } from 'lodash-es';
@@ -12,6 +12,7 @@ import { NButton, NTag } from 'naive-ui'
import { editFormShow, enable } from '@/enums/common'
import { FormSchema } from '@/components/Base/Jsq-crud/src/components/Jsq-searchForm';
import { getAuthorityTree } from '@/api/access/accessAuthority';
import { number } from 'vue-types';
// tree配置
export const getTreeOptions = () => {
@@ -168,7 +169,7 @@ export const getDialogRecordingSchemas = () => {
dictCode: 'ENABLE_FLAG',
},
rules: [
{ required: true, message: "启用状态必填", trigger: ['blur', 'change'] }
{ required: true, type: 'number', message: "启用状态必填", trigger: 'change' }
],
},
{