From 21ade9b9ac059ac18ccba224d08803474825a6ea Mon Sep 17 00:00:00 2001 From: cherishsince Date: Wed, 10 Jul 2024 09:12:11 +0800 Subject: [PATCH] =?UTF-8?q?=E3=80=90=E8=A7=A3=E5=86=B3todo=E3=80=91role=20?= =?UTF-8?q?=E8=A7=92=E8=89=B2=E8=A1=A8=E5=8D=95=EF=BC=8C=E8=A7=84=E5=88=99?= =?UTF-8?q?=E6=94=B9=E4=B8=BA=20formRules?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/views/ai/model/chatRole/ChatRoleForm.vue | 26 ++++++++------------ 1 file changed, 10 insertions(+), 16 deletions(-) diff --git a/src/views/ai/model/chatRole/ChatRoleForm.vue b/src/views/ai/model/chatRole/ChatRoleForm.vue index 7815fd85..3c49e8ed 100644 --- a/src/views/ai/model/chatRole/ChatRoleForm.vue +++ b/src/views/ai/model/chatRole/ChatRoleForm.vue @@ -69,6 +69,7 @@ import { getIntDictOptions, getBoolDictOptions, DICT_TYPE } from '@/utils/dict' import { ChatRoleApi, ChatRoleVO } from '@/api/ai/model/chatRole' import { CommonStatusEnum } from '@/utils/constants' import { ChatModelApi, ChatModelVO } from '@/api/ai/model/chatModel' +import {FormRules} from "element-plus"; /** AI 聊天角色 表单 */ defineOptions({ name: 'ChatRoleForm' }) @@ -92,7 +93,6 @@ const formData = ref({ publicStatus: true, status: CommonStatusEnum.ENABLE }) -const formRules = ref() // reactive(formRulesObj) const formRef = ref() // 表单 Ref const chatModelList = ref([] as ChatModelVO[]) // 聊天模型列表 @@ -101,20 +101,15 @@ const isUser = computed(() => { return formType.value === 'my-create' || formType.value === 'my-update' }) -// TODO @fan:直接使用 formRules;只要隐藏掉的字段,它是不会校验的哈; -const getFormRules = async (type: string) => { - let formRulesObj = { - name: [{ required: true, message: '角色名称不能为空', trigger: 'blur' }], - avatar: [{ required: true, message: '角色头像不能为空', trigger: 'blur' }], - category: [{ required: true, message: '角色类别不能为空', trigger: 'blur' }], - sort: [{ required: true, message: '角色排序不能为空', trigger: 'blur' }], - description: [{ required: true, message: '角色描述不能为空', trigger: 'blur' }], - systemMessage: [{ required: true, message: '角色设定不能为空', trigger: 'blur' }], - publicStatus: [{ required: true, message: '是否公开不能为空', trigger: 'blur' }] - } - - formRules.value = reactive(formRulesObj) -} +const formRules = reactive({ + name: [{ required: true, message: '角色名称不能为空', trigger: 'blur' }], + avatar: [{ required: true, message: '角色头像不能为空', trigger: 'blur' }], + category: [{ required: true, message: '角色类别不能为空', trigger: 'blur' }], + sort: [{ required: true, message: '角色排序不能为空', trigger: 'blur' }], + description: [{ required: true, message: '角色描述不能为空', trigger: 'blur' }], + systemMessage: [{ required: true, message: '角色设定不能为空', trigger: 'blur' }], + publicStatus: [{ required: true, message: '是否公开不能为空', trigger: 'blur' }] +}) /** 打开弹窗 */ // TODO @fan:title 是不是收敛到 type 判断生成 title,会更合理 @@ -122,7 +117,6 @@ const open = async (type: string, id?: number, title?: string) => { dialogVisible.value = true dialogTitle.value = title || t('action.' + type) formType.value = type - getFormRules(type) resetForm() // 修改时,设置数据 if (id) {