From 3959e507bfa99cc4ced2a6f48f9b4358334d34c4 Mon Sep 17 00:00:00 2001 From: riku <risaku@163.com> Date: 星期二, 19 十二月 2023 17:34:45 +0800 Subject: [PATCH] 1. 调试表单选项组件的双向绑定逻辑 --- src/components/form/FYForm.vue | 42 +++++++++++++++++++++++++++++++++++------- 1 files changed, 35 insertions(+), 7 deletions(-) diff --git a/src/components/form/FYForm.vue b/src/components/form/FYForm.vue index 42cf198..5bfa1b8 100644 --- a/src/components/form/FYForm.vue +++ b/src/components/form/FYForm.vue @@ -3,7 +3,7 @@ :inline="false" :model="formObj" ref="formRef" - :rules="rules" + :rules="allRules" label-position="right" label-width="150px" > @@ -26,7 +26,7 @@ * 鍙紶鍏ュ垵濮嬭〃鍗曟暟鎹甪ormInfo锛岃〃鍗曟牎楠岃鍒檙ules * 瀹炵幇submit鍜宑ancel瑙﹀彂鍑芥暟 */ -import { defineProps, defineEmits, reactive, ref, watch } from 'vue'; +import { defineProps, defineEmits, reactive, ref, watch, computed } from 'vue'; import { useFormConfirm } from '@/composables/formConfirm'; const props = defineProps({ @@ -43,7 +43,7 @@ //閲嶇疆鎸夐挳鏄惁鍙敤 useReset: Boolean, //瑙﹀彂閲嶇疆 - reset: Boolean, + doClear: Boolean, //閫氱煡缂栬緫鐘舵�� isEdit: Boolean }); @@ -51,8 +51,32 @@ //瑙﹀彂鍑芥暟锛屾彁浜ゅ拰鍙栨秷 const emit = defineEmits(['submit', 'cancel', 'update:isEdit']); +const baseRules = reactive({ + _usertype: [ + { + required: true, + message: '鐢ㄦ埛绫诲瀷涓嶈兘涓虹┖', + trigger: 'change' + } + ], + _locations: [ + { + required: true, + message: '鐪�/甯�/鍖�/闀囦笉鑳戒负绌�', + trigger: 'change', + } + ], + _scenetype: [ + { + required: true, + message: '鍦烘櫙绫诲瀷涓嶈兘涓虹┖', + trigger: 'change' + } + ] +}); + //琛ㄥ崟鎿嶄綔鍑芥暟 -const { formObj, formRef, edit, onSubmit, onCancel, onReset, formProps } = useFormConfirm({ +const { formObj, formRef, edit, onSubmit, onCancel, onReset, clear } = useFormConfirm({ submit: { do: submit }, @@ -83,21 +107,25 @@ emit('cancel'); } +const allRules = computed(()=>{ + return {...baseRules.value, ...props.rules} +}) + //鐩戝惉琛ㄥ崟鍒濆鏁版嵁浼犲叆 watch( () => props.formInfo, (nValue) => { formObj.value = nValue; }, - { deep: false, immediate: false } + { deep: false, immediate: true } ); //鐩戝惉琛ㄥ崟閲嶇疆鍔熻兘瑙﹀彂 watch( - () => props.reset, + () => props.doClear, (nValue) => { if (nValue) { - onReset(); + clear(); } } ); -- Gitblit v1.9.3