From dbecc8667b342fa97b3f8a6106f4278ba248bdcb Mon Sep 17 00:00:00 2001 From: wkc <978997012@qq.com> Date: Mon, 9 Mar 2026 09:17:26 +0800 Subject: [PATCH] =?UTF-8?q?fix(ui):=20=E4=BF=AE=E5=A4=8D=E4=BF=AE=E6=94=B9?= =?UTF-8?q?=E8=BF=BD=E8=B8=AA=E4=B8=8D=E7=94=9F=E6=95=88=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 将 Map 改为普通对象,确保 Vue 2 能检测变化 - 使用 添加新属性,触发响应式更新 - 使用 强制更新视图 - 同时修复全局配置和项目配置页面 --- ruoyi-ui/src/views/ccdi/modelParam/index.vue | 24 ++++++++++++------- .../components/detail/ParamConfig.vue | 24 ++++++++++++------- 2 files changed, 30 insertions(+), 18 deletions(-) diff --git a/ruoyi-ui/src/views/ccdi/modelParam/index.vue b/ruoyi-ui/src/views/ccdi/modelParam/index.vue index aafa824..a8cdd7a 100644 --- a/ruoyi-ui/src/views/ccdi/modelParam/index.vue +++ b/ruoyi-ui/src/views/ccdi/modelParam/index.vue @@ -56,8 +56,8 @@ export default { return { // 模型参数数据(按模型分组) modelGroups: [], - // 修改记录(记录哪些参数被修改过) - modifiedParams: new Map(), + // 修改记录(使用对象而非Map,确保Vue能检测变化) + modifiedParams: {}, // 保存状态 saving: false }; @@ -66,7 +66,7 @@ export default { /** 计算已修改参数数量 */ modifiedCount() { let count = 0; - this.modifiedParams.forEach(params => { + Object.values(this.modifiedParams).forEach(params => { count += params.size; }); return count; @@ -82,7 +82,7 @@ export default { const res = await listAllParams({ projectId: 0 }); this.modelGroups = res.data.models; // 清空修改记录 - this.modifiedParams.clear(); + this.modifiedParams = {}; } catch (error) { this.$message.error('加载参数失败:' + error.message); console.error('加载参数失败', error); @@ -91,10 +91,14 @@ export default { /** 标记参数为已修改 */ markAsModified(modelCode, row) { - if (!this.modifiedParams.has(modelCode)) { - this.modifiedParams.set(modelCode, new Set()); + // 使用 $set 确保 Vue 能检测到对象属性的新增 + if (!this.modifiedParams[modelCode]) { + this.$set(this.modifiedParams, modelCode, new Set()); } - this.modifiedParams.get(modelCode).add(row.paramCode); + this.modifiedParams[modelCode].add(row.paramCode); + + // 强制更新视图 + this.$forceUpdate(); }, /** 保存所有修改 */ @@ -111,8 +115,10 @@ export default { models: [] }; - this.modifiedParams.forEach((paramCodes, modelCode) => { + Object.entries(this.modifiedParams).forEach(([modelCode, paramCodes]) => { const modelGroup = this.modelGroups.find(m => m.modelCode === modelCode); + if (!modelGroup) return; + const modifiedParamList = modelGroup.params .filter(p => paramCodes.has(p.paramCode)) .map(p => ({ @@ -134,7 +140,7 @@ export default { await saveAllParams(saveDTO); this.$modal.msgSuccess('保存成功'); // 清空修改记录并重新加载 - this.modifiedParams.clear(); + this.modifiedParams = {}; await this.loadAllParams(); } catch (error) { if (error.response && error.response.data && error.response.data.msg) { diff --git a/ruoyi-ui/src/views/ccdiProject/components/detail/ParamConfig.vue b/ruoyi-ui/src/views/ccdiProject/components/detail/ParamConfig.vue index 077d924..eddb87a 100644 --- a/ruoyi-ui/src/views/ccdiProject/components/detail/ParamConfig.vue +++ b/ruoyi-ui/src/views/ccdiProject/components/detail/ParamConfig.vue @@ -61,8 +61,8 @@ export default { return { // 模型参数数据(按模型分组) modelGroups: [], - // 修改记录(记录哪些参数被修改过) - modifiedParams: new Map(), + // 修改记录(使用对象而非Map,确保Vue能检测变化) + modifiedParams: {}, // 保存状态 saving: false } @@ -71,7 +71,7 @@ export default { /** 计算已修改参数数量 */ modifiedCount() { let count = 0; - this.modifiedParams.forEach(params => { + Object.values(this.modifiedParams).forEach(params => { count += params.size; }); return count; @@ -96,7 +96,7 @@ export default { const res = await listAllParams({ projectId: this.projectId }); this.modelGroups = res.data.models; // 清空修改记录 - this.modifiedParams.clear(); + this.modifiedParams = {}; } catch (error) { this.$message.error('加载参数失败:' + error.message); console.error('加载参数失败', error); @@ -105,10 +105,14 @@ export default { /** 标记参数为已修改 */ markAsModified(modelCode, row) { - if (!this.modifiedParams.has(modelCode)) { - this.modifiedParams.set(modelCode, new Set()); + // 使用 $set 确保 Vue 能检测到对象属性的新增 + if (!this.modifiedParams[modelCode]) { + this.$set(this.modifiedParams, modelCode, new Set()); } - this.modifiedParams.get(modelCode).add(row.paramCode); + this.modifiedParams[modelCode].add(row.paramCode); + + // 强制更新视图 + this.$forceUpdate(); }, /** 保存所有修改 */ @@ -125,8 +129,10 @@ export default { models: [] }; - this.modifiedParams.forEach((paramCodes, modelCode) => { + Object.entries(this.modifiedParams).forEach(([modelCode, paramCodes]) => { const modelGroup = this.modelGroups.find(m => m.modelCode === modelCode); + if (!modelGroup) return; + const modifiedParamList = modelGroup.params .filter(p => paramCodes.has(p.paramCode)) .map(p => ({ @@ -148,7 +154,7 @@ export default { await saveAllParams(saveDTO); this.$message.success('保存成功'); // 清空修改记录并重新加载 - this.modifiedParams.clear(); + this.modifiedParams = {}; await this.loadAllParams(); } catch (error) { if (error.response && error.response.data && error.response.data.msg) {