xyc
2026-11-11 841847dbbab3c6fd532dcb747ca290ba6a9e12d0
traffic-audit-web/src/views/DataView.vue
@@ -24,7 +24,9 @@
        <div class="toolbar">
          <template v-if="!isRollup">
            <span class="toolbar-label">报表期</span>
            <el-date-picker v-model="period" type="month" placeholder="报表期(全部)" value-format="yyyy-MM" clearable style="width:150px" @change="doQuery"></el-date-picker>
            <el-date-picker v-model="period" type="month" placeholder="报表期(全部)" value-format="yyyy-MM" clearable
                            style="width:150px" :picker-options="periodPickerOptions" @change="doQuery"></el-date-picker>
            <span v-if="periodHint" class="toolbar-hint">{{ periodHint }}</span>
          </template>
          <span class="toolbar-sep"></span>
          <span class="toolbar-label">数据类型</span>
@@ -88,6 +90,7 @@
<script>
import AppHeader from '@/components/AppHeader.vue'
import api from '@/api'
import { granularityOfImportType, disabledDateFor, granularityHint, snapPeriod } from '@/utils/periodGranularity'
export default {
  components: { AppHeader },
  name: 'DataView',
@@ -97,6 +100,7 @@
        {
          key: 'freight', name: '道路货运', types: [
            { value: 'h2032', label: '道路货物运输月度生产情况' },
            { value: 'h202', label: '公路货物营运车辆拥有情况(H202)' },
            { value: 'transportAuth', label: '运政车辆' },
            { value: 'trackMileage', label: '轨迹里程' },
            { value: 'scaleSplit', label: '规上规下拆分' },
@@ -154,6 +158,12 @@
    }
  },
  computed: {
    periodGranularity() { return granularityOfImportType(this.type) },
    periodPickerOptions() {
      const d = disabledDateFor(this.periodGranularity)
      return d ? { disabledDate: d } : {}
    },
    periodHint() { return granularityHint(this.periodGranularity) },
    canRollup() {
      return (this.rollupTypes || []).some(t => t.type === this.type)
    },
@@ -188,6 +198,17 @@
        count++
      }
      return cols.map((c, i) => Object.assign({}, c, { fixed: i < count }))
    }
  },
  watch: {
    // 选到能耗(季报)时把报表期对齐到季度末月
    periodGranularity() {
      const snapped = snapPeriod(this.period, this.periodGranularity)
      if (snapped && snapped !== this.period) {
        this.period = snapped
        const hint = granularityHint(this.periodGranularity)
        if (hint) this.$message.warning(hint + '(已自动调整为 ' + snapped + ')')
      }
    }
  },
  methods: {
@@ -385,6 +406,7 @@
    //  - 其余数值千分位、保留两位小数;整数原样。
    formatCell(v, prop) {
      if (v === null || v === undefined || v === '') return '-'
      if (this.type === 'h202' && /Value$/.test(String(prop || ''))) return this.formatExactDecimal(v)
      const s = typeof v === 'string' ? v.trim() : v
      if (typeof v !== 'number' && !/^-?\d+(\.\d+)?$/.test(String(s))) return v
      const n = Number(s)
@@ -394,6 +416,17 @@
      if (/(rate|yoy|mom|growth|ratio|percent|share)/.test(key)) return (n * 100).toFixed(2) + '%'
      if (Number.isInteger(n)) return n.toLocaleString('zh-CN')
      return n.toLocaleString('zh-CN', { minimumFractionDigits: 2, maximumFractionDigits: 2 })
    },
    // H202 values arrive as exact decimal strings. Format without Number() to preserve source precision.
    formatExactDecimal(v) {
      const text = String(v === null || v === undefined ? '' : v).trim()
      if (!/^-?\d+(?:\.\d+)?$/.test(text)) return v
      const negative = text.charAt(0) === '-'
      const unsigned = negative ? text.slice(1) : text
      const parts = unsigned.split('.')
      const integer = parts[0].replace(/\B(?=(\d{3})+(?!\d))/g, ',')
      const fraction = (parts[1] || '').replace(/0+$/, '')
      return (negative ? '-' : '') + integer + (fraction ? '.' + fraction : '')
    }
  },
  mounted() {