feat: 编辑目标——回车自动加%+权重合计校验
This commit is contained in:
@@ -67,11 +67,11 @@
|
||||
<div class="mc-kr-row-bottom">
|
||||
<div class="mc-kr-field">
|
||||
<label>目标值</label>
|
||||
<input v-model="kr.target_value" class="mc-input mc-kr-input" placeholder="如 ≥18%" />
|
||||
<input v-model="kr.target_value" class="mc-input mc-kr-input" placeholder="输入数字,回车自动加%" @keydown.enter.prevent="formatTargetValue(ki)" />
|
||||
</div>
|
||||
<div class="mc-kr-field">
|
||||
<label>权重</label>
|
||||
<select v-model="kr.weight" class="mc-input mc-kr-input">
|
||||
<select v-model="kr.weight" class="mc-input mc-kr-input" @change="checkWeightSum">
|
||||
<option value="10">10%</option>
|
||||
<option value="20">20%</option>
|
||||
<option value="25">25%</option>
|
||||
@@ -86,6 +86,7 @@
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
<div v-if="weightSum !== null && weightSum !== 100" class="mc-kr-warning">⚠️ 权重合计 {{ weightSum }}%,应为100%</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
@@ -496,6 +497,10 @@ function prevStep() {
|
||||
selectedTemplateIdx.value = null
|
||||
}
|
||||
|
||||
const weightSum = computed(() => {
|
||||
return form.value.krs.reduce((s, kr) => s + (parseInt(kr.weight) || 0), 0)
|
||||
})
|
||||
|
||||
function addKr() {
|
||||
form.value.krs.push({ name: "", target_value: "", weight: "33" })
|
||||
}
|
||||
@@ -504,6 +509,17 @@ function removeKr(idx: number) {
|
||||
form.value.krs.splice(idx, 1)
|
||||
}
|
||||
|
||||
function formatTargetValue(idx: number) {
|
||||
const val = form.value.krs[idx]?.target_value
|
||||
if (val && !val.includes('%') && !isNaN(parseFloat(val))) {
|
||||
form.value.krs[idx].target_value = parseFloat(val).toFixed(2) + '%'
|
||||
}
|
||||
}
|
||||
|
||||
function checkWeightSum() {
|
||||
// 触发computed重新计算,warning自动显示
|
||||
}
|
||||
|
||||
function onSave() {
|
||||
if (!form.value.o_name?.trim()) {
|
||||
// 简单提示 — 父组件会检测
|
||||
@@ -772,3 +788,4 @@ function planStatusLabel(s: string): string {
|
||||
.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; }
|
||||
|
||||
Reference in New Issue
Block a user