liding
2026-06-09 76302992e7bcb60682ee6d3ae9de6619b477b968
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
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
<template>
  <div class="app-container dashboard-container">
    <!-- 顶部统计卡片 -->
    <el-row :gutter="20" style="margin-bottom: 20px;">
      <el-col :span="4">
        <el-card shadow="hover" class="stat-card-wrapper">
          <div class="stat-card">
            <div class="stat-icon" style="background: #409EFF;">
              <i class="el-icon-s-claim" />
            </div>
            <div class="stat-content">
              <div class="stat-title">待领样品</div>
              <div class="stat-value">{{ overviewData.waitReceive || 0 }}</div>
            </div>
          </div>
        </el-card>
      </el-col>
      <el-col :span="4">
        <el-card shadow="hover" class="stat-card-wrapper">
          <div class="stat-card">
            <div class="stat-icon" style="background: #E6A23C;">
              <i class="el-icon-time" />
            </div>
            <div class="stat-content">
              <div class="stat-title">待检样品</div>
              <div class="stat-value">{{ overviewData.waitInspection || 0 }}</div>
            </div>
          </div>
        </el-card>
      </el-col>
      <el-col :span="4">
        <el-card shadow="hover" class="stat-card-wrapper">
          <div class="stat-card">
            <div class="stat-icon" style="background: #909399;">
              <i class="el-icon-document-checked" />
            </div>
            <div class="stat-content">
              <div class="stat-title">待审核</div>
              <div class="stat-value">{{ overviewData.waitAudit || 0 }}</div>
            </div>
          </div>
        </el-card>
      </el-col>
      <el-col :span="4">
        <el-card shadow="hover" class="stat-card-wrapper">
          <div class="stat-card">
            <div class="stat-icon" style="background: #F56C6C;">
              <i class="el-icon-document" />
            </div>
            <div class="stat-content">
              <div class="stat-title">待编制报告</div>
              <div class="stat-value">{{ overviewData.waitReport || 0 }}</div>
            </div>
          </div>
        </el-card>
      </el-col>
      <el-col :span="4">
        <el-card shadow="hover" class="stat-card-wrapper">
          <div class="stat-card">
            <div class="stat-icon" style="background: #67C23A;">
              <i class="el-icon-circle-check" />
            </div>
            <div class="stat-content">
              <div class="stat-title">今日完成</div>
              <div class="stat-value">{{ overviewData.todayFinished || 0 }}</div>
            </div>
          </div>
        </el-card>
      </el-col>
      <el-col :span="4">
        <el-card shadow="hover" class="voice-control" @click.native="toggleVoice">
          <div class="voice-content">
            <i :class="voiceEnabled ? 'el-icon-microphone' : 'el-icon-turn-off-microphone'" />
            <span>{{ voiceEnabled ? '语音播报中' : '语音已关闭' }}</span>
          </div>
        </el-card>
      </el-col>
    </el-row>
 
    <!-- 图表区域 -->
    <el-row :gutter="20" style="margin-bottom: 20px;">
      <!-- 历史15天检测任务 -->
      <el-col :span="16">
        <el-card shadow="hover">
          <div slot="header">
            <span>近15天检测任务</span>
            <el-tag type="info" size="mini" style="margin-left: 10px;">实时更新</el-tag>
          </div>
          <Echart
            :xAxis="historyXAxis"
            :yAxis="historyYAxis"
            :series="historySeries"
            :tooltip="{ trigger: 'axis' }"
            :legend="{ data: ['检测任务', '完成任务'] }"
            :grid="{ left: '3%', right: '4%', bottom: '3%', containLabel: true }"
            :chartStyle="{ height: '280px' }"
          />
        </el-card>
      </el-col>
      <!-- 未来15天任务预览 -->
      <el-col :span="8">
        <el-card shadow="hover" class="future-task-card">
          <div slot="header">未来15天任务</div>
          <div class="future-task-list">
            <div v-for="(item, index) in futureTasks" :key="index" class="future-task-item">
              <span class="task-date">{{ item.date }}</span>
              <el-progress :percentage="item.progress" :stroke-width="10" style="flex: 1; margin: 0 10px;" />
              <span class="task-count">{{ item.taskCount }}个任务</span>
            </div>
          </div>
        </el-card>
      </el-col>
    </el-row>
 
    <el-row :gutter="20" style="margin-bottom: 20px;">
      <!-- 提交排行榜 -->
      <el-col :span="12">
        <el-card shadow="hover">
          <div slot="header">
            <span>近15天提交排行</span>
            <el-radio-group v-model="rankingType" size="mini" style="float: right;" @change="getRankingData">
              <el-radio-button label="record">原始记录</el-radio-button>
              <el-radio-button label="report">报告</el-radio-button>
            </el-radio-group>
          </div>
          <div class="ranking-list">
            <div v-for="(item, index) in rankingData" :key="index" class="ranking-item">
              <span class="ranking-index" :class="getRankingClass(index)">{{ index + 1 }}</span>
              <span class="ranking-name">{{ item.userName }}</span>
              <el-progress :percentage="item.percentage" :stroke-width="15" :show-text="false" style="flex: 1; margin: 0 15px;" />
              <span class="ranking-count">{{ item.count }}份</span>
            </div>
          </div>
        </el-card>
      </el-col>
      <!-- 检验结果统计 -->
      <el-col :span="12">
        <el-card shadow="hover">
          <div slot="header">近30天检验结果</div>
          <el-row :gutter="20">
            <el-col :span="8">
              <div class="result-card">
                <div class="result-title">原材料</div>
                <Echart
                  :series="rawMaterialSeries"
                  :tooltip="{ trigger: 'item', formatter: '{b}: {c} ({d}%)' }"
                  :chartStyle="{ height: '200px' }"
                />
              </div>
            </el-col>
            <el-col :span="8">
              <div class="result-card">
                <div class="result-title">半成品</div>
                <Echart
                  :series="semiProductSeries"
                  :tooltip="{ trigger: 'item', formatter: '{b}: {c} ({d}%)' }"
                  :chartStyle="{ height: '200px' }"
                />
              </div>
            </el-col>
            <el-col :span="8">
              <div class="result-card">
                <div class="result-title">成品</div>
                <Echart
                  :series="finishedProductSeries"
                  :tooltip="{ trigger: 'item', formatter: '{b}: {c} ({d}%)' }"
                  :chartStyle="{ height: '200px' }"
                />
              </div>
            </el-col>
          </el-row>
        </el-card>
      </el-col>
    </el-row>
 
    <!-- 紧急事项播报 -->
    <el-card shadow="hover">
      <div slot="header">
        <span>紧急事项</span>
        <el-button type="text" style="float: right;" @click="refreshVoiceQueue">
          <i class="el-icon-refresh" /> 刷新
        </el-button>
      </div>
      <el-table :data="urgentItems" border style="width: 100%" max-height="200">
        <el-table-column prop="type" label="类型" width="120" />
        <el-table-column prop="content" label="内容" />
        <el-table-column prop="time" label="时间" width="180" />
        <el-table-column prop="level" label="级别" width="100">
          <template slot-scope="scope">
            <el-tag :type="getLevelType(scope.row.level)">{{ scope.row.level }}</el-tag>
          </template>
        </el-table-column>
        <el-table-column label="操作" width="100">
          <template slot-scope="scope">
            <el-button type="text" size="mini" @click="speakContent(scope.row.content)">播报</el-button>
          </template>
        </el-table-column>
      </el-table>
    </el-card>
  </div>
</template>
 
<script>
import Echart from '@/components/echarts/echarts.vue'
import {
  getOverview,
  getHistory15Days,
  getFuture15Days,
  getRanking,
  getInsResult,
  getVoiceQueue
} from '@/api/report/dashboard'
 
export default {
  name: 'TestHall',
  components: { Echart },
  data() {
    return {
      overviewData: {},
      futureTasks: [],
      rankingData: [],
      rankingType: 'record',
      urgentItems: [],
      voiceEnabled: true,
      refreshTimer: null,
      // 历史15天图表配置
      historyXAxis: [{ type: 'category', data: [] }],
      historyYAxis: [{ type: 'value' }],
      historySeries: [
        { name: '检测任务', type: 'bar', data: [] },
        { name: '完成任务', type: 'line', data: [] }
      ],
      // 检验结果饼图配置
      rawMaterialSeries: [{
        type: 'pie',
        radius: ['50%', '70%'],
        data: [
          { name: '合格', value: 0, itemStyle: { color: '#67C23A' } },
          { name: '不合格', value: 0, itemStyle: { color: '#F56C6C' } }
        ]
      }],
      semiProductSeries: [{
        type: 'pie',
        radius: ['50%', '70%'],
        data: [
          { name: '合格', value: 0, itemStyle: { color: '#67C23A' } },
          { name: '不合格', value: 0, itemStyle: { color: '#F56C6C' } }
        ]
      }],
      finishedProductSeries: [{
        type: 'pie',
        radius: ['50%', '70%'],
        data: [
          { name: '合格', value: 0, itemStyle: { color: '#67C23A' } },
          { name: '不合格', value: 0, itemStyle: { color: '#F56C6C' } }
        ]
      }]
    }
  },
  mounted() {
    this.initDashboard()
    this.startAutoRefresh()
  },
  beforeDestroy() {
    this.stopAutoRefresh()
  },
  methods: {
    // 初始化看板数据
    async initDashboard() {
      await Promise.all([
        this.getOverviewData(),
        this.getHistoryData(),
        this.getFutureData(),
        this.getRankingData(),
        this.getInsResultData(),
        this.refreshVoiceQueue()
      ])
    },
    // 获取概览数据
    getOverviewData() {
      return getOverview().then(res => {
        this.overviewData = res.data || {}
      })
    },
    // 获取历史15天数据
    getHistoryData() {
      return getHistory15Days().then(res => {
        this.historyXAxis[0].data = res.data.dates || []
        this.historySeries[0].data = res.data.taskCounts || []
        this.historySeries[1].data = res.data.finishCounts || []
      })
    },
    // 获取未来15天任务
    getFutureData() {
      return getFuture15Days().then(res => {
        this.futureTasks = res.data || []
      })
    },
    // 获取提交排行
    getRankingData() {
      return getRanking({ type: this.rankingType }).then(res => {
        this.rankingData = res.data || []
      })
    },
    // 获取检验结果统计
    getInsResultData() {
      return getInsResult().then(res => {
        if (res.data.rawMaterial) {
          this.rawMaterialSeries[0].data[0].value = res.data.rawMaterial.passCount || 0
          this.rawMaterialSeries[0].data[1].value = res.data.rawMaterial.unpassCount || 0
        }
        if (res.data.semiProduct) {
          this.semiProductSeries[0].data[0].value = res.data.semiProduct.passCount || 0
          this.semiProductSeries[0].data[1].value = res.data.semiProduct.unpassCount || 0
        }
        if (res.data.finishedProduct) {
          this.finishedProductSeries[0].data[0].value = res.data.finishedProduct.passCount || 0
          this.finishedProductSeries[0].data[1].value = res.data.finishedProduct.unpassCount || 0
        }
      })
    },
    // 刷新语音播报队列
    refreshVoiceQueue() {
      return getVoiceQueue().then(res => {
        this.urgentItems = res.data || []
      })
    },
    // 切换语音播报状态
    toggleVoice() {
      this.voiceEnabled = !this.voiceEnabled
      if (this.voiceEnabled) {
        this.$message.success('语音播报已开启')
      } else {
        this.$message.info('语音播报已关闭')
      }
    },
    // 语音播报内容
    speakContent(content) {
      if ('speechSynthesis' in window) {
        const utterance = new SpeechSynthesisUtterance(content)
        utterance.lang = 'zh-CN'
        speechSynthesis.speak(utterance)
      } else {
        this.$message.warning('当前浏览器不支持语音播报')
      }
    },
    // 开启自动刷新
    startAutoRefresh() {
      this.refreshTimer = setInterval(() => {
        this.initDashboard()
      }, 30000)
    },
    // 停止自动刷新
    stopAutoRefresh() {
      if (this.refreshTimer) {
        clearInterval(this.refreshTimer)
        this.refreshTimer = null
      }
    },
    // 获取排行样式类
    getRankingClass(index) {
      if (index === 0) return 'first'
      if (index === 1) return 'second'
      if (index === 2) return 'third'
      return ''
    },
    // 获取级别标签类型
    getLevelType(level) {
      const map = { '紧急': 'danger', '重要': 'warning', '普通': 'info' }
      return map[level] || 'info'
    }
  }
}
</script>
 
<style scoped>
.dashboard-container {
  background: #f0f2f5;
  min-height: calc(100vh - 84px);
}
.stat-card-wrapper {
  cursor: pointer;
}
.stat-card {
  display: flex;
  align-items: center;
  padding: 10px;
}
.stat-icon {
  width: 50px;
  height: 50px;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
}
.stat-icon i {
  font-size: 24px;
  color: #fff;
}
.stat-content {
  margin-left: 10px;
}
.stat-title {
  font-size: 12px;
  color: #909399;
}
.stat-value {
  font-size: 22px;
  font-weight: bold;
  color: #303133;
  margin-top: 5px;
}
.voice-control {
  cursor: pointer;
}
.voice-content {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 15px;
  color: #409EFF;
}
.voice-content i {
  font-size: 32px;
}
.voice-content span {
  font-size: 12px;
  margin-top: 8px;
}
.future-task-card {
  height: 380px;
  overflow: auto;
}
.future-task-list {
  padding: 10px;
}
.future-task-item {
  display: flex;
  align-items: center;
  margin-bottom: 15px;
}
.task-date {
  width: 80px;
  font-size: 12px;
  color: #606266;
}
.task-count {
  width: 60px;
  text-align: right;
  font-size: 12px;
  color: #909399;
}
.ranking-list {
  padding: 10px;
}
.ranking-item {
  display: flex;
  align-items: center;
  margin-bottom: 12px;
}
.ranking-index {
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: #909399;
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
}
.ranking-index.first { background: #FFD700; }
.ranking-index.second { background: #C0C0C0; }
.ranking-index.third { background: #CD7F32; }
.ranking-name {
  width: 80px;
  margin-left: 10px;
  font-size: 14px;
}
.ranking-count {
  width: 50px;
  text-align: right;
  font-size: 14px;
  color: #606266;
}
.result-card {
  text-align: center;
}
.result-title {
  font-size: 14px;
  color: #606266;
  margin-bottom: 10px;
}
</style>