zhizhijie
2026-10-20 c89f5fe744773ed06de8a0834009100e941227f9
traffic-audit-web/src/views/RuleManage.vue
@@ -1,19 +1,23 @@
<template>
  <el-container>
    <el-header>交通统计报表审核系统 - 规则管理</el-header>
  <el-container direction="vertical">
    <app-header title="交通统计报表审核系统 - 规则管理"></app-header>
    <el-container>
      <el-aside width="200px">
        <el-menu router default-active="/rules">
        <el-menu ref="sideMenu" router :default-active="$route.path" @select="onMenuSelect">
          <el-menu-item index="/dashboard">工作台</el-menu-item>
          <el-menu-item index="/import">数据导入</el-menu-item>
          <el-menu-item index="/data">数据查看</el-menu-item>
          <el-menu-item index="/explain">企业解释</el-menu-item>
          <el-menu-item index="/audit">审核结果</el-menu-item>
          <el-menu-item index="/report">报表生成</el-menu-item>
          <el-submenu index="/special-stats">
            <template slot="title">专项统计</template>
            <el-menu-item index="/holiday-stat">节假日</el-menu-item>
          </el-submenu>
          <el-menu-item index="/rules">规则管理</el-menu-item>
          <el-menu-item index="/users">用户管理</el-menu-item>
          <el-menu-item index="/login" @click="logout">退出登录</el-menu-item>
</el-menu>
          <el-menu-item v-if="operatorIsAdmin" index="/system-config">系统配置</el-menu-item>
        </el-menu>
      </el-aside>
      <el-main>
        <h3>审核规则管理</h3>
@@ -70,6 +74,7 @@
</template>
<script>
import api from '@/api'
import AppHeader from '@/components/AppHeader.vue'
const TYPE_CN = {
  DIFF: '差值对比', RATIO: '比例对比', MOM: '环比新增', NULL_CHECK: '必填/一致性',
  OUT_RANGE: '范围检查', MOM_EQ_ZERO: '环比为0', MOM_PCT: '环比百分比',
@@ -78,9 +83,11 @@
  TREND_CONSISTENCY: '趋势一致', RATIO_CHANGE: '占比变化', AVG_DIST_CHANGE: '平均运距变化',
  PAX_PER_TRIP_CHANGE: '单车次载客人数变化', LOADED_RATIO_DIFF: '载货里程占比对比',
  FUEL_RANGE: '单耗超范围', FUEL_MOM: '单耗环比', FREIGHT_VS_H2032: '与货运月报对比',
  AVG_DIST_VS_H2032: '平均运距对比', LOADED_TON_RATIO: '载货吨位比值'
  AVG_DIST_VS_H2032: '平均运距对比', LOADED_TON_RATIO: '载货吨位比值',
  EFFICIENCY_RATIO: '运输效率比值', VEHICLE_VS_ENT_AVG: '单车与月报每主车对比', MILEAGE_VS_TRACK: '单车行程与轨迹对比'
}
export default {
  components: { AppHeader },
  name: 'RuleManage',
  data() {
    return { reportType: 'H2032', rules: [], loading: false }
@@ -91,24 +98,30 @@
      this.loading = true
      api.get('/rules/list', { params: { reportType: this.reportType } })
        .then(res => { this.rules = res.data || [] })
        .catch(() => { this.$message.error('规则加载失败') })
        .catch(e => { if (e && e._toast) return; this.$message.error('规则加载失败') })
        .finally(() => { this.loading = false })
    },
    toggleRule(row) {
      api.post('/rules/toggle', null, { params: { id: row.id, enabled: row.isEnabled } })
        .then(() => { this.$message.success((row.isEnabled ? '已启用:' : '已停用:') + row.ruleCode) })
        .catch(() => { row.isEnabled = row.isEnabled ? 0 : 1; this.$message.error('操作失败') })
        .catch(e => { if (e && e._toast) return; row.isEnabled = row.isEnabled ? 0 : 1; this.$message.error('操作失败') })
    },
    saveThreshold(row) {
      api.post('/rules/update', {
        id: row.id, threshold: row.threshold, alertLevel: row.alertLevel
      }).then(() => { this.$message.success('已保存:' + row.ruleCode) })
        .catch(() => { this.$message.error('保存失败') })
      }).then(res => {
        // 后端会按新阈值同步改写「规则名称/说明」,把最新值回填到当前行,否则列表还显示旧文案
        const r = res && res.data
        if (r) {
          row.ruleName = r.ruleName
          row.description = r.description
          row.threshold = r.threshold
        }
        this.$message.success('已保存:' + row.ruleCode)
      })
        .catch(e => { if (e && e._toast) return; this.$message.error('保存失败') })
    }
  },
  mounted() { this.loadRules() }
}
</script>
<style scoped>
.el-header { background: #409EFF; color: white; line-height: 60px; font-size: 18px; }
</style>