From f17c76ce685522441bb5c04fe25bb54838b2eb06 Mon Sep 17 00:00:00 2001
From: zzw <228544128@qq.com>
Date: 星期五, 02 十月 2026 18:45:15 +0800
Subject: [PATCH] fix: load only active report data
---
emergency-repair-web/src/views/report/ReportPage.vue | 33 +++++++++++++++++++++++----------
1 files changed, 23 insertions(+), 10 deletions(-)
diff --git a/emergency-repair-web/src/views/report/ReportPage.vue b/emergency-repair-web/src/views/report/ReportPage.vue
index 2ae5bae..4f1e476 100644
--- a/emergency-repair-web/src/views/report/ReportPage.vue
+++ b/emergency-repair-web/src/views/report/ReportPage.vue
@@ -38,11 +38,13 @@
export default {
name: 'ReportPage',
+ props: {
+ type: { type: String, required: true }
+ },
data() {
- return { stats: {}, rows: [], chart: null }
+ return { stats: {}, rows: [], chart: null, loadSeq: 0 }
},
computed: {
- type() { return this.$route.params.type },
title() {
return {
overview: '瑁呭鏁呴殰鎬讳綋鍒嗘瀽',
@@ -93,7 +95,7 @@
}
},
watch: {
- '$route.params.type': 'load'
+ type: 'load'
},
mounted() {
this.load()
@@ -105,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
--
Gitblit v1.9.1