yaowanxin
2025-09-26 7d5d50d0c80738d56c2e6e0a643c45849c796d5b
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
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
<template>
  <div class="kpl-monitor-container">
    <!-- 页面头部 -->
    <div class="page-header">
      <div class="header-content">
        <h1>KPL监控分析</h1>
        <p>设备关键性能指标监控与维保策略优化</p>
      </div>
      <div class="time-range">
        <el-date-picker
          v-model="timeRange"
          type="daterange"
          range-separator="至"
          start-placeholder="开始日期"
          end-placeholder="结束日期"
          value-format="YYYY-MM-DD"
          @change="fetchKPLData"
        />
      </div>
    </div>
 
    <!-- 关键指标概览 -->
    <div class="metrics-overview">
      <div class="metric-card mtbf-card">
        <div class="metric-icon">⏱️</div>
        <div class="metric-content">
          <div class="metric-title">MTBF</div>
          <div class="metric-subtitle">平均无故障时间</div>
          <div class="metric-value">{{ currentMTBF }}<span class="unit">小时</span></div>
          <div class="metric-trend" :class="mtbfTrendClass">
            <span class="trend-icon">{{ mtbfTrendText }}</span>
            <span class="trend-text">{{ Math.abs(mtbfChange) }}%</span>
          </div>
        </div>
      </div>
 
      <div class="metric-card mttr-card">
        <div class="metric-icon">🔧</div>
        <div class="metric-content">
          <div class="metric-title">MTTR</div>
          <div class="metric-subtitle">平均修复时间</div>
          <div class="metric-value">{{ currentMTTR }}<span class="unit">小时</span></div>
          <div class="metric-trend" :class="mttrTrendClass">
            <span class="trend-icon">{{ mttrTrendText }}</span>
            <span class="trend-text">{{ Math.abs(mttrChange) }}%</span>
          </div>
        </div>
      </div>
 
      <div class="metric-card availability-card">
        <div class="metric-icon">📊</div>
        <div class="metric-content">
          <div class="metric-title">设备可用率</div>
          <div class="metric-subtitle">运行效率指标</div>
          <div class="metric-value">{{ currentAvailability }}<span class="unit">%</span></div>
          <div class="metric-trend" :class="availabilityTrendClass">
            <span class="trend-icon">{{ availabilityTrendText }}</span>
            <span class="trend-text">{{ Math.abs(availabilityChange) }}%</span>
          </div>
        </div>
      </div>
    </div>
 
    <!-- 趋势分析图表 -->
    <div class="charts-section">
      <div class="chart-container">
        <div class="chart-header">
          <h3>MTBF & MTTR 趋势分析</h3>
          <div class="chart-legend">
            <span class="legend-item mtbf-legend">
              <span class="legend-color"></span>
              MTBF (平均无故障时间)
            </span>
            <span class="legend-item mttr-legend">
              <span class="legend-color"></span>
              MTTR (平均修复时间)
            </span>
          </div>
        </div>
        <div class="chart-wrapper">
          <div ref="trendChart" class="chart"></div>
        </div>
      </div>
    </div>
 
    <!-- 维保策略建议 -->
    <div class="recommendations-section">
      <div class="section-header">
        <h3>维保策略优化建议</h3>
        <p>基于当前指标分析,为您提供针对性的优化建议</p>
      </div>
      <div class="recommendations-grid">
        <div 
          v-for="(recommendation, index) in recommendations" 
          :key="index"
          class="recommendation-card"
        >
          <div class="recommendation-icon">{{ recommendation.icon }}</div>
          <div class="recommendation-content">
            <h4>{{ recommendation.title }}</h4>
            <p>{{ recommendation.description }}</p>
            <div class="recommendation-priority" :class="recommendation.priority">
              {{ recommendation.priorityText }}
            </div>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>
 
<script setup>
import { ref, reactive, onMounted, computed, nextTick } from 'vue'
import * as echarts from 'echarts'
 
// 生成模拟数据
const generateMockData = () => {
  const months = ['1月', '2月', '3月', '4月', '5月', '6月', '7月', '8月', '9月', '10月', '11月', '12月']
  const mtbfData = months.map(() => Math.floor(Math.random() * 200 + 300)) // 300-500小时
  const mttrData = months.map(() => Math.floor(Math.random() * 8 + 4)) // 4-12小时
  
  return {
    months,
    mtbfData,
    mttrData
  }
}
 
const timeRange = ref([
  new Date(new Date().getFullYear(), 0, 1).toISOString().split('T')[0],
  new Date().toISOString().split('T')[0]
])
 
const mockData = reactive(generateMockData())
 
// 计算当前指标值
const currentMTBF = computed(() => mockData.mtbfData[mockData.mtbfData.length - 1])
const currentMTTR = computed(() => mockData.mttrData[mockData.mttrData.length - 1])
const currentAvailability = computed(() => 
  Math.round((currentMTBF.value / (currentMTBF.value + currentMTTR.value)) * 100)
)
 
// 计算变化趋势
const mtbfChange = computed(() => {
  const current = currentMTBF.value
  const previous = mockData.mtbfData[mockData.mtbfData.length - 2] || current
  return Math.round(((current - previous) / previous) * 100)
})
 
const mttrChange = computed(() => {
  const current = currentMTTR.value
  const previous = mockData.mttrData[mockData.mttrData.length - 2] || current
  return Math.round(((current - previous) / previous) * 100)
})
 
const availabilityChange = computed(() => {
  const current = currentAvailability.value
  const previous = Math.round(
    (mockData.mtbfData[mockData.mtbfData.length - 2] / 
    (mockData.mtbfData[mockData.mtbfData.length - 2] + mockData.mttrData[mockData.mttrData.length - 2])) * 100
  ) || current
  return Math.round(((current - previous) / previous) * 100)
})
 
// 趋势样式和文本
const mtbfTrendClass = computed(() => mtbfChange.value >= 0 ? 'trend-up' : 'trend-down')
const mttrTrendClass = computed(() => mttrChange.value <= 0 ? 'trend-up' : 'trend-down')
const availabilityTrendClass = computed(() => availabilityChange.value >= 0 ? 'trend-up' : 'trend-down')
 
const mtbfTrendText = computed(() => mtbfChange.value >= 0 ? '↗' : '↘')
const mttrTrendText = computed(() => mttrChange.value <= 0 ? '↗' : '↘')
const availabilityTrendText = computed(() => availabilityChange.value >= 0 ? '↗' : '↘')
 
// 智能维保建议
const recommendations = computed(() => {
  const suggestions = []
  
  // MTBF相关建议
  if (currentMTBF.value < 400) {
    suggestions.push({
      icon: '🔧',
      title: '提升MTBF',
      description: '当前MTBF较低,建议加强预防性维护,定期检查关键部件,延长设备无故障运行时间',
      priority: 'high',
      priorityText: '高优先级'
    })
  }
  
  // MTTR相关建议
  if (currentMTTR.value > 8) {
    suggestions.push({
      icon: '⚡',
      title: '优化MTTR',
      description: '当前MTTR较高,建议优化维修流程,提高维修人员技能,缩短故障修复时间',
      priority: 'high',
      priorityText: '高优先级'
    })
  }
  
  // 可用率相关建议
  if (currentAvailability.value < 95) {
    suggestions.push({
      icon: '📈',
      title: '提升可用率',
      description: '设备可用率有待提升,建议优化维保计划安排,减少计划外停机时间',
      priority: 'medium',
      priorityText: '中优先级'
    })
  }
  
  // 综合建议
  if (currentMTBF.value >= 400 && currentMTTR.value <= 8 && currentAvailability.value >= 95) {
    suggestions.push({
      icon: '✅',
      title: '运行状况良好',
      description: '当前设备运行状况良好,各项指标均达到预期,建议继续保持现有维保策略',
      priority: 'low',
      priorityText: '低优先级'
    })
  }
  
  // 预防性建议
  suggestions.push({
    icon: '📋',
    title: '预防性维护',
    description: '建议建立设备健康档案,定期分析设备运行数据,提前识别潜在故障风险',
    priority: 'medium',
    priorityText: '中优先级'
  })
  
  return suggestions
})
 
// 图表实例
let trendChart = null
 
const initChart = () => {
  nextTick(() => {
    trendChart = echarts.init(document.querySelector('.chart'))
    trendChart.setOption({
      tooltip: {
        trigger: 'axis',
        axisPointer: {
          type: 'cross'
        }
      },
      legend: {
        data: ['MTBF', 'MTTR'],
        top: 10
      },
      grid: {
        left: '3%',
        right: '4%',
        bottom: '3%',
        containLabel: true
      },
      xAxis: {
        type: 'category',
        data: mockData.months,
        axisLine: {
          lineStyle: {
            color: '#e0e0e0'
          }
        }
      },
      yAxis: [
        {
          type: 'value',
          name: 'MTBF (小时)',
          position: 'left',
          axisLine: {
            lineStyle: {
              color: '#1890ff'
            }
          },
          axisLabel: {
            formatter: '{value}h'
          }
        },
        {
          type: 'value',
          name: 'MTTR (小时)',
          position: 'right',
          axisLine: {
            lineStyle: {
              color: '#52c41a'
            }
          },
          axisLabel: {
            formatter: '{value}h'
          }
        }
      ],
      series: [
        {
          name: 'MTBF',
          type: 'line',
          yAxisIndex: 0,
          data: mockData.mtbfData,
          smooth: true,
          lineStyle: {
            color: '#1890ff',
            width: 3
          },
          itemStyle: {
            color: '#1890ff'
          },
          areaStyle: {
            color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [
              { offset: 0, color: 'rgba(24, 144, 255, 0.3)' },
              { offset: 1, color: 'rgba(24, 144, 255, 0.1)' }
            ])
          }
        },
        {
          name: 'MTTR',
          type: 'line',
          yAxisIndex: 1,
          data: mockData.mttrData,
          smooth: true,
          lineStyle: {
            color: '#52c41a',
            width: 3
          },
          itemStyle: {
            color: '#52c41a'
          },
          areaStyle: {
            color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [
              { offset: 0, color: 'rgba(82, 196, 26, 0.3)' },
              { offset: 1, color: 'rgba(82, 196, 26, 0.1)' }
            ])
          }
        }
      ]
    })
  })
}
 
const fetchKPLData = () => {
  // 模拟数据刷新
  Object.assign(mockData, generateMockData())
  
  // 重新渲染图表
  if (trendChart) {
    trendChart.setOption({
      xAxis: {
        data: mockData.months
      },
      series: [
        {
          data: mockData.mtbfData
        },
        {
          data: mockData.mttrData
        }
      ]
    })
  }
}
 
onMounted(() => {
  initChart()
  
  // 监听窗口大小变化,重新调整图表大小
  window.addEventListener('resize', () => {
    if (trendChart) trendChart.resize()
  })
})
</script>
 
<style scoped>
.kpl-monitor-container {
  min-height: 100vh;
  background: linear-gradient(135deg, #f5f7fa 0%, #c3cfe2 100%);
  padding: 24px;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
}
 
/* 页面头部 */
.page-header {
  background: white;
  border-radius: 12px;
  padding: 24px;
  margin-bottom: 24px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
  display: flex;
  justify-content: space-between;
  align-items: center;
}
 
.header-content h1 {
  margin: 0 0 8px 0;
  color: #1f2937;
  font-size: 28px;
  font-weight: 700;
}
 
.header-content p {
  margin: 0;
  color: #6b7280;
  font-size: 16px;
}
 
.time-range {
  display: flex;
  align-items: center;
  gap: 12px;
}
 
/* 指标概览 */
.metrics-overview {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
  gap: 20px;
  margin-bottom: 24px;
}
 
.metric-card {
  background: white;
  border-radius: 12px;
  padding: 24px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
  display: flex;
  align-items: center;
  gap: 16px;
  transition: transform 0.2s ease, box-shadow 0.2s ease;
}
 
.metric-card:hover {
  transform: translateY(-2px);
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.15);
}
 
.metric-icon {
  font-size: 32px;
  width: 60px;
  height: 60px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 12px;
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
}
 
.mtbf-card .metric-icon {
  background: linear-gradient(135deg, #4facfe 0%, #00f2fe 100%);
}
 
.mttr-card .metric-icon {
  background: linear-gradient(135deg, #43e97b 0%, #38f9d7 100%);
}
 
.availability-card .metric-icon {
  background: linear-gradient(135deg, #fa709a 0%, #fee140 100%);
}
 
.metric-content {
  flex: 1;
}
 
.metric-title {
  font-size: 18px;
  font-weight: 600;
  color: #1f2937;
  margin-bottom: 4px;
}
 
.metric-subtitle {
  font-size: 14px;
  color: #6b7280;
  margin-bottom: 12px;
}
 
.metric-value {
  font-size: 32px;
  font-weight: 700;
  color: #1f2937;
  margin-bottom: 8px;
}
 
.unit {
  font-size: 16px;
  font-weight: 500;
  color: #6b7280;
  margin-left: 4px;
}
 
.metric-trend {
  display: flex;
  align-items: center;
  gap: 4px;
  font-size: 14px;
  font-weight: 600;
}
 
.trend-up {
  color: #10b981;
}
 
.trend-down {
  color: #ef4444;
}
 
.trend-icon {
  font-size: 16px;
}
 
/* 图表区域 */
.charts-section {
  margin-bottom: 24px;
}
 
.chart-container {
  background: white;
  border-radius: 12px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
  overflow: hidden;
}
 
.chart-header {
  padding: 20px 24px;
  border-bottom: 1px solid #e5e7eb;
  display: flex;
  justify-content: space-between;
  align-items: center;
}
 
.chart-header h3 {
  margin: 0;
  color: #1f2937;
  font-size: 18px;
  font-weight: 600;
}
 
.chart-legend {
  display: flex;
  gap: 20px;
}
 
.legend-item {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 14px;
  color: #6b7280;
}
 
.legend-color {
  width: 12px;
  height: 12px;
  border-radius: 2px;
}
 
.mtbf-legend .legend-color {
  background: #1890ff;
}
 
.mttr-legend .legend-color {
  background: #52c41a;
}
 
.chart-wrapper {
  padding: 20px;
  height: 400px;
}
 
.chart {
  width: 100%;
  height: 100%;
}
 
/* 建议区域 */
.recommendations-section {
  background: white;
  border-radius: 12px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
  overflow: hidden;
}
 
.section-header {
  padding: 24px;
  border-bottom: 1px solid #e5e7eb;
}
 
.section-header h3 {
  margin: 0 0 8px 0;
  color: #1f2937;
  font-size: 20px;
  font-weight: 600;
}
 
.section-header p {
  margin: 0;
  color: #6b7280;
  font-size: 14px;
}
 
.recommendations-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(350px, 1fr));
  gap: 20px;
  padding: 24px;
}
 
.recommendation-card {
  background: #f8fafc;
  border-radius: 8px;
  padding: 20px;
  display: flex;
  gap: 16px;
  transition: transform 0.2s ease, box-shadow 0.2s ease;
}
 
.recommendation-card:hover {
  transform: translateY(-1px);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
}
 
.recommendation-icon {
  font-size: 24px;
  width: 40px;
  height: 40px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 8px;
  background: white;
  flex-shrink: 0;
}
 
.recommendation-content {
  flex: 1;
}
 
.recommendation-content h4 {
  margin: 0 0 8px 0;
  color: #1f2937;
  font-size: 16px;
  font-weight: 600;
}
 
.recommendation-content p {
  margin: 0 0 12px 0;
  color: #6b7280;
  font-size: 14px;
  line-height: 1.5;
}
 
.recommendation-priority {
  display: inline-block;
  padding: 4px 8px;
  border-radius: 4px;
  font-size: 12px;
  font-weight: 500;
}
 
.priority.high {
  background: #fef2f2;
  color: #dc2626;
}
 
.priority.medium {
  background: #fffbeb;
  color: #d97706;
}
 
.priority.low {
  background: #f0fdf4;
  color: #16a34a;
}
 
/* 响应式设计 */
@media (max-width: 768px) {
  .kpl-monitor-container {
    padding: 16px;
  }
  
  .page-header {
    flex-direction: column;
    gap: 16px;
    align-items: stretch;
  }
  
  .metrics-overview {
    grid-template-columns: 1fr;
  }
  
  .recommendations-grid {
    grid-template-columns: 1fr;
  }
  
  .chart-wrapper {
    height: 300px;
  }
  
  .chart-legend {
    flex-direction: column;
    gap: 8px;
  }
}
 
@media (max-width: 480px) {
  .metric-card {
    flex-direction: column;
    text-align: center;
  }
  
  .recommendation-card {
    flex-direction: column;
    text-align: center;
  }
}
</style>