gaoluyang
6 天以前 bc365ef47ae4e01754aeadbae26170e11c9bb80e
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
<template>
  <div>
    <div class="warn-panel">
      <div class="warn-header">
        <div class="warn-header-left">
          <div class="warn-badge"></div>
          <span class="warn-title">不合格预警</span>
        </div>
        <div class="warn-range" @click="handleRangeClick">近7天</div>
      </div>
 
      <div class="warn-body">
        <div class="warn-list" role="list">
          <div v-for="item in warnings" :key="item.id" class="warn-item" role="listitem" @click="openWarning(item)">
            <div class="warn-tag" :class="tagClass(item.type)">{{ item.parentProductTitle }}-{{ item.productTitle }}
            </div>
            <div class="warn-text" :title="item.title">{{ item.title }}</div>
            <div class="warn-action" @click.stop="openWarning(item)">查看</div>
            <div class="warn-date">{{ item.date }}</div>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>
 
<script setup>
import { computed, getCurrentInstance, ref, onMounted } from 'vue'
import Echarts from '@/components/Echarts/echarts.vue'
import { nonComplianceWarning } from '@/api/viewIndex.js'
 
const { proxy } = getCurrentInstance() || {}
 
const warnings = ref([])
 
// 占比数据
const ratios = ref({
  rawMaterialRatio: 0,
  semiFinishedProductRatio: 0,
  finishedProductRatio: 0,
})
 
const TAG_COLORS = {
  raw: '#7C4DFF',
  final: '#F5A000',
  semi: '#FF66CC',
}
 
const tagClass = (type) => {
  if (type === 'raw') return 'tag-raw'
  if (type === 'final') return 'tag-final'
  return 'tag-semi'
}
 
// 根据productTitle映射类型
const mapProductTitleToType = (productTitle) => {
  if (productTitle === '原材料') return 'raw'
  if (productTitle === '半成品') return 'semi'
  if (productTitle === '成品') return 'final'
  return 'raw' // 默认值
}
 
const pieChartStyle = { width: '100%', height: '100%' }
 
const pieOptions = {
  backgroundColor: 'transparent',
  textStyle: { color: '#B8C8E0' },
}
 
const pieTooltip = {
  trigger: 'item',
  formatter: (p) => `${p.name}:${p.value}%`,
}
 
const pieData = computed(() => {
  return [
    { name: '原材料', value: ratios.value.rawMaterialRatio, itemStyle: { color: TAG_COLORS.raw } },
    { name: '半成品', value: ratios.value.semiFinishedProductRatio, itemStyle: { color: TAG_COLORS.semi } },
    { name: '成品', value: ratios.value.finishedProductRatio, itemStyle: { color: TAG_COLORS.final } },
  ]
})
 
const pieSeries = computed(() => {
  return [
    {
      type: 'pie',
      radius: ['0%', '68%'],
      center: ['50%', '50%'],
      startAngle: 90,
      clockwise: true,
      avoidLabelOverlap: true,
      label: { show: false },
      labelLine: { show: false },
      itemStyle: {
        borderColor: '#071a3a',
        borderWidth: 4,
        shadowBlur: 14,
        shadowColor: 'rgba(0, 0, 0, 0.35)',
      },
      data: pieData.value,
    },
    {
      // 内圈暗环,增强层次
      type: 'pie',
      radius: ['70%', '74%'],
      center: ['50%', '50%'],
      silent: true,
      label: { show: false },
      labelLine: { show: false },
      itemStyle: { color: 'rgba(78, 228, 255, 0.12)' },
      data: [1],
    },
  ]
})
 
const fetchWarnings = async () => {
  try {
    const res = await nonComplianceWarning()
    if (res?.code === 200 && res?.data) {
      const data = res.data
 
      // 更新占比数据
      ratios.value = {
        rawMaterialRatio: data.rawMaterialRatio ?? 0,
        semiFinishedProductRatio: data.semiFinishedProductRatio ?? 0,
        finishedProductRatio: data.finishedProductRatio ?? 0,
      }
 
      // 更新警告列表
      const children = data.children || []
      warnings.value = children.map((item, idx) => {
        const type = mapProductTitleToType(item.parentProductTitle)
        const date = item.date ? item.date.replace(/-/g, '.') : ''
        return {
          id: item.id ?? `warning-${idx}`,
          type,
          parentProductTitle: item.parentProductTitle || '原材料',
          productTitle: item.productTitle || '原材料',
          title: item.description || '不合格预警',
          date,
        }
      })
    }
  } catch (e) {
    // 接口失败则保持空数据
    console.error('获取不合格预警失败:', e)
  }
}
 
const openWarning = (item) => {
  const title = `【${item.parentProductTitle}-${item.productTitle}】${item.title}`
  if (proxy?.$modal?.alert) {
    proxy.$modal.alert(title)
    return
  }
  // 兜底:没有全局 modal 时用 console
  console.log('warning:', { ...item })
}
 
const handleRangeClick = () => {
  // 先按截图做静态“近7天”,后续有真实筛选需求再接入
}
 
onMounted(() => {
  fetchWarnings()
})
</script>
 
<style scoped>
.warn-panel {
  border: 1px solid #1a58b0;
  padding: 0 18px 18px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  height: 100%;
  box-sizing: border-box;
  position: relative;
  overflow: hidden;
}
 
/* 预警面板角落装饰 */
.warn-panel::before,
.warn-panel::after {
  content: '';
  position: absolute;
  width: 15px;
  height: 15px;
  border-color: rgba(255, 77, 79, 0.5);
  border-style: solid;
  pointer-events: none;
}
 
.warn-panel::before {
  top: -1px;
  left: -1px;
  border-width: 2px 0 0 2px;
}
 
.warn-panel::after {
  bottom: -1px;
  right: -1px;
  border-width: 0 2px 2px 0;
}
 
/* 预警脉冲背景 */
.warn-panel::after {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: radial-gradient(circle at 50% 50%, rgba(255, 77, 79, 0.05) 0%, transparent 70%);
  pointer-events: none;
  animation: warnPulse 4s ease-in-out infinite;
  z-index: 0;
}
 
@keyframes warnPulse {
  0%, 100% { opacity: 0.3; }
  50% { opacity: 0.6; }
}
 
.warn-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid;
  border-image: linear-gradient(270deg,
      rgba(0, 126, 255, 0) 0%,
      rgba(0, 126, 255, 0.4549) 35%,
      #007eff 78%,
      #007eff 100%) 1;
  padding: 10px 0 6px;
  position: relative;
  z-index: 1;
}
 
.warn-header-left {
  display: flex;
  align-items: center;
  gap: 10px;
}
 
.warn-badge {
  width: 18px;
  height: 18px;
  background: linear-gradient(180deg, #2aa8ff 0%, #4ee4ff 100%);
  clip-path: polygon(50% 0%, 100% 50%, 50% 100%, 0% 50%);
  box-shadow: 0 0 12px rgba(78, 228, 255, 0.25);
  animation: badgePulse 2s ease-in-out infinite;
}
 
@keyframes badgePulse {
  0%, 100% { transform: scale(1); box-shadow: 0 0 12px rgba(78, 228, 255, 0.25); }
  50% { transform: scale(1.1); box-shadow: 0 0 20px rgba(78, 228, 255, 0.5); }
}
 
.warn-title {
  font-weight: 600;
  font-size: 18px;
  background: linear-gradient(360deg, #056dff 0%, #43e8fc 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  line-height: 24px;
  animation: titleGlow 3s ease-in-out infinite;
}
 
@keyframes titleGlow {
  0%, 100% { filter: brightness(1); }
  50% { filter: brightness(1.2); }
}
 
.warn-range {
  height: 32px;
  padding: 0 14px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 4px;
  color: #ffffff;
  font-weight: 600;
  background: linear-gradient(180deg, rgba(51, 120, 255, 1) 0%, rgba(0, 164, 237, 1) 100%);
  border: 1px solid rgba(78, 228, 255, 0.25);
  cursor: pointer;
  transition: all 0.3s ease;
}
 
.warn-range:hover {
  background: linear-gradient(180deg, rgba(51, 140, 255, 1) 0%, rgba(0, 184, 237, 1) 100%);
  box-shadow: 0 0 15px rgba(0, 212, 255, 0.4);
  transform: translateY(-1px);
}
 
.warn-body {
  display: grid;
  gap: 18px;
  align-items: stretch;
  min-height: 260px;
  position: relative;
  z-index: 1;
}
 
.warn-list {
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding-top: 6px;
}
 
.warn-item {
  display: grid;
  grid-template-columns: 130px 1fr auto 110px;
  align-items: center;
  gap: 12px;
  color: #b8c8e0;
  font-size: 14px;
  line-height: 1.2;
  padding: 8px 0;
  border-radius: 4px;
  transition: all 0.3s ease;
  position: relative;
  animation: itemFadeIn 0.5s ease-out both;
}
 
@keyframes itemFadeIn {
  from {
    opacity: 0;
    transform: translateX(20px);
  }
  to {
    opacity: 1;
    transform: translateX(0);
  }
}
 
.warn-item::before {
  content: '';
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  height: 1px;
  background: linear-gradient(90deg, transparent, rgba(255, 77, 79, 0.2), transparent);
  opacity: 0;
  transition: opacity 0.3s;
}
 
.warn-item:hover {
  color: #ff4d4f;
  background-color: rgba(255, 77, 79, 0.08);
}
 
.warn-item:hover::before {
  opacity: 1;
}
 
.warn-item:hover .warn-text {
  color: #ff4d4f;
}
 
.warn-tag {
  height: 28px;
  padding: 0 10px;
  border-radius: 4px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  color: #ffffff;
  transition: all 0.3s ease;
  position: relative;
  overflow: hidden;
}
 
/* 标签发光效果 */
.warn-tag::after {
  content: '';
  position: absolute;
  top: 0;
  left: -100%;
  width: 100%;
  height: 100%;
  background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.2), transparent);
  animation: tagShine 3s ease-in-out infinite;
}
 
@keyframes tagShine {
  0% { left: -100%; }
  50%, 100% { left: 100%; }
}
 
.warn-item:hover .warn-tag {
  transform: scale(1.02);
  box-shadow: 0 0 15px currentColor;
}
 
.tag-raw {
  background: #7c4dff;
}
 
.tag-final {
  background: #f5a000;
}
 
.tag-semi {
  background: #ff66cc;
}
 
.warn-text {
  color: #e8f1ff;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
 
.warn-action {
  color: #ff4d4f;
  font-weight: 700;
  white-space: nowrap;
  cursor: pointer;
  transition: all 0.3s ease;
}
 
.warn-item:hover .warn-action {
  text-shadow: 0 0 10px rgba(255, 77, 79, 0.5);
}
 
.warn-date {
  color: rgba(184, 200, 224, 0.75);
  white-space: nowrap;
}
 
.warn-chart {
  display: flex;
  align-items: center;
  justify-content: center;
}
 
.chart-frame {
  width: 100%;
  height: 260px;
  border: 2px dashed rgba(184, 200, 224, 0.35);
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  background: radial-gradient(circle at 50% 50%, rgba(78, 228, 255, 0.08) 0%, rgba(0, 0, 0, 0) 65%);
}
 
/* 外圈刻度环 */
.chart-frame::before {
  content: '';
  position: absolute;
  width: 220px;
  height: 220px;
  border-radius: 50%;
  background: repeating-conic-gradient(from 0deg, rgba(78, 228, 255, 0.75) 0 1deg, rgba(78, 228, 255, 0) 1deg 9deg);
  -webkit-mask: radial-gradient(circle, transparent 62%, #000 63%);
  mask: radial-gradient(circle, transparent 62%, #000 63%);
  opacity: 0.5;
  pointer-events: none;
  animation: ringRotate 20s linear infinite;
}
 
@keyframes ringRotate {
  from { transform: rotate(0deg); }
  to { transform: rotate(360deg); }
}
 
/* 十字辅助线 */
.chart-frame::after {
  content: '';
  position: absolute;
  width: 240px;
  height: 240px;
  background:
    linear-gradient(to right, rgba(78, 228, 255, 0) 0%, rgba(78, 228, 255, 0.55) 50%, rgba(78, 228, 255, 0) 100%),
    linear-gradient(to bottom, rgba(78, 228, 255, 0) 0%, rgba(78, 228, 255, 0.55) 50%, rgba(78, 228, 255, 0) 100%);
  background-size: 100% 1px, 1px 100%;
  background-position: center, center;
  background-repeat: no-repeat;
  opacity: 0.35;
  pointer-events: none;
  animation: crossPulse 3s ease-in-out infinite;
}
 
@keyframes crossPulse {
  0%, 100% { opacity: 0.35; }
  50% { opacity: 0.5; }
}
</style>