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
| <template>
| <div class="data-chart-container">
| <el-card class="data-card" :body-style="{ height: '100%' }">
| <div class="card-content">
| <div class="title-container">
| <h1>运维工单报表</h1>
| <div class="select-container">
| <el-select v-model="params.unitId" placeholder="请选择运维公司" @change="showData">
| <el-option v-for="item in options" :key="item.value" :label="item.label" :value="item.value">
| </el-option>
| </el-select>
| </div>
| <div class="date-container">
| <el-select v-model="params.dateType" placeholder="请选择时间范围" @change="showData">
| <el-option v-for="item in options2" :key="item.value" :label="item.label" :value="item.value">
| </el-option>
| </el-select>
| </div>
| </div>
| <div class="chart-container">
| <div id="chartContent" ref="chartContent"></div>
| </div>
| </div>
| </el-card>
| </div>
| </template>
|
| <script>
| import * as echarts from 'echarts';
| import { ywUnitList, workOrder } from "@/api/platform/home";
| let lineChart = null;
| let observer = null;
| export default {
| name: 'DataChart',
| data() {
| return {
| params: {
| dateType: '',
| unitId: ''
| },
| options: [],
| options2: [
| { label: '日工单数', value: 'day' },
| { label: '周工单数', value: 'week' },
| { label: '月工单数', value: 'month' },
| ],
| dataList: [],
| }
| },
| methods: {
| initChart() {
| // 对 complete 对象的键进行排序
| const sortedKeys = Object.keys(this.acitveData.complete)
| .sort(); // 按照字符串的字典序对键进行排序
| const option = {
| legend: {
| right: 'right',
| top: 'top',
| icon: 'rect',
| orient: "vertical",
| data: [
| {
| name: '完成工单数',
| itemStyle: {
| color: 'rgba(62, 144, 247, 1)'
| }
| },
| {
| name: '待完成工单数',
| itemStyle: {
| color: 'rgba(85, 192, 191, 1)'
| }
| },
| {
| name: '待审批工单数',
| itemStyle: {
| color: 'rgba(255, 165, 0, 1)'
| }
| },
| ],
| },
| grid: {
| left: 0,
| right: 0,
| bottom: 0,
| top: '20%',
| containLabel: true
| },
| tooltip: {},
| xAxis: {
| type: 'category',
| data: sortedKeys,
| axisLabel: {
| interval: 0 // 强制显示所有标签
| },
| sortSeriesData: false
| },
| yAxis: {},
| series: [
| {
| name: '完成工单数',
| data: sortedKeys.map(key => this.acitveData.complete[key]),
| type: 'line',
| itemStyle: {
| color: 'rgba(62, 144, 247, 1)'
| }
| },
| {
| name: '待完成工单数',
| data: sortedKeys.map(key => this.acitveData.waiting[key]),
| type: 'line',
| itemStyle: {
| color: 'rgba(85, 192, 191, 1)'
| }
| },
| {
| name: '待审批工单数',
| data: sortedKeys.map(key => this.acitveData.pending[key]),
| type: 'line',
| itemStyle: {
| color: 'rgba(255, 165, 0, 1)'
| }
| }
| ]
| };
| lineChart.setOption(option, true);
| },
|
|
| showData() {
| workOrder(this.params).then(res => {
| this.acitveData = res.data;
| if (Object.keys(this.acitveData).length === 0) {
| this.acitveData = {
| name: '',
| complete: {},
| waiting: {},
| pending: {}
| }
| }
|
| lineChart = echarts.init(this.$refs.chartContent);
| this.initChart();
| this.observe();
| })
| },
|
| // 监听变化
| observe() {
| if (!observer) {
| observer = new ResizeObserver(entries => {
| this.handleResize();
| })
| }
| observer.observe(this.$refs.chartContent);
| },
| // 窗口变换
| handleResize() {
| if (lineChart) {
| lineChart.resize();
| }
| }
|
| },
| mounted() {
| ywUnitList().then(res => {
| this.options = res.data.data.map(item => {
| return {
| label: item.value,
| value: item.id
| }
| })
| if (this.params.unitId === '') {
| this.params.unitId = this.options[0].value;
| }
| this.params.dateType = this.options2[0].value;
| this.showData();
| })
| },
| beforeDestroy() {
| if (lineChart) {
| lineChart.dispose();
| observer.unobserve(this.$refs.chartContent);
| }
| },
| }
| </script>
|
| <style lang="scss" scoped>
| .data-chart-container {
| height: 400px;
| margin-bottom: 20px;
|
| .data-card {
| height: 100%;
|
| .card-content {
| width: 100%;
| height: 100%;
| position: relative;
| }
| }
| }
|
| .title-container {
| position: absolute;
| display: flex;
| justify-content: space-between;
| align-items: center;
| z-index: 2;
|
|
| .more-button {
| cursor: pointer;
| font-size: 16px;
| padding: 0 10px;
| }
| }
|
| .chart-container {
|
| width: 100%;
| height: 100%;
|
| #chartContent {
| width: 100%;
| height: 100%;
| }
| }
|
| .select-container {
| margin: 0 20px;
| width: 180px;
| }
| </style>
|
|