zzw
4 小时以前 f17c76ce685522441bb5c04fe25bb54838b2eb06
emergency-repair-web/src/views/report/ReportPage.vue
@@ -42,7 +42,7 @@
    type: { type: String, required: true }
  },
  data() {
    return { stats: {}, rows: [], chart: null }
    return { stats: {}, rows: [], chart: null, loadSeq: 0 }
  },
  computed: {
    title() {
@@ -107,14 +107,25 @@
  },
  methods: {
    load() {
      const requests = {
        overview: api.get('/reports/overview').then(res => { this.stats = res.data || {}; this.rows = this.stats.chart || [] }),
        'top-equipment': api.get('/reports/top-equipment').then(res => { this.rows = res.data || []; this.stats = {} }),
        'by-team': api.get('/reports/by-team').then(res => { this.rows = res.data || []; this.stats = {} }),
        contractors: api.get('/reports/contractors').then(res => { this.rows = res.data || []; this.stats = {} }),
        trend: api.get('/reports/yearly-trend').then(res => { this.rows = res.data || []; this.stats = {} })
      const loaders = {
        overview: () => api.get('/reports/overview').then(res => ({
          stats: res.data || {},
          rows: (res.data && res.data.chart) || []
        })),
        'top-equipment': () => api.get('/reports/top-equipment').then(res => ({ stats: {}, rows: res.data || [] })),
        'by-team': () => api.get('/reports/by-team').then(res => ({ stats: {}, rows: res.data || [] })),
        contractors: () => api.get('/reports/contractors').then(res => ({ stats: {}, rows: res.data || [] })),
        trend: () => api.get('/reports/yearly-trend').then(res => ({ stats: {}, rows: res.data || [] }))
      }
      ;(requests[this.type] || Promise.resolve()).then(() => this.$nextTick(this.renderChart))
      const seq = ++this.loadSeq
      const loader = loaders[this.type]
      const request = loader ? loader() : Promise.resolve({ stats: {}, rows: [] })
      request.then(result => {
        if (seq !== this.loadSeq) return
        this.stats = result.stats
        this.rows = result.rows
        this.$nextTick(this.renderChart)
      }).catch(() => {})
    },
    renderChart() {
      if (!this.$refs.chart) return