|
|
@@ -59,7 +59,7 @@
|
|
|
<!-- 编辑/新增模式 -->
|
|
|
<div v-else class="edit-container">
|
|
|
<!-- 动态渲染topFormSchema字段(编辑/新增模式) -->
|
|
|
- <div class="mine-base-info" v-if="mode === 'add'">
|
|
|
+ <div class="mine-base-info" v-if="mode === 'add' ">
|
|
|
<a-form-item
|
|
|
v-for="schema in topFormSchema"
|
|
|
:key="schema.field"
|
|
|
@@ -69,7 +69,7 @@
|
|
|
>
|
|
|
<component
|
|
|
:is="getComponent(schema.component)"
|
|
|
- v-model:value="currentRecord[schema.field]"
|
|
|
+ v-model:value="formData[schema.field]"
|
|
|
v-bind="schema.componentProps"
|
|
|
:placeholder="`请输入${schema.label}`"
|
|
|
style="width: 100%"
|
|
|
@@ -221,13 +221,13 @@ const formRules = reactive({
|
|
|
|
|
|
// 监听queList变化,同步到formData
|
|
|
watch(queList, (newVal) => {
|
|
|
- formData.queList = newVal;
|
|
|
-}, { deep: true });
|
|
|
+ formData.queList = JSON.parse(JSON.stringify(newVal));
|
|
|
+}, { deep: true, immediate: true });
|
|
|
|
|
|
// 监听currentRecord变化,同步mineCode到formData
|
|
|
watch(() => currentRecord.value.mineCode, (newVal) => {
|
|
|
formData.mineCode = newVal;
|
|
|
-});
|
|
|
+}, { immediate: true });
|
|
|
|
|
|
// 根据组件名获取对应组件
|
|
|
const getComponent = (componentName: string) => {
|
|
|
@@ -257,7 +257,7 @@ const [registerModal, { setModalProps, closeModal }] = useModalInner(async (data
|
|
|
// 接收模式参数
|
|
|
mode.value = data?.mode || 'view';
|
|
|
// 初始化当前记录
|
|
|
- currentRecord.value = data?.record ? { ...data.record } : {
|
|
|
+ currentRecord.value = data?.record ? JSON.parse(JSON.stringify(data.record)) : {
|
|
|
mineCode: '',
|
|
|
mineLinkStatus: '0',
|
|
|
queJson: [],
|
|
|
@@ -279,32 +279,34 @@ const [registerModal, { setModalProps, closeModal }] = useModalInner(async (data
|
|
|
endTime: null,
|
|
|
param: ''
|
|
|
}];
|
|
|
+ formData.queList = JSON.parse(JSON.stringify(queList.value));
|
|
|
+ if (formRef.value) {
|
|
|
+ formRef.value.resetFields();
|
|
|
+ }
|
|
|
} else {
|
|
|
// 编辑/查看模式:解析已有问题数据
|
|
|
try {
|
|
|
const rawData = currentRecord.value?.queJson
|
|
|
? (typeof currentRecord.value.queJson === 'string'
|
|
|
- ? JSON.parse(currentRecord.value.queJson)
|
|
|
+ ? (currentRecord.value.queJson.trim() ? JSON.parse(currentRecord.value.queJson) : []) // 兼容空字符串
|
|
|
: currentRecord.value.queJson)
|
|
|
: [];
|
|
|
- // 转换日期格式为dayjs对象(适配DatePicker)
|
|
|
+ // 兼容日期格式,避免转换失败
|
|
|
queList.value = rawData.map((item: any) => ({
|
|
|
...item,
|
|
|
- startTime: item.startTime ? dayjs(item.startTime) : null,
|
|
|
- endTime: item.endTime ? dayjs(item.endTime) : null
|
|
|
+ startTime: item.startTime ? dayjs(item.startTime, ['YYYY-MM-DD HH:mm:ss', 'YYYY-MM-DD']) : null,
|
|
|
+ endTime: item.endTime ? dayjs(item.endTime, ['YYYY-MM-DD HH:mm:ss', 'YYYY-MM-DD']) : null
|
|
|
}));
|
|
|
- // 同步到formData
|
|
|
- formData.queList = queList.value;
|
|
|
+ // 深拷贝同步到formData,切断引用
|
|
|
+ formData.queList = JSON.parse(JSON.stringify(queList.value));
|
|
|
} catch (error) {
|
|
|
console.error('解析问题数据失败:', error);
|
|
|
- queList.value = [{
|
|
|
- orderNum: '1',
|
|
|
- goafName: '',
|
|
|
- queCon: '',
|
|
|
- startTime: null,
|
|
|
- endTime: null,
|
|
|
- param: ''
|
|
|
- }];
|
|
|
+ message.warning('问题数据格式异常,将显示原始数据');
|
|
|
+ // 保留原始queJson,而非重置为空数据
|
|
|
+ queList.value = currentRecord.value?.queJson
|
|
|
+ ? (typeof currentRecord.value.queJson === 'string' ? [] : currentRecord.value.queJson)
|
|
|
+ : [];
|
|
|
+ formData.queList = JSON.parse(JSON.stringify(queList.value));
|
|
|
}
|
|
|
}
|
|
|
// 重置表单校验状态
|