ZN
8 小时以前 077ab59c700b85efdd057265bf752ad5942395b2
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
<template>
  <view class="quality-dashboard-page">
    <PageHeader title="质量看板" @back="goBack" />
    
    <scroll-view scroll-y class="dashboard-scroll">
      <!-- 样品状态列表 -->
      <view class="dashboard-card">
        <view class="card-header">
          <text class="card-title">检测样品动态状态</text>
          <up-switch v-model="voiceEnabled" size="18" activeText="语音" inactiveText="静音"></up-switch>
        </view>
        <view class="status-list">
          <view v-for="item in sampleStatus" :key="item.id" class="status-item">
            <view class="status-left">
              <view class="status-dot" :class="item.status"></view>
              <text class="sample-name">{{ item.name }}</text>
            </view>
            <view class="status-right">
              <up-tag :text="statusLabel(item.status)" :type="statusTagType(item.status)" size="mini"></up-tag>
              <text class="sample-time">{{ item.time }}</text>
            </view>
          </view>
        </view>
      </view>
 
      <!-- 合格率分析 (仪表盘) -->
      <view class="dashboard-card">
        <view class="card-header">
          <text class="card-title">合格率分析</text>
        </view>
        <view class="chart-box">
          <qiun-data-charts
            type="gauge"
            :opts="gaugeOpts"
            :chartData="gaugeData"
          />
        </view>
        <view class="passrate-summary">
          <text>当前合格率:</text>
          <text class="highlight">{{ (passRate * 100).toFixed(1) }}%</text>
        </view>
      </view>
 
      <!-- 任务排行 (柱状图) -->
      <view class="dashboard-card">
        <view class="card-header">
          <text class="card-title">任务排行 (Top 10)</text>
        </view>
        <view class="chart-box">
          <qiun-data-charts
            type="column"
            :opts="columnOpts"
            :chartData="columnData"
          />
        </view>
      </view>
 
      <!-- 历史趋势 (折线图) -->
      <view class="dashboard-card">
        <view class="card-header">
          <text class="card-title">历史趋势</text>
        </view>
        <view class="chart-box">
          <qiun-data-charts
            type="line"
            :opts="lineOpts"
            :chartData="lineData"
          />
        </view>
      </view>
    </scroll-view>
  </view>
</template>
 
<script setup>
import { ref, reactive, onMounted, onBeforeUnmount } from 'vue';
 
const voiceEnabled = ref(false);
let dataTimer = null;
 
// 1) 样品动态状态
const sampleStatus = ref([]);
const statusPool = ['processing', 'warning', 'error', 'success'];
 
const statusLabel = (s) => {
  const labels = { 'processing': '检测中', 'warning': '预警', 'error': '不合格', 'success': '合格' };
  return labels[s] || '未知';
};
 
const statusTagType = (s) => {
  const types = { 'processing': 'primary', 'warning': 'warning', 'error': 'error', 'success': 'success' };
  return types[s] || 'info';
};
 
const randomSample = () => {
  const id = Math.random().toString(36).slice(2, 8);
  const status = statusPool[Math.floor(Math.random() * statusPool.length)];
  const name = `样品-${Math.floor(Math.random() * 900 + 100)}`;
  const time = new Date().toLocaleTimeString('zh-CN', { hour12: false });
  return { id, name, status, time };
};
 
// 2) 合格率分析 (仪表盘)
const passRate = ref(0.92);
const gaugeData = ref({
  categories: [{ value: 0.92, color: "#2fc25b" }],
  series: [{ name: "合格率", data: 0.92 }]
});
const gaugeOpts = {
  title: { name: "合格率", color: "#2fc25b", fontSize: 16 },
  subtitle: { name: "92%", color: "#666666", fontSize: 12 },
  extra: { gauge: { type: "default", width: 15, labelColor: "#666666", splitLine: { fixRadius: -10 } } }
};
 
// 3) 任务排行 (柱状图)
const columnData = ref({
  categories: ["任务1", "任务2", "任务3", "任务4", "任务5"],
  series: [{ name: "完成数", data: [35, 36, 31, 33, 13] }]
});
const columnOpts = {
  color: ["#1890FF"],
  padding: [15, 15, 0, 5],
  enableScroll: false,
  xAxis: { disableGrid: true },
  yAxis: { data: [{ min: 0 }] },
  extra: { column: { type: "group", width: 30, activeBgColor: "#000000", activeBgOpacity: 0.08 } }
};
 
// 4) 历史趋势 (折线图)
const lineData = ref({
  categories: ["10:00", "10:05", "10:10", "10:15", "10:20"],
  series: [
    { name: "来样数", data: [35, 8, 25, 37, 4, 20] },
    { name: "完成数", data: [70, 40, 65, 100, 44, 68] }
  ]
});
const lineOpts = {
  color: ["#1890FF", "#91CB74"],
  padding: [15, 10, 0, 15],
  enableScroll: false,
  xAxis: { disableGrid: true },
  yAxis: { gridType: "dash", dashLength: 2 },
  legend: { position: "top" },
  extra: { line: { type: "straight", width: 2 } }
};
 
const refreshData = () => {
  // 模拟数据更新
  const next = randomSample();
  sampleStatus.value = [next, ...sampleStatus.value].slice(0, 5);
  
  const delta = (Math.random() - 0.5) * 0.02;
  passRate.value = Math.min(0.99, Math.max(0.6, passRate.value + delta));
  gaugeData.value = {
    series: [{ name: "合格率", data: passRate.value }]
  };
  gaugeOpts.subtitle.name = (passRate.value * 100).toFixed(1) + '%';
};
 
const goBack = () => {
  uni.navigateBack();
};
 
onMounted(() => {
  for (let i = 0; i < 5; i++) {
    sampleStatus.value.push(randomSample());
  }
  dataTimer = setInterval(refreshData, 3000);
});
 
onBeforeUnmount(() => {
  if (dataTimer) clearInterval(dataTimer);
});
</script>
 
<style lang="scss" scoped>
.quality-dashboard-page {
  background-color: #f5f7fa;
  height: 100vh;
  display: flex;
  flex-direction: column;
}
 
.dashboard-scroll {
  flex: 1;
  padding: 20rpx;
}
 
.dashboard-card {
  background-color: #ffffff;
  border-radius: 16rpx;
  padding: 30rpx;
  margin-bottom: 30rpx;
  box-shadow: 0 2rpx 12rpx rgba(0, 0, 0, 0.05);
}
 
.card-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 30rpx;
  border-left: 8rpx solid #3c9cff;
  padding-left: 20rpx;
}
 
.card-title {
  font-size: 30rpx;
  font-weight: bold;
  color: #303133;
}
 
.status-list {
  display: flex;
  flex-direction: column;
  gap: 20rpx;
}
 
.status-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10rpx 0;
}
 
.status-left {
  display: flex;
  align-items: center;
  gap: 15rpx;
}
 
.status-dot {
  width: 12rpx;
  height: 12rpx;
  border-radius: 50%;
  
  &.processing { background-color: #3c9cff; }
  &.warning { background-color: #f9ae3d; }
  &.error { background-color: #f56c6c; }
  &.success { background-color: #5ac725; }
}
 
.sample-name {
  font-size: 28rpx;
  color: #303133;
}
 
.status-right {
  display: flex;
  align-items: center;
  gap: 20rpx;
}
 
.sample-time {
  font-size: 24rpx;
  color: #909399;
}
 
.chart-box {
  width: 100%;
  height: 400rpx;
}
 
.passrate-summary {
  text-align: center;
  margin-top: 20rpx;
  font-size: 28rpx;
  color: #606266;
  
  .highlight {
    font-size: 36rpx;
    font-weight: bold;
    color: #3c9cff;
    margin-left: 10rpx;
  }
}
</style>