wangrong
2026-09-29 e2d1d78bc72459a0ac2e2e337bbca7c8a1e41e17
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
<template>
    <div class="screen-page dash">
        <!-- KPI 指标条 -->
        <div class="kpi-grid" style="--kpi-cols: 7">
            <kpi-card v-for="item in kpis" :key="item.label" v-bind="item" />
        </div>
 
        <!-- 主体三栏:左图表 / 中地图 / 右图表 -->
        <div class="dash-body">
            <!-- 左栏 -->
            <div class="dash-col dash-col--left">
                <panel-card
                    title="垃圾分类结构"
                    :demo="isDemoSection('wasteMix')"
                    class="dash-card dash-card--flex"
                >
                    <template #extra>
                        <cl-select-button v-model="mixMetric" :options="mixOptions" small />
                    </template>
                    <v-chart :option="mixOption" autoresize class="chart" />
                </panel-card>
 
                <panel-card
                    title="碳减排来源"
                    :demo="isDemoSection('recycleItems')"
                    class="dash-card dash-card--flex"
                >
                    <v-chart :option="carbonOption" autoresize class="chart" />
                </panel-card>
            </div>
 
            <!-- 中栏:地图主视觉 -->
            <div class="dash-col dash-col--center">
                <panel-card title="全域态势一张图" sub="站点 / 车辆 / 分拣员实时分布" class="dash-card dash-card--map">
                    <screen-map-panel />
                </panel-card>
            </div>
 
            <!-- 右栏 -->
            <div class="dash-col dash-col--right">
                <panel-card
                    title="回收趋势"
                    :demo="isDemoSection('trend')"
                    class="dash-card dash-card--flex"
                >
                    <template #extra>
                        <cl-select-button v-model="trendMetric" :options="trendOptions" small />
                    </template>
                    <v-chart :option="trendOption" autoresize class="chart" />
                </panel-card>
 
                <panel-card
                    title="各类回收量"
                    :demo="isDemoSection('recycleItems')"
                    class="dash-card dash-card--flex"
                >
                    <template #extra>
                        <cl-select-button v-model="itemMetric" :options="itemOptions" small />
                    </template>
                    <v-chart :option="itemOption" autoresize class="chart chart--items" />
                </panel-card>
            </div>
        </div>
 
        <!-- 底部:现场监控 -->
        <div class="dash-foot">
            <panel-card title="现场监控" sub="重点站点实时画面,首帧后暂停拉流以节省带宽">
                <template #extra>
                    <router-link class="camera-more" to="/monitor/device">更多</router-link>
                </template>
                <CameraMonitor :limit="6" />
            </panel-card>
        </div>
    </div>
</template>
 
<script lang="ts" setup>
defineOptions({
    name: 'report-screen-map'
});
 
import { computed, ref } from 'vue';
import KpiCard from '../../components/kpi-card.vue';
import PanelCard from '../../components/panel-card.vue';
import ScreenMapPanel from '../../components/screen-map-panel.vue';
import CameraMonitor from '../../../monitor/views/cameras.vue';
import { TIME_RANGE_OPTIONS } from '../../data/screen';
import { useChartTheme, useScreenData, useScreenFieldSource } from '../../hooks/use-screen';
 
const { data, timeRange } = useScreenData();
const { isDemoSection } = useScreenFieldSource();
const { textColor, mutedColor, splitColor, primary, baseGrid, axisStyle, tooltip } = useChartTheme();
 
const mixMetric = ref<'weight' | 'value' | 'count'>('weight');
const trendMetric = ref<'weight' | 'value' | 'carbon'>('weight');
const itemMetric = ref<'weight' | 'value' | 'carbon'>('weight');
 
const mixOptions = [
    { label: '重量(kg)', value: 'weight' },
    { label: '价值(元)', value: 'value' },
    { label: '计数(次)', value: 'count' }
];
 
const trendOptions = [
    { label: '重量(kg)', value: 'weight' },
    { label: '价值(元)', value: 'value' },
    { label: '碳减排(kgCO₂e)', value: 'carbon' }
];
 
const itemOptions = [
    { label: '重量(kg)', value: 'weight' },
    { label: '价值(元)', value: 'value' },
    { label: '碳减排(kgCO₂e)', value: 'carbon' }
];
 
const rangeLabel = computed(
    () => TIME_RANGE_OPTIONS.find(e => e.value === timeRange.value)?.label || '本区间'
);
 
/** 顶部 KPI */
const kpis = computed(() => [
    { field: 'kpis.periodWeightTon', label: `${rangeLabel.value}回收量`, value: data.value.kpis.periodWeightTon, suffix: '吨', fixed: 2 },
    { field: 'kpis.resourceRate', label: '资源化率', value: data.value.kpis.resourceRate, suffix: '%', fixed: 1 },
    { field: 'kpis.periodValue', label: '回收价值', value: data.value.kpis.periodValue, suffix: '元', fixed: 0 },
    { field: 'kpis.periodCarbonTon', label: '碳减排(tCO₂e)', value: data.value.kpis.periodCarbonTon, suffix: 'tCO₂e', fixed: 2 },
    { field: 'kpis.totalWeightTon', label: '累计回收量', value: data.value.kpis.totalWeightTon, suffix: '吨', fixed: 1 },
    { field: 'kpis.totalParticipants', label: '累计参与人数', value: data.value.kpis.totalParticipants, suffix: '人', fixed: 0 },
    { field: 'kpis.totalPoints', label: '累计碳积分', value: data.value.kpis.totalPoints, suffix: '分', fixed: 0 }
]);
 
const trendUnit = computed(() => {
    if (trendMetric.value === 'value') return '元';
    if (trendMetric.value === 'carbon') return 'kgCO₂e';
    return 'kg';
});
 
const itemUnit = computed(() => {
    if (itemMetric.value === 'value') return '元';
    if (itemMetric.value === 'carbon') return 'kgCO₂e';
    return 'kg';
});
 
/** 垃圾分类结构(饼) */
const mixOption = computed(() => ({
    tooltip: { trigger: 'item', formatter: '{b}<br/>{c} ({d}%)', ...tooltip() },
    series: [
        {
            type: 'pie',
            radius: ['38%', '62%'],
            center: ['50%', '50%'],
            padAngle: 3,
            itemStyle: { borderRadius: 6 },
            label: { color: textColor.value, formatter: '{b}\n{d}%' },
            data: data.value.wasteMix.map(e => ({
                name: e.name,
                value: e[mixMetric.value],
                itemStyle: { color: e.color }
            }))
        }
    ]
}));
 
/** 碳减排来源(饼) */
const carbonOption = computed(() => ({
    tooltip: { trigger: 'item', formatter: '{b}<br/>{c} kgCO₂e ({d}%)', ...tooltip() },
    series: [
        {
            type: 'pie',
            radius: ['36%', '60%'],
            center: ['50%', '50%'],
            padAngle: 3,
            itemStyle: { borderRadius: 6 },
            label: { color: textColor.value, formatter: '{b}\n{d}%' },
            data: data.value.recycleItems.map(e => ({
                name: e.name + '回收',
                value: e.carbon,
                itemStyle: { color: e.color }
            }))
        }
    ]
}));
 
/** 回收趋势(折线) */
const trendOption = computed(() => ({
    grid: baseGrid(),
    tooltip: { trigger: 'axis', ...tooltip() },
    xAxis: { type: 'category', data: data.value.axis, ...axisStyle() },
    yAxis: {
        type: 'value',
        name: trendUnit.value,
        nameTextStyle: { color: mutedColor.value },
        splitLine: { lineStyle: { color: splitColor.value, type: 'dashed' } },
        axisLabel: { color: mutedColor.value },
        axisLine: { show: false },
        axisTick: { show: false }
    },
    series: [
        {
            type: 'line',
            smooth: true,
            showSymbol: false,
            data: data.value.trend[trendMetric.value],
            itemStyle: { color: primary.value },
            areaStyle: { color: primary.value, opacity: 0.12 }
        }
    ]
}));
 
/** 各类回收量(横向条形) */
const itemOption = computed(() => {
    // 反转让数值最大的排在顶部
    const rows = [...data.value.recycleItems].reverse();
    return {
        grid: { containLabel: true, left: 8, right: 24, top: 12, bottom: 8 },
        tooltip: {
            trigger: 'axis',
            axisPointer: { type: 'shadow' },
            valueFormatter: (v: number) => `${Number(v || 0).toLocaleString()} ${itemUnit.value}`,
            ...tooltip()
        },
        xAxis: {
            type: 'value',
            name: itemUnit.value,
            nameTextStyle: { color: mutedColor.value },
            splitLine: { lineStyle: { color: splitColor.value, type: 'dashed' } },
            axisLabel: { color: mutedColor.value },
            axisLine: { show: false },
            axisTick: { show: false }
        },
        yAxis: {
            type: 'category',
            data: rows.map(e => e.name),
            axisLabel: { color: textColor.value },
            axisLine: { show: false },
            axisTick: { show: false }
        },
        series: [
            {
                type: 'bar',
                barWidth: 14,
                data: rows.map(e => Number(e[itemMetric.value] || 0)),
                itemStyle: {
                    borderRadius: [0, 8, 8, 0],
                    // 沿用各类自身配色,与左侧碳减排饼图视觉一致
                    color: (params: any) => rows[params.dataIndex]?.color || primary.value
                }
            }
        ]
    };
});
</script>
 
<style lang="scss" scoped>
@use '../../styles/screen-kpi' as *;
 
.dash {
    display: flex;
    flex-direction: column;
    gap: 10px;
    height: 100%;
    min-height: 0;
    overflow: auto;
 
    /* 主体三栏 */
    &-body {
        display: grid;
        grid-template-columns: 24% 46% 30%;
        gap: 10px;
        flex: 1;
        min-height: 420px;
    }
 
    &-col {
        display: flex;
        flex-direction: column;
        gap: 10px;
        min-width: 0;
        min-height: 0;
    }
 
    &-card {
        min-height: 0;
 
        /* 左右栏图表卡均分高度 */
        &--flex {
            flex: 1;
            display: flex;
            flex-direction: column;
 
            :deep(.panel-card__body) {
                flex: 1;
                min-height: 0;
            }
        }
 
        &--map {
            flex: 1;
            display: flex;
            flex-direction: column;
 
            :deep(.panel-card__body) {
                flex: 1;
                min-height: 0;
                padding: 10px;
            }
        }
    }
 
    /* 底部监控:压缩后给 CameraMonitor 一个紧凑高度 */
    &-foot {
        flex-shrink: 0;
        display: flex;
        flex-direction: column;
        height: clamp(200px, 20vh, 260px);
 
        :deep(.panel-card) {
            flex: 1;
            display: flex;
            flex-direction: column;
            min-height: 0;
        }
 
        :deep(.panel-card__head) {
            padding-top: 6px;
            padding-bottom: 6px;
        }
 
        :deep(.panel-card__body) {
            flex: 1;
            min-height: 0;
            overflow: hidden;
            padding: 6px;
        }
 
        .camera-more {
            font-size: 12px;
            color: var(--el-color-primary);
            text-decoration: none;
        }
    }
 
    .chart {
        height: 100%;
        min-height: 180px;
        width: 100%;
    }
}
 
/* 窄屏兜底:三栏改单栏纵向 */
@media (max-width: 1200px) {
    .dash-body {
        grid-template-columns: 1fr;
        min-height: 0;
 
        .dash-col--center {
            min-height: 420px;
        }
    }
}
 
@media (max-width: 768px) {
    .dash,
    .dash-body,
    .dash-col {
        height: auto;
        min-height: 0;
        overflow: visible;
        flex: none;
    }
 
    .dash :deep(.kpi-grid) {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }
 
    .dash-card--flex {
        flex: none;
        height: auto;
        min-height: 0;
        overflow: visible;
 
        :deep(.panel-card) {
            height: auto;
            min-height: 0;
            overflow: visible;
        }
 
        :deep(.panel-card__body) {
            flex: none;
            height: auto;
            min-height: 0;
            overflow: visible;
        }
    }
 
    /* 地图画布层级很高,限制在中栏内,避免盖住上下两块图表 */
    .dash-card--map {
        position: relative;
        z-index: 0;
        flex: none;
        height: 480px;
        min-height: 480px;
        overflow: hidden;
    }
 
    .dash .chart {
        display: block;
        height: 260px;
        min-height: 260px;
    }
 
    .dash .chart--items {
        height: 420px;
        min-height: 420px;
    }
 
    .dash-foot {
        height: auto;
        min-height: 300px;
    }
}
</style>