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
| <script setup lang="ts">
| import { watch } from 'vue';
| import { useAppStore } from '@/store/modules/app';
| import { useEcharts } from '@/hooks/common/echarts';
| import { $t } from '@/locales';
|
| defineOptions({
| name: 'PieChart'
| });
|
| const appStore = useAppStore();
|
| const { domRef, updateOptions } = useEcharts(() => ({
| tooltip: {
| trigger: 'item'
| },
| legend: {
| bottom: '1%',
| left: 'center',
| itemStyle: {
| borderWidth: 0
| }
| },
| series: [
| {
| color: ['#5da8ff', '#8e9dff', '#fedc69', '#26deca'],
| name: $t('page.home.schedule'),
| type: 'pie',
| radius: ['45%', '75%'],
| avoidLabelOverlap: false,
| itemStyle: {
| borderRadius: 10,
| borderColor: '#fff',
| borderWidth: 1
| },
| label: {
| show: false,
| position: 'center'
| },
| emphasis: {
| label: {
| show: true,
| fontSize: '12'
| }
| },
| labelLine: {
| show: false
| },
| data: [] as { name: string; value: number }[]
| }
| ]
| }));
|
| async function mockData() {
| await new Promise(resolve => {
| setTimeout(resolve, 1000);
| });
|
| updateOptions(opts => {
| opts.series[0].data = [
| { name: $t('page.home.study'), value: 20 },
| { name: $t('page.home.entertainment'), value: 10 },
| { name: $t('page.home.work'), value: 40 },
| { name: $t('page.home.rest'), value: 30 }
| ];
|
| return opts;
| });
| }
|
| function updateLocale() {
| updateOptions((opts, factory) => {
| const originOpts = factory();
|
| opts.series[0].name = originOpts.series[0].name;
|
| opts.series[0].data = [
| { name: $t('page.home.study'), value: 20 },
| { name: $t('page.home.entertainment'), value: 10 },
| { name: $t('page.home.work'), value: 40 },
| { name: $t('page.home.rest'), value: 30 }
| ];
|
| return opts;
| });
| }
|
| async function init() {
| mockData();
| }
|
| watch(
| () => appStore.locale,
| () => {
| updateLocale();
| }
| );
|
| // init
| init();
| </script>
|
| <template>
| <NCard :bordered="false" class="card-wrapper">
| <div ref="domRef" class="h-360px overflow-hidden"></div>
| </NCard>
| </template>
|
| <style scoped></style>
|
|