fix(maps): KR 目标值逐键输入污染名称根治 — 移除 formatTargetValue 回写名称 + 只读预览拼接 (project-20260911-kr-name-pollution)

This commit is contained in:
Hermes CI Fix
2026-09-11 19:15:31 +08:00
parent e22093256b
commit c928d59f60
@@ -87,7 +87,7 @@
</div>
<div class="mc-kr-field">
<label>目标值 <span class="mc-required">*</span></label>
<input v-model.number="kr.target_value" type="number" step="0.01" min="0" class="mc-input mc-kr-input" placeholder="目标数值" @input="formatTargetValue(ki)" />
<input v-model.number="kr.target_value" type="number" step="0.01" min="0" class="mc-input mc-kr-input" placeholder="目标数值" />
</div>
<div class="mc-kr-field">
<label>权重(0-100,可小数)</label>
@@ -103,6 +103,9 @@
</select>
</div>
</div>
<div v-if="kr.name || kr.target_value != null" class="mc-kr-preview">
展示为:{{ kr.name }} {{ opSymbol(kr.operator) }}{{ kr.target_value }}
</div>
<div v-if="weightSum !== null && weightSum !== 100" class="mc-kr-warning">⚠️ 权重合计 {{ weightSum }}%,应为100%</div>
</div>
</div>
@@ -678,16 +681,13 @@ function onKpiChange(ki: number) {
ElMessage.success(`已关联KPI: ${kpiName}(方向 ${kr.operator} ${kr.target_value})`)
}
function formatTargetValue(idx: number) {
// 数值输入,不需要追加%(weightSum实时校验)
const kr = form.value.krs[idx]
if (!kr) return
if (kr.target_value == null || kr.target_value === "") return
// 自动同步到KR名称:如果名称是纯文字无数字,追加方向+目标值
if (kr.name && !/\d/.test(kr.name)) {
const opSymbol = kr.operator === ">=" ? "≥" : kr.operator === "<=" ? "≤" : kr.operator
kr.name = kr.name + opSymbol + kr.target_value
}
// ── KR 展示符号(只读展示:名称与目标值解耦,不再回写名称) ──
// project-20260911-kr-name-pollution 根治:原 formatTargetValue 在 @input 逐键触发时
// 把「方向符号+当时已输入的数字」追加进名称(输入 780 → 名称被改成 "营业收入≥7"),
// 导致名称与 target_value 不一致的存量污染。现删除该写入点——KR 名称的唯一写入点是
// 用户输入;「名称+值」的展示只在模板里做只读拼接(.mc-kr-preview),不改数据。
function opSymbol(op: string) {
return op === ">=" ? "≥" : op === "<=" ? "≤" : (op || "")
}
function checkWeightSum() {
@@ -1020,5 +1020,7 @@ function planStatusLabel(s: string): string {
.pps-cancelled { background: #fef0f0; color: #f56c6c; }
.plan-popup-title { font-size: 13px; font-weight: 500; }
.plan-popup-meta { display: flex; gap: 12px; margin-top: 4px; font-size: 12px; color: #909399; }
</style>
.mc-kr-warning { color: #e6a23c; font-size: 12px; margin-top: 4px; }
/* KR 名称+目标值 只读预览(名称与值解耦,展示层拼接,不回写数据) */
.mc-kr-preview { color: #909399; font-size: 12px; margin-top: 4px; }
</style>