AccountDistribution.vue
6.62 KB
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
<template>
<a-row :gutter="16" class="ml-10">
<a-col :span="8" style="text-align: center;">
<a-statistic class="stat" title="今日活跃车商" :value="accountStat?.activeCount??0" :precision="0"></a-statistic>
</a-col>
<a-col :span="8" style="text-align: center;">
<a-statistic class="stat" title="本周新增" :value="accountStat?.newCount??0" :precision="0"></a-statistic>
</a-col>
<a-col :span="8" style="text-align: center;">
<a-statistic class="stat" title="本周首单" :value="accountStat?.dealCount??0" :precision="0"></a-statistic>
</a-col>
</a-row>
<a-row :gutter="16">
<a-col :span="16">
<v-chart :option="option" style="height: 400px" autoresize theme="walden"/>
</a-col>
<a-col :span="8">
<a-list item-layout="horizontal" :data-source="provinceAccounts" size="small" :bordered="false" class="mt-16">
<template #renderItem="{ item,index }">
<a-list-item>
<template #actions>
{{ provincePercent(item.value).toFixed(0) }}%
<h3 style="width: 40px">{{ item.value }}</h3>
</template>
<a-list-item-meta>
<template #title>
{{ item.name }}
</template>
<template #description>
</template>
<template #avatar>
<a-avatar :style="{ backgroundColor: colors[index%13] }" shape="square" :size="14">
</a-avatar>
</template>
</a-list-item-meta>
</a-list-item>
</template>
</a-list>
</a-col>
</a-row>
</template>
<script lang="ts">
import {Component, Vue} from "vue-facing-decorator";
import chinaGeo from '@/assets/china.json';
import * as echarts from 'echarts/core';
import {AccountController} from "@/api/AccountController";
import {getAreaNameByCode} from "@/common/chinaarea";
import {AccountTotalStat} from "lib/src/entity/account/domain/AccountTotalStat";
@Component({
components: {}
})
export default class AccountDistribution extends Vue {
colors = ['#5B8FF9', '#4CD8A0', '#5D7092', '#F6BD16', '#E8684A', '#52C2EB', '#9270CA', '#FF9D4D', '#269A99', '#FF99C3', '#4CBF82', '#33ADFF', '#CD92FE'];
accountStat: AccountTotalStat = null;
option = {
tooltip: {
trigger: 'item',
formatter: function (params) {
return `${params.name}<br/>用户数量:${params.value.toLocaleString() !== 'NaN' ? params.value.toLocaleString() : '0'} 人`;
}
},
// legend: {show: true, data: ['广东省']},
legend: {
type: 'scroll', // 支持滚动(避免图例过多溢出)
right: 10, // 靠右显示
top: 'center', // 垂直居中
orient: 'vertical', // 垂直排列
data: [], // 图例名称(与userData对应)
// textStyle: {color: '#333'}, // 图例文字颜色
},
// 图例(颜色对应数值范围)
// visualMap: {
// type: 'piecewise', // 分段型视觉映射
// pieces: [
// {max: 1000, label: '1000以下', color: '#e0f2f1'},
// {min: 1000, max: 10000, label: '1000-1万', color: '#80cbc4'},
// {min: 10000, label: '1万以上', color: '#00897b'}
// ],
// left: 'left',
// bottom: 'bottom',
// textStyle: {fontSize: 12}
// },
// geo: {
// map: "china",
// },
series: [
{
type: 'map',
mapType: 'china', // 使用中国地图
// roam: false, // 允许缩放和平移
// label: {
// show: false, // 显示省份名称
// fontSize: 12
// },
data: [], // 绑定用户数量数据
emphasis: {
// 高亮样式(鼠标悬停时)
itemStyle: {areaColor: '#ffcc80', borderWidth: 2},
label: {fontSize: 14}
}
}
]
};
provinceAccounts = [];
created() {
AccountController.getDashboardAccountStat(this.axios).then((res) => {
this.accountStat = res.data;
});
}
mounted() {
// 使用 registerMap 注册的地图名称。
echarts.registerMap('china', chinaGeo);
AccountController.getAccountCountGroupByProvince(this.axios).then(res => {
const provinceData = res.data.map((item, index) => {
return {
name: getAreaNameByCode(item.provinceCode), value: item.accountCount, label: {
normal: {
show: index < 5, color: '#999', fontSize: 12,
textStyle: {
borderColor: this.colors[index], // 边框颜色(与悬停背景色呼应)
borderWidth: 2,
padding: [4, 10],
backgroundColor: '#ffffff', // 标签背景色
borderRadius: 7
},
formatter: (params) => {
return params.value ? params.value.toLocaleString() : '';
}
}
}, itemStyle: {
normal: {
areaColor: this.colors[index]
}
}
};
});
this.provinceAccounts = provinceData;
const formattedData = provinceData.map(item => item.name);
console.log(provinceData);
this.option.legend.data = formattedData;
this.option.series[0].data = provinceData;
});
}
provincePercent(count: number): number {
let total = 0;
this.provinceAccounts.forEach(item => {
total = total + item.value;
});
if (total > 0) {
return (count / total) * 100;
} else {
return 0;
}
}
}
</script>
<style lang="less" scoped>
.stat {
border-radius: 8px;
background: linear-gradient(129.4deg, #F7FAFF 0%, #EBF3FF 36.53%, #F7FAFF 100%);
padding: 12px 16px 12px 16px;
}
</style>