TodaySummaryView.vue
3.27 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
<template>
<div class="summary-page">
<div class="content-item">
<div class="task-stats">
<div class="stat-item">
<span class="stat-label">任务总数</span>
<span class="stat-value success">{{ summary.totalTask }}</span>
</div>
<div class="stat-item">
<span class="stat-label">进行中任务数</span>
<span class="stat-value success">{{ summary.uncompletedTask }}</span>
</div>
<div class="stat-item">
<span class="stat-label">完成任务数</span>
<span class="stat-value success">{{ summary.completedTask }}</span>
</div>
<div class="stat-item">
<span class="stat-label">平均耗时</span>
<span class="stat-value success">{{ summary.averageTaskDuration }}</span>
</div>
<div class="stat-item">
<span class="stat-label">异常任务数</span>
<span class="stat-value error">{{ summary.exceptionTask }}</span>
</div>
</div>
</div>
</div>
</template>
<script>
import { CMC_OFFLINE_STATUS_API } from '@/api/cmcApi'
export default {
name: 'TodaySummaryView',
props: {
userName: {
type: String,
default: '',
},
},
watch: {
userName: {
immediate: true,
handler(newVal) {
if (newVal) {
// this.getData()
}
},
},
},
data() {
return {
baseUrlOff: CMC_OFFLINE_STATUS_API,
baseUrlOnLine: window.appConfig.baseUrlintThree,
sysData: {},
timer: null,
deviceStatus: [],
summary: {},
drawer: false,
direction: 'rtl',
device: {},
temp: 0,
// 新增:定时器控制字段
refreshTimer: null, // 全局刷新定时器ID
}
},
methods: {
getData() {
const opt = {
urlSuffix: window.baseOnLineOrOff ? `${this.baseUrlOnLine}?zoneCode=${this.userName}` : `${this.baseUrlOnLine}?zoneCode=${this.userName}`,
logTitle: '任务耗时',
isUrlALL: true,
headers: window.baseOnLineOrOff,
header: window.baseOnLineOrOff,
type: 'post',
}
const callBackFn = (res) => {
if (!this.ajaxSuccessDataBefore(res, opt.logTitle)) return
this.summary = res.data.result
}
''.ajax(this, opt, callBackFn)
},
ajaxSuccessDataBefore(res, title) {
if (!res || !res.data || res.data.result == null || res.data.result.length === 0) {
this.sysData = []
''.Log(`${title}无数据`, 'getData')
return false
}
return true
},
// 修改:定时器启动方法
intInterval: function() {
// 清理现有定时器
if (this.refreshTimer) {
clearInterval(this.refreshTimer)
}
// 启动新的定时器
this.refreshTimer = setInterval(() => {
this.getData()
}, 10000)
},
// 新增:暂停接口请求
pauseApiRequest() {
// 停止全局刷新定时器
if (this.refreshTimer) {
clearInterval(this.refreshTimer)
this.refreshTimer = null
}
},
// 新增:恢复接口请求
resumeApiRequest() {
// 重启全局刷新
if (!this.refreshTimer) {
this.intInterval()
}
},
},
mounted() {
this.getData()
this.intInterval()
},
// 新增:组件销毁时停止定时器
beforeDestroy() {
this.pauseApiRequest()
},
// 新增:激活组件时恢复请求
activated() {
this.resumeApiRequest()
},
// 新增:停用组件时暂停请求
deactivated() {
this.pauseApiRequest()
},
}
</script>
<style src="../../styles/today-summary.css"></style>