wangrong
2026-09-26 3c7f5d8d9cc64f1d459f5e199f556a5d1e68ce49
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
import type { ScreenData, TimeRange } from './screen';
 
export const WASTE_COLORS: Record<string, string> = {
    SW62: '#16a34a',
    SW64: '#64748b',
    SW63: '#f59e0b',
    SW61: '#ef4444',
    SW60: '#06b6d4'
};
 
export const ITEM_COLORS = ['#3b82f6', '#22c55e', '#f59e0b', '#a855f7', '#06b6d4', '#ef4444', '#94a3b8'];
 
const WASTE_ITEMS = [
    { code: 'SW62', name: '可回收物' },
    { code: 'SW64', name: '其他垃圾' },
    { code: 'SW63', name: '大件垃圾' },
    { code: 'SW61', name: '有害垃圾' },
    { code: 'SW60', name: '湿垃圾' }
];
 
const RECYCLE_NAMES = ['废纸', '塑料', '金属', '织物', '玻璃', '电子产品', '其他可回收'];
 
/** 与后端 buildTrend 对齐的时间轴 */
export function buildScreenAxis(range: TimeRange): string[] {
    const now = new Date();
    const pad = (n: number) => String(n).padStart(2, '0');
    const fmt = (d: Date) => `${pad(d.getMonth() + 1)}-${pad(d.getDate())}`;
 
    if (range === 'year') {
        return Array.from({ length: 12 }, (_, i) => `${i + 1}月`);
    }
 
    let start: Date;
    if (range === 'today') {
        start = new Date(now);
        start.setDate(start.getDate() - 6);
    } else if (range === 'week') {
        start = new Date(now);
        const day = start.getDay() || 7;
        start.setDate(start.getDate() - day + 1);
    } else if (range === 'quarter') {
        start = new Date(now.getFullYear(), Math.floor(now.getMonth() / 3) * 3, 1);
    } else {
        start = new Date(now.getFullYear(), now.getMonth(), 1);
    }
 
    const axis: string[] = [];
    const cursor = new Date(start);
    while (cursor <= now) {
        axis.push(fmt(cursor));
        cursor.setDate(cursor.getDate() + 1);
    }
    return axis;
}
 
/** 只保证图表/表格结构完整,数值为 0 */
export function structureScreen(range: TimeRange = 'month'): ScreenData {
    const axis = buildScreenAxis(range);
    const orderAxis =
        range === 'year'
            ? axis
            : (() => {
                    const days: string[] = [];
                    const end = new Date();
                    const start = new Date(end);
                    start.setDate(start.getDate() - 6);
                    const pad = (n: number) => String(n).padStart(2, '0');
                    const cursor = new Date(start);
                    while (cursor <= end) {
                        days.push(`${pad(cursor.getMonth() + 1)}-${pad(cursor.getDate())}`);
                        cursor.setDate(cursor.getDate() + 1);
                    }
                    return days;
              })();
 
    return {
        range,
        axis,
        kpis: {
            todayWeightKg: 0,
            periodWeightTon: 0,
            resourceRate: 0,
            periodValue: 0,
            periodCarbonTon: 0,
            totalWeightTon: 0,
            totalParticipants: 0,
            totalPoints: 0,
            recyclableTon: 0,
            bulkTon: 0,
            elecTon: 0,
            fabricTon: 0,
            yearCarbonTon: 0,
            monthCarbonTon: 0,
            totalCarbonTon: 0,
            greenActions: 0,
            newParticipants: 0,
            participateRate: 0,
            pointsIssued: 0,
            pointsConsumed: 0,
            pointsBalance: 0,
            sorterOnline: 0,
            sorterTotal: 0,
            vehicleOnline: 0,
            vehicleTotal: 0,
            siteOnline: 0,
            siteTotal: 0,
            todayOrders: 0,
            todayAppointments: 0,
            pendingAppointments: 0,
            alerts: 0,
            healthAlerts: 0
        },
        wasteMix: WASTE_ITEMS.map(e => ({
            name: e.name,
            code: e.code,
            weight: 0,
            value: 0,
            count: 0,
            color: WASTE_COLORS[e.code]
        })),
        recycleItems: RECYCLE_NAMES.map((name, i) => ({
            name,
            weight: 0,
            value: 0,
            carbon: 0,
            color: ITEM_COLORS[i]
        })),
        trend: {
            weight: axis.map(() => 0),
            value: axis.map(() => 0),
            carbon: axis.map(() => 0)
        },
        yearCarbon: Array.from({ length: 12 }, () => 0),
        deptRank: [],
        classRank: [],
        majorRank: [],
        pointFlow: { issued: 0, transfer: 0, donate: 0, mall: 0, balance: 0 },
        participateTrend: axis.map(() => 0),
        deliverTrend: axis.map(() => 0),
        ordersByType: {
            axis: orderAxis,
            现场回收: orderAxis.map(() => 0),
            预约上门: orderAxis.map(() => 0),
            大屏投递: orderAxis.map(() => 0),
            活动回收: orderAxis.map(() => 0)
        },
        appointmentFlow: [
            { name: '预约', value: 0 },
            { name: '接单', value: 0 },
            { name: '完成', value: 0 }
        ],
        sorterStatus: [
            { name: '工作中', value: 0, color: '#22c55e' },
            { name: '休息', value: 0, color: '#f59e0b' },
            { name: '异常', value: 0, color: '#ef4444' },
            { name: '离线', value: 0, color: '#94a3b8' }
        ],
        vehicles: [],
        sites: [],
        unavailable: []
    };
}