fix: 优化watch 修改编辑用户弹窗样式

This commit is contained in:
ZhuRui
2026-07-27 09:51:30 +08:00
parent 17d5c85904
commit e3e66ec03b
11 changed files with 146 additions and 161 deletions
@@ -1,4 +1,5 @@
import { defineComponent, ref, reactive, watch } from 'vue';
import { defineComponent, ref, reactive } from 'vue';
import { useEffect } from '@/hooks';
import {
Modal,
Form,
@@ -119,33 +120,27 @@ export default defineComponent({
};
/** 监听 visible 变化重置表单 */
watch(
() => props.visible,
(val) => {
if (val) {
initFormFromRecord(props.record);
cropperVisible.value = false;
uploadImageUrl.value = '';
setTimeout(() => formRef.value?.clearValidate(), 0);
}
},
{ immediate: true },
);
useEffect(() => {
if (props.visible) {
initFormFromRecord(props.record);
cropperVisible.value = false;
uploadImageUrl.value = '';
setTimeout(() => formRef.value?.clearValidate(), 0);
}
}, [() => props.visible]);
/** 监听 jumpType 变化时清理联动字段 */
watch(
() => formData.jumpType,
(newType) => {
if (newType !== 'event_detail') formData.relatedEventId = '';
if (newType !== 'miniprogram_page') formData.pagePath = '';
if (newType !== 'custom_link') formData.customUrl = '';
const fieldsToValidate: string[] = [];
if (newType === 'event_detail') fieldsToValidate.push('relatedEventId');
if (newType === 'miniprogram_page') fieldsToValidate.push('pagePath');
if (newType === 'custom_link') fieldsToValidate.push('customUrl');
if (fieldsToValidate.length) formRef.value?.clearValidate(fieldsToValidate);
},
);
useEffect(() => {
const newType = formData.jumpType;
if (newType !== 'event_detail') formData.relatedEventId = '';
if (newType !== 'miniprogram_page') formData.pagePath = '';
if (newType !== 'custom_link') formData.customUrl = '';
const fieldsToValidate: string[] = [];
if (newType === 'event_detail') fieldsToValidate.push('relatedEventId');
if (newType === 'miniprogram_page') fieldsToValidate.push('pagePath');
if (newType === 'custom_link') fieldsToValidate.push('customUrl');
if (fieldsToValidate.length) formRef.value?.clearValidate(fieldsToValidate);
}, [() => formData.jumpType]);
/** 触发隐藏的文件选择器 */
const triggerFilePicker = () => {