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
| <template>
| <div class="data-dashboard">
| <!-- 顶部统计卡片 -->
| <div class="stat-cards">
| <div class="stat-card" v-for="(card, index) in statCards" :key="index">
| <div class="stat-label">{{ card.label }}</div>
| <div class="stat-value" :class="{ 'has-prefix': card.prefix }">
| <span v-if="card.prefix" class="stat-prefix">{{ card.prefix }}</span>
| {{ card.value }}
| </div>
| <div class="stat-sub">
| <span>昨日 {{ card.yesterday }}</span>
| <span>今日 {{ card.today }}</span>
| </div>
| </div>
| </div>
|
| <!-- 图表区域 -->
| <div class="charts-row">
| <!-- 近30天收益分析 -->
| <div class="chart-panel chart-bar">
| <div class="chart-title">近30天收益分析</div>
| <div ref="barChart" class="chart-container"></div>
| </div>
|
| <!-- 车辆实时使用情况 -->
| <div class="chart-panel chart-donut">
| <div class="chart-header">
| <div class="chart-title">车辆实时使用情况</div>
| <div class="chart-toggle">
| <el-button-group>
| <el-button
| :type="vehicleType === 'bicycle' ? 'primary' : 'default'"
| size="mini"
| @click="vehicleType = 'bicycle'"
| >自行车</el-button>
| <el-button
| :type="vehicleType === 'electric' ? 'primary' : 'default'"
| size="mini"
| @click="vehicleType = 'electric'"
| >电动车</el-button>
| </el-button-group>
| </div>
| </div>
| <div class="chart-subtitle">总计:{{ vehicleTotal }}辆</div>
| <div ref="donutChart" class="chart-container"></div>
| </div>
|
| <!-- 套餐销售来源分析 -->
| <div class="chart-panel chart-pie">
| <div class="chart-header">
| <div class="chart-title">套餐销售来源分析</div>
| <div class="chart-toggle">
| <el-button-group>
| <el-button
| :type="salesPeriod === 'month' ? 'primary' : 'default'"
| size="mini"
| @click="salesPeriod = 'month'"
| >本月</el-button>
| <el-button
| :type="salesPeriod === 'year' ? 'primary' : 'default'"
| size="mini"
| @click="salesPeriod = 'year'"
| >本年</el-button>
| </el-button-group>
| </div>
| </div>
| <div ref="pieChart" class="chart-container"></div>
| </div>
| </div>
| </div>
| </template>
|
| <script>
| import * as echarts from 'echarts'
|
| export default {
| data () {
| return {
| statCards: [
| { label: '本月收益', prefix: '¥', value: '32242.34', yesterday: '24243.23', today: '235.34' },
| { label: '本月订单', value: '2849', yesterday: '345', today: '243' },
| { label: '在客户数', value: '243', yesterday: '23', today: '12' },
| { label: '车辆总数', value: '243', yesterday: '在线 240', today: '离线 3' }
| ],
| vehicleType: 'bicycle',
| vehicleTotal: 142,
| salesPeriod: 'month',
| barChart: null,
| donutChart: null,
| pieChart: null
| }
| },
| mounted () {
| this.$nextTick(() => {
| this.initBarChart()
| this.initDonutChart()
| this.initPieChart()
| })
| window.addEventListener('resize', this.handleResize)
| },
| beforeDestroy () {
| window.removeEventListener('resize', this.handleResize)
| if (this.barChart) this.barChart.dispose()
| if (this.donutChart) this.donutChart.dispose()
| if (this.pieChart) this.pieChart.dispose()
| },
| methods: {
| initBarChart () {
| const chart = echarts.init(this.$refs.barChart)
| const data = [111, 227, 147, 163, 178, 200, 126]
| const dates = ['6-15', '6-16', '6-17', '6-18', '6-19', '6-20', '6-21']
| chart.setOption({
| tooltip: { trigger: 'axis' },
| legend: {
| data: ['收入'],
| bottom: 0
| },
| grid: {
| left: 10,
| right: 10,
| top: 20,
| bottom: 40,
| containLabel: true
| },
| xAxis: {
| type: 'category',
| data: dates,
| axisLine: { lineStyle: { color: '#e0e0e0' } },
| axisTick: { show: false }
| },
| yAxis: {
| type: 'value',
| axisLine: { show: false },
| axisTick: { show: false },
| splitLine: { lineStyle: { color: '#f0f0f0' } }
| },
| series: [{
| name: '收入',
| type: 'bar',
| barWidth: 30,
| itemStyle: { color: '#5B8FF9' },
| label: {
| show: true,
| position: 'top',
| color: '#5B8FF9',
| fontSize: 11
| },
| data: data
| }]
| })
| this.barChart = chart
| },
| initDonutChart () {
| const chart = echarts.init(this.$refs.donutChart)
| chart.setOption({
| tooltip: { trigger: 'item' },
| legend: {
| orient: 'horizontal',
| bottom: 0,
| data: ['空闲', '使用中']
| },
| series: [{
| type: 'pie',
| radius: ['50%', '75%'],
| center: ['50%', '45%'],
| avoidLabelOverlap: true,
| itemStyle: {
| borderColor: '#fff',
| borderWidth: 2
| },
| label: {
| show: true,
| formatter: '{b}\n{c}',
| fontSize: 12
| },
| data: [
| { value: 60, name: '空闲', itemStyle: { color: '#73C0DE' } },
| { value: 180, name: '使用中', itemStyle: { color: '#5B8FF9' } }
| ]
| }]
| })
| this.donutChart = chart
| },
| initPieChart () {
| const chart = echarts.init(this.$refs.pieChart)
| chart.setOption({
| tooltip: { trigger: 'item' },
| legend: {
| orient: 'horizontal',
| top: 0,
| data: ['抖音团购', '小程序销售']
| },
| series: [{
| type: 'pie',
| radius: '70%',
| center: ['50%', '55%'],
| avoidLabelOverlap: true,
| itemStyle: {
| borderColor: '#fff',
| borderWidth: 2
| },
| label: {
| show: true,
| formatter: '{b}\n{c}',
| fontSize: 12
| },
| data: [
| { value: 130, name: '抖音团购', itemStyle: { color: '#73C0DE' } },
| { value: 100, name: '小程序销售', itemStyle: { color: '#5B8FF9' } }
| ]
| }]
| })
| this.pieChart = chart
| },
| handleResize () {
| if (this.barChart) this.barChart.resize()
| if (this.donutChart) this.donutChart.resize()
| if (this.pieChart) this.pieChart.resize()
| }
| }
| }
| </script>
|
| <style lang="scss" scoped>
| .data-dashboard {
| padding: 16px;
| background: #f0f2f5;
| min-height: 100%;
| box-sizing: border-box;
| }
|
| // 统计卡片
| .stat-cards {
| display: flex;
| gap: 16px;
| margin-bottom: 16px;
| }
|
| .stat-card {
| flex: 1;
| background: #e8f0fe;
| border-radius: 8px;
| padding: 20px 24px;
| }
|
| .stat-label {
| font-size: 14px;
| color: #666;
| margin-bottom: 12px;
| }
|
| .stat-value {
| font-size: 28px;
| font-weight: bold;
| color: #1a1a1a;
| margin-bottom: 10px;
|
| &.has-prefix {
| display: flex;
| align-items: baseline;
| }
| }
|
| .stat-prefix {
| font-size: 20px;
| margin-right: 2px;
| }
|
| .stat-sub {
| font-size: 12px;
| color: #999;
| display: flex;
| gap: 16px;
| }
|
| // 图表行
| .charts-row {
| display: flex;
| gap: 16px;
| }
|
| .chart-panel {
| background: #fff;
| border-radius: 8px;
| padding: 20px;
| box-sizing: border-box;
| }
|
| .chart-bar {
| flex: 1.2;
| }
|
| .chart-donut,
| .chart-pie {
| flex: 1;
| }
|
| .chart-header {
| display: flex;
| justify-content: space-between;
| align-items: center;
| margin-bottom: 4px;
| }
|
| .chart-title {
| font-size: 16px;
| font-weight: bold;
| color: #1a1a1a;
| }
|
| .chart-toggle {
| ::v-deep .el-button--primary {
| background: #216EEE;
| border-color: #216EEE;
| }
| }
|
| .chart-subtitle {
| font-size: 12px;
| color: #999;
| margin-bottom: 10px;
| }
|
| .chart-container {
| width: 100%;
| height: 320px;
| }
| </style>
|
|