修复崩溃问题
This commit is contained in:
parent
f81e56e167
commit
7a7d550a77
|
|
@ -215,6 +215,8 @@ export default {
|
|||
},
|
||||
data() {
|
||||
return {
|
||||
// 当前编辑的ID
|
||||
currentEditId: null,
|
||||
formGroup,
|
||||
AEform: {
|
||||
formModel: {
|
||||
|
|
@ -242,12 +244,26 @@ export default {
|
|||
this.getMediaType();
|
||||
const rawData = await cityDataCache.getCityData();
|
||||
this.cityList = Object.freeze(rawData);
|
||||
|
||||
if (this.$route.query.id) {
|
||||
this.getDetailData()
|
||||
}
|
||||
},
|
||||
mounted() {
|
||||
if (this.$route.query.id) {
|
||||
this.getDetailData()
|
||||
}
|
||||
},
|
||||
watch: {
|
||||
'$route.query.id': {
|
||||
immediate: true,
|
||||
handler(newId) {
|
||||
if (newId !== this.currentEditId) {
|
||||
this.getDetailData();
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
computed: {
|
||||
contractMoney() {
|
||||
// 使用非响应式方式计算
|
||||
|
|
@ -263,53 +279,82 @@ export default {
|
|||
},
|
||||
},
|
||||
methods: {
|
||||
resetFormData() {
|
||||
this.AEform.formModel = {};
|
||||
this.mediaTableData = [];
|
||||
this.paymentTableData = [];
|
||||
|
||||
// 更新key强制重新渲染组件
|
||||
this.mediaTableKey = Date.now();
|
||||
this.paymentTableKey = Date.now();
|
||||
this.formKey = Date.now();
|
||||
|
||||
// 重置文件上传组件
|
||||
this.$nextTick(() => {
|
||||
const resetFileUpload = (ref) => {
|
||||
if (ref && ref.setFileList) {
|
||||
ref.setFileList([]);
|
||||
}
|
||||
};
|
||||
|
||||
resetFileUpload(this.$refs.contractAccess);
|
||||
resetFileUpload(this.$refs.detectPicAttr);
|
||||
resetFileUpload(this.$refs.upPrint);
|
||||
resetFileUpload(this.$refs.nextPrint);
|
||||
resetFileUpload(this.$refs.exchangePrint);
|
||||
resetFileUpload(this.$refs.mediaLink);
|
||||
});
|
||||
},
|
||||
async getDetailData() {
|
||||
try {
|
||||
const res = await getAction(`/system/purchase/${this.$route.query.id}`);
|
||||
if (this.$route.query.id) {
|
||||
this.resetFormData()
|
||||
this.currentEditId = this.$route.query.id;
|
||||
const res = await getAction(`/system/purchase/${this.$route.query.id}`);
|
||||
|
||||
// 使用浅拷贝避免深层响应式
|
||||
const formModel = { ...res.data };
|
||||
// 使用浅拷贝避免深层响应式
|
||||
const formModel = { ...res.data };
|
||||
|
||||
// 分离表格数据,使用 Object.freeze 防止响应式
|
||||
if (formModel.purchaseMediaVoList) {
|
||||
const mediaData = formModel.purchaseMediaVoList.map(item => ({
|
||||
...item,
|
||||
cityIds: item.cityIds ? item.cityIds.split(',').map(id => Number(id)) : []
|
||||
}));
|
||||
this.mediaTableData = Object.freeze(mediaData);
|
||||
delete formModel.purchaseMediaVoList;
|
||||
} else {
|
||||
this.mediaTableData = Object.freeze([]);
|
||||
// 分离表格数据,使用 Object.freeze 防止响应式
|
||||
if (formModel.purchaseMediaVoList) {
|
||||
const mediaData = formModel.purchaseMediaVoList.map(item => ({
|
||||
...item,
|
||||
cityIds: item.cityIds ? item.cityIds.split(',').map(id => Number(id)) : []
|
||||
}));
|
||||
this.mediaTableData = Object.freeze(mediaData);
|
||||
delete formModel.purchaseMediaVoList;
|
||||
} else {
|
||||
this.mediaTableData = Object.freeze([]);
|
||||
}
|
||||
|
||||
if (formModel.conPurchasePaymentVo) {
|
||||
this.paymentTableData = Object.freeze([...formModel.conPurchasePaymentVo]);
|
||||
delete formModel.conPurchasePaymentVo;
|
||||
} else {
|
||||
this.paymentTableData = Object.freeze([]);
|
||||
}
|
||||
|
||||
// 设置基础表单数据
|
||||
this.AEform.formModel = formModel;
|
||||
|
||||
// 延迟附件回显,避免阻塞主线程
|
||||
this.$nextTick(() => {
|
||||
if (this._isDestroyed) return;
|
||||
|
||||
const setFileList = (ref, list) => {
|
||||
if (ref && list) {
|
||||
ref.setFileList(list);
|
||||
}
|
||||
};
|
||||
|
||||
setFileList(this.$refs.contractAccess, res.data.contractAccessList);
|
||||
setFileList(this.$refs.detectPicAttr, res.data.detectPicAttrList);
|
||||
setFileList(this.$refs.upPrint, res.data.upPrintList);
|
||||
setFileList(this.$refs.nextPrint, res.data.nextPrintList);
|
||||
setFileList(this.$refs.exchangePrint, res.data.exchangePrintList);
|
||||
setFileList(this.$refs.mediaLink, res.data.mediaLinkList);
|
||||
});
|
||||
}
|
||||
|
||||
if (formModel.conPurchasePaymentVo) {
|
||||
this.paymentTableData = Object.freeze([...formModel.conPurchasePaymentVo]);
|
||||
delete formModel.conPurchasePaymentVo;
|
||||
} else {
|
||||
this.paymentTableData = Object.freeze([]);
|
||||
}
|
||||
|
||||
// 设置基础表单数据
|
||||
this.AEform.formModel = formModel;
|
||||
|
||||
// 延迟附件回显,避免阻塞主线程
|
||||
this.$nextTick(() => {
|
||||
if (this._isDestroyed) return;
|
||||
|
||||
const setFileList = (ref, list) => {
|
||||
if (ref && list) {
|
||||
ref.setFileList(list);
|
||||
}
|
||||
};
|
||||
|
||||
setFileList(this.$refs.contractAccess, res.data.contractAccessList);
|
||||
setFileList(this.$refs.detectPicAttr, res.data.detectPicAttrList);
|
||||
setFileList(this.$refs.upPrint, res.data.upPrintList);
|
||||
setFileList(this.$refs.nextPrint, res.data.nextPrintList);
|
||||
setFileList(this.$refs.exchangePrint, res.data.exchangePrintList);
|
||||
setFileList(this.$refs.mediaLink, res.data.mediaLinkList);
|
||||
});
|
||||
|
||||
} catch (error) {
|
||||
console.error('获取详情失败:', error);
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user