From 608f5b4488ccbcde625649ccf3caa4f22606c7d6 Mon Sep 17 00:00:00 2001 From: wkc <978997012@qq.com> Date: Mon, 16 Mar 2026 13:42:00 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E4=BC=98=E5=8C=96=E5=85=A8=E5=B1=80?= =?UTF-8?q?=E6=A8=A1=E5=9E=8B=E5=8F=82=E6=95=B0=E9=A1=B5=E5=8A=A8=E6=80=81?= =?UTF-8?q?=E5=B1=95=E7=A4=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ruoyi-ui/src/views/ccdi/modelParam/index.vue | 105 ++++++++++--------- 1 file changed, 57 insertions(+), 48 deletions(-) diff --git a/ruoyi-ui/src/views/ccdi/modelParam/index.vue b/ruoyi-ui/src/views/ccdi/modelParam/index.vue index 5869d3fc..85db7937 100644 --- a/ruoyi-ui/src/views/ccdi/modelParam/index.vue +++ b/ruoyi-ui/src/views/ccdi/modelParam/index.vue @@ -59,38 +59,53 @@ export default { name: "ModelParam", data() { return { - // 模型参数数据(按模型分组) modelGroups: [], - // 修改记录(使用对象而非Map,确保Vue能检测变化) modifiedParams: {}, - // 加载状态 + originalParamValues: {}, loading: false, - // 保存状态 saving: false }; }, computed: { - /** 计算已修改参数数量 */ modifiedCount() { - let count = 0; - Object.values(this.modifiedParams).forEach(params => { - count += params.size; - }); - return count; + return Object.keys(this.modifiedParams).length; } }, created() { this.loadAllParams(); }, methods: { - /** 加载所有模型参数 */ + buildModifiedKey(modelCode, paramCode) { + return `${modelCode}:${paramCode}`; + }, + normalizeParamValue(value) { + return value === null || value === undefined ? '' : String(value); + }, + normalizeModelGroups(models) { + if (!Array.isArray(models)) { + return []; + } + return models.map(model => ({ + ...model, + params: Array.isArray(model.params) ? model.params : [] + })); + }, + resetModifiedState() { + this.modifiedParams = {}; + this.originalParamValues = {}; + this.modelGroups.forEach(model => { + model.params.forEach(row => { + const key = this.buildModifiedKey(model.modelCode, row.paramCode); + this.$set(this.originalParamValues, key, this.normalizeParamValue(row.paramValue)); + }); + }); + }, async loadAllParams() { this.loading = true; try { const res = await listAllParams({ projectId: 0 }); - this.modelGroups = res.data.models || []; - // 清空修改记录 - this.modifiedParams = {}; + this.modelGroups = this.normalizeModelGroups(res.data && res.data.models); + this.resetModifiedState(); } catch (error) { this.$message.error('加载参数失败:' + error.message); console.error('加载参数失败', error); @@ -99,58 +114,52 @@ export default { } }, - /** 标记参数为已修改 */ markAsModified(modelCode, row) { - // 使用 $set 确保 Vue 能检测到对象属性的新增 - if (!this.modifiedParams[modelCode]) { - this.$set(this.modifiedParams, modelCode, new Set()); - } - this.modifiedParams[modelCode].add(row.paramCode); + const modifiedKey = this.buildModifiedKey(modelCode, row.paramCode); + const currentValue = this.normalizeParamValue(row.paramValue); + const originalValue = this.originalParamValues[modifiedKey]; - // 强制更新视图 - this.$forceUpdate(); + if (currentValue === originalValue) { + if (this.modifiedParams[modifiedKey]) { + this.$delete(this.modifiedParams, modifiedKey); + } + return; + } + this.$set(this.modifiedParams, modifiedKey, { + modelCode, + paramCode: row.paramCode, + paramValue: row.paramValue + }); }, - /** 保存所有修改 */ async handleSaveAll() { - // 验证是否有修改 if (this.modifiedCount === 0) { this.$message.info('没有需要保存的修改'); return; } - // 构造保存数据(只包含修改过的参数) + const modelMap = {}; + Object.values(this.modifiedParams).forEach(item => { + if (!modelMap[item.modelCode]) { + modelMap[item.modelCode] = { + modelCode: item.modelCode, + params: [] + }; + } + modelMap[item.modelCode].params.push({ + paramCode: item.paramCode, + paramValue: item.paramValue + }); + }); const saveDTO = { projectId: 0, - models: [] + models: Object.values(modelMap) }; - 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 => ({ - paramCode: p.paramCode, - paramValue: p.paramValue - })); - - if (modifiedParamList.length > 0) { - saveDTO.models.push({ - modelCode: modelCode, - params: modifiedParamList - }); - } - }); - - // 保存 this.saving = true; try { await saveAllParams(saveDTO); this.$modal.msgSuccess('保存成功'); - // 清空修改记录并重新加载 - this.modifiedParams = {}; await this.loadAllParams(); } catch (error) { if (error.response && error.response.data && error.response.data.msg) {