refactor: make rule type a read-only label on card

Type is fixed by preset, no need for dropdown editing

Remove unused typeDefaults, onTypeChange functions
This commit is contained in:
mediabot-pt
2026-07-06 23:00:55 +08:00
parent cf26f2f6b1
commit 194ce96f39

View File

@@ -85,9 +85,7 @@
<div class="card-header" @dblclick="rule._fold = !rule._fold">
<div class="card-header-left">
<el-icon class="drag-handle"><Rank /></el-icon>
<el-select v-model="rule.type" size="small" @change="onTypeChange(rule)" style="width:100px">
<el-option v-for="x in typeOptions" :key="x.value" :label="x.label" :value="x.value" />
</el-select>
<span class="type-tag">{{ typeLabel(rule.type) }}</span>
<span v-if="rule.type==='TASK'" class="rule-fixed-text">考核周期 {{ rule.threshold }}天</span>
<span v-else-if="rule.type==='DRATIO'" class="rule-fixed-text">下载量 ≥ {{ rule.threshold }}GB 时分享率 ≥ {{ rule.minRatio }}</span>
<span v-else-if="rule.type==='EXEMPT'" class="rule-fixed-text">永久保留 ≥ {{ rankDisplay(rule.permRank) }} / 封存豁免 ≥ {{ rankDisplay(rule.sealExemptRank) }}</span>
@@ -245,12 +243,6 @@ const metricOptions = [
const typeLabel = (t) => typeOptions.find(x => x.value === t)?.label || t
const typeDefaults = {
KILL: { metric:'days_since_last_login', condition:'GT', unit:'天' },
TRAFFIC: { metric:'days_since_last_traffic', condition:'GT', unit:'天' },
HD: { metric:'hnr_count', condition:'GTE', unit:'次' },
RATIO: { metric:'ratio', condition:'LT', unit:'' },
}
const metricLabel = (m) => metricOptions.find(x => x.value === m)?.label || m || ''
const condLabel = (c) => condOptions.find(x => x.value === c)?.label || c || ''
@@ -279,27 +271,6 @@ const onApplicableChange = (rule) => {
sync()
}
const onTypeChange = (rule) => {
if (rule.type === 'TASK') {
if (!rule.requirements || !rule.requirements.length) {
rule.requirements = JSON.parse(JSON.stringify(taskReqDefaults))
}
rule.threshold = rule.threshold || 30
rule.unit = '天'
} else if (rule.type === 'DRATIO') {
rule.threshold = rule.threshold || 100
rule.minRatio = rule.minRatio || 1.0
rule.unit = 'GB'
} else if (rule.type === 'EXEMPT') {
rule.permRank = rule.permRank || ''
rule.sealExemptRank = rule.sealExemptRank || ''
} else {
const d = typeDefaults[rule.type]
if (d) { rule.metric = d.metric; rule.condition = d.condition; rule.unit = d.unit }
}
sync()
}
// ============ 预设规则模板 ============
const presets = [
// 四、账号存活策略
@@ -475,6 +446,7 @@ onMounted(fetchAll)
.card-body { padding: 6px 12px 10px 12px; display: flex; flex-direction: column; gap: 6px; }
.rule-fixed-text { font-size: 13px; color: #303133; }
.type-tag { font-size: 12px; color: #303133; font-weight: 500; }
.field-row { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; font-size: 13px; }
.field-label { font-weight: 500; color: #606266; font-size: 12px; min-width: 56px; }