现有 DimensionWeightPicker.vue 采用 checkbox 选择维度 + slider 调整权重的组合,存在两个体验问题:
用户要求:滑动条 + 数字输入框,拖动条表示对应维度分配比例,全部比例之和不超过 100%。
max = 100 - Σ(其他已启用维度的当前值)
Props value 格式不变(向后兼容):
value: [{ dimension: 'body', weight: 25, enabled: true }, ...]
emit 格式也不变:
this.$emit('input', [{ dimension: 'body', weight: 25, enabled: true }, ...])
每行:[维度名称] [滑动条━━━━━━━━●━━━━] [数字输入]
% 单位身·土 [━━━━━━━━━━●━━━] 30% ← max=100-0=100
智·金 [━━━━━━━━●━━━━━━] 20% ← max=100-30=70
行·木 [━━━━━━━━━━━━━━━] 0% ← max=100-50=50(灰色禁用)
富·水 [━━━━━━━━━━━━━━━] 0%
心·火 [━━━━━━━━━━━━━━━] 0%
合计: 50%
| 预设 | body | mind | action | wealth | heart |
|---|---|---|---|---|---|
| 均衡 | 20 | 20 | 20 | 20 | 20 |
| 偏身 | 40 | 15 | 15 | 15 | 15 |
| 偏智 | 15 | 40 | 15 | 15 | 15 |
| 偏行 | 15 | 15 | 40 | 15 | 15 |
| 偏富 | 15 | 15 | 15 | 40 | 15 |
| 偏心 | 15 | 15 | 15 | 15 | 40 |
预设一键应用,重新计算每个 slider 的 max 值。
getMaxForDim(code) {
const otherTotal = this.dimensions
.filter(d => d.code !== code && d.currentValue > 0)
.reduce((sum, d) => sum + d.currentValue, 0)
return 100 - otherTotal
}
currentValue → recalculate all maxes → emitcurrentValue → recalculate all maxes → emitcurrentValue === 0 的维度 slider 显示灰色且 disabled=true,其他维度正常可调。
cfc-web/src/components/DimensionWeightPicker.vue — 重写核心实现cfc-web/src/views/admin/Activities.vue — 用到该组件,无需改动cfc-web/src/views/admin/ArticleEdit.vue — 用到该组件,无需改动cfc-web/src/views/admin/EnergyRuleManagement.vue — 用到该组件,无需改动