提交 | 用户 | 时间
|
850106
|
1 |
<template> |
H |
2 |
<el-dialog |
|
3 |
title="采集值" |
|
4 |
:close-on-click-modal="false" |
|
5 |
:width="dialogWidth" |
|
6 |
:visible.sync="visible" |
|
7 |
> |
|
8 |
<el-form |
|
9 |
:inline="true" |
|
10 |
:model="dataForm" |
|
11 |
@keyup.enter.native="getDataList()" |
|
12 |
> |
|
13 |
<el-form-item> |
|
14 |
<el-date-picker |
|
15 |
v-model="dataForm.startTime" |
|
16 |
type="datetime" |
|
17 |
value-format="yyyy-MM-dd HH:mm:ss" |
|
18 |
placeholder="选择日期时间" |
|
19 |
> |
|
20 |
</el-date-picker> |
|
21 |
</el-form-item> |
|
22 |
<el-form-item> |
|
23 |
<el-date-picker |
|
24 |
v-model="dataForm.endTime" |
|
25 |
type="datetime" |
|
26 |
value-format="yyyy-MM-dd HH:mm:ss" |
|
27 |
placeholder="选择日期时间" |
|
28 |
> |
|
29 |
</el-date-picker> |
|
30 |
</el-form-item> |
|
31 |
<el-form-item> |
|
32 |
<el-button @click="getDataList()">查询</el-button> |
|
33 |
<el-button type="primary" @click="exportPointsValue()">导出</el-button> |
|
34 |
</el-form-item> |
|
35 |
</el-form> |
|
36 |
<div id="chartDom" class="result-chart"></div> |
|
37 |
</el-dialog> |
|
38 |
</template> |
|
39 |
|
|
40 |
<script> |
|
41 |
export default { |
|
42 |
data() { |
|
43 |
return { |
|
44 |
dialogWidth: 0, |
|
45 |
pointtypeList: [], |
|
46 |
pointtypeMap: {}, |
|
47 |
minfreqList: [], |
|
48 |
minfreqMap: {}, |
|
49 |
storetypeList: [], |
|
50 |
storetypeMap: {}, |
|
51 |
datatypeList: [], |
|
52 |
datatypeMap: {}, |
|
53 |
sourceList: [], |
|
54 |
sourceMap: {}, |
|
55 |
expressionList: [], |
|
56 |
pointList: [], |
|
57 |
pointMap: {}, |
|
58 |
pointCodeMap: {}, |
|
59 |
operatorList: ["+", "-"], |
|
60 |
visible: false, |
|
61 |
roleList: [], |
|
62 |
dataForm: { |
|
63 |
pointno: "", |
|
64 |
pointname: "", |
|
65 |
tableName: "", |
|
66 |
startTime: "", |
|
67 |
endTime: "", |
|
68 |
}, |
|
69 |
pointsValue: [], |
|
70 |
}; |
|
71 |
}, |
|
72 |
created() { |
|
73 |
this.setDialogWidth(); |
|
74 |
}, |
|
75 |
mounted() { |
|
76 |
window.onresize = () => { |
|
77 |
return (() => { |
|
78 |
this.setDialogWidth(); |
|
79 |
})(); |
|
80 |
}; |
|
81 |
}, |
|
82 |
methods: { |
|
83 |
setDialogWidth() { |
|
84 |
let val = document.body.clientWidth; |
|
85 |
const def = 1300; // 默认宽度 |
|
86 |
if (val < def) { |
|
87 |
this.dialogWidth = "70%"; |
|
88 |
} else { |
|
89 |
this.dialogWidth = "50%"; |
|
90 |
} |
|
91 |
}, |
|
92 |
init(pointno, pointname, tableName) { |
|
93 |
this.dataForm.pointno = pointno; |
|
94 |
this.dataForm.pointname = pointname; |
|
95 |
this.dataForm.tableName = tableName; |
|
96 |
this.dataForm.startTime = ""; |
|
97 |
this.dataForm.endTime = ""; |
|
98 |
this.getDataList(); |
|
99 |
}, |
|
100 |
exportPointsValue() { |
|
101 |
let that = this; |
|
102 |
this.$axios |
|
103 |
.post( |
|
104 |
`/data/mcs/point/points-value/excel`, |
|
105 |
{ |
|
106 |
tableName: this.dataForm.tableName, |
|
107 |
pointno: this.dataForm.pointno, |
|
108 |
startTime: this.dataForm.startTime, |
|
109 |
endTime: this.dataForm.endTime, |
|
110 |
}, |
|
111 |
{ |
|
112 |
responseType: "blob", |
|
113 |
} |
|
114 |
) |
|
115 |
.then(function (res) { |
|
116 |
let blob = res.data; |
|
117 |
// FileReader主要用于将文件内容读入内存 |
|
118 |
let reader = new FileReader(); |
|
119 |
reader.readAsDataURL(blob); |
|
120 |
// onload当读取操作成功完成时调用 |
|
121 |
reader.onload = function (e) { |
|
122 |
let a = document.createElement("a"); |
|
123 |
a.download = that.dataForm.pointname + "PointValue.xls"; |
|
124 |
a.href = e.target.result; |
|
125 |
document.body.appendChild(a); |
|
126 |
a.click(); |
|
127 |
document.body.removeChild(a); |
|
128 |
}; |
|
129 |
}); |
|
130 |
}, |
|
131 |
getDataList() { |
|
132 |
this.visible = true; |
|
133 |
if (this.dataForm.pointno) { |
|
134 |
this.$http({ |
|
135 |
url: `/data/mcs/point/data-values`, |
|
136 |
method: "get", |
|
137 |
params: { |
|
138 |
tableName: this.dataForm.tableName, |
|
139 |
pointno: this.dataForm.pointno, |
|
140 |
startTime: this.dataForm.startTime, |
|
141 |
endTime: this.dataForm.endTime, |
|
142 |
}, |
|
143 |
}).then(({ data }) => { |
|
144 |
if (data && data.code === 0) { |
|
145 |
let dataList = []; |
|
146 |
data.data.forEach(function (value) { |
|
147 |
//判断数据是否为布尔型 |
|
148 |
if (typeof value["datavalue"] === "boolean") { |
|
149 |
value["datavalue"] = value["datavalue"] ? 1 : 0; |
|
150 |
} |
|
151 |
dataList.push([value["datatime"], value["datavalue"]]); |
|
152 |
}); |
|
153 |
let charName = this.dataForm.pointname; |
|
154 |
let myChart = this.$echarts.init( |
|
155 |
document.getElementById("chartDom") |
|
156 |
); |
|
157 |
let option = { |
|
158 |
title: { |
|
159 |
text: charName, |
|
160 |
left: "1%", |
|
161 |
}, |
|
162 |
tooltip: { |
|
163 |
trigger: "axis", |
|
164 |
}, |
|
165 |
grid: { |
|
166 |
left: "5%", |
|
167 |
right: "5%", |
|
168 |
bottom: "10%", |
|
169 |
}, |
|
170 |
toolbox: { |
|
171 |
right: 10, |
|
172 |
}, |
|
173 |
xAxis: { |
|
174 |
type: "time", |
|
175 |
splitLine: { |
|
176 |
show: false, |
|
177 |
}, |
|
178 |
}, |
|
179 |
yAxis: { |
|
180 |
type: "value", |
|
181 |
axisTick: { |
|
182 |
inside: true, |
|
183 |
}, |
|
184 |
splitLine: { |
|
185 |
show: false, |
|
186 |
}, |
|
187 |
axisLabel: { |
|
188 |
inside: true, |
|
189 |
formatter: "{value}\n", |
|
190 |
}, |
|
191 |
z: 10, |
|
192 |
}, |
|
193 |
dataZoom: [ |
|
194 |
{ |
|
195 |
type: "inside", |
|
196 |
}, |
|
197 |
], |
|
198 |
visualMap: { |
|
199 |
top: 50, |
|
200 |
right: 10, |
|
201 |
pieces: [ |
|
202 |
{ |
|
203 |
gt: 0, |
|
204 |
lte: 50, |
|
205 |
color: "#93CE07", |
|
206 |
}, |
|
207 |
{ |
|
208 |
gt: 50, |
|
209 |
lte: 100, |
|
210 |
color: "#FBDB0F", |
|
211 |
}, |
|
212 |
{ |
|
213 |
gt: 100, |
|
214 |
lte: 150, |
|
215 |
color: "#FC7D02", |
|
216 |
}, |
|
217 |
{ |
|
218 |
gt: 150, |
|
219 |
lte: 200, |
|
220 |
color: "#FD0100", |
|
221 |
}, |
|
222 |
{ |
|
223 |
gt: 200, |
|
224 |
lte: 300, |
|
225 |
color: "#AA069F", |
|
226 |
}, |
|
227 |
{ |
|
228 |
gt: 300, |
|
229 |
color: "#AC3B2A", |
|
230 |
}, |
|
231 |
], |
|
232 |
outOfRange: { |
|
233 |
color: "#999", |
|
234 |
}, |
|
235 |
}, |
|
236 |
series: [ |
|
237 |
{ |
|
238 |
name: "实际值", |
|
239 |
type: "line", |
|
240 |
data: dataList, |
|
241 |
}, |
|
242 |
], |
|
243 |
}; |
|
244 |
myChart.setOption(option); |
|
245 |
} |
|
246 |
}); |
|
247 |
} |
|
248 |
}, |
|
249 |
resetFields(obj) { |
|
250 |
for (let key in obj) { |
|
251 |
if (key === "pointtypename") { |
|
252 |
continue; |
|
253 |
} |
|
254 |
if (obj[key] instanceof Array) { |
|
255 |
obj[key] = []; |
|
256 |
} else if (obj[key] instanceof Object) { |
|
257 |
this.resetFields(obj[key]); |
|
258 |
} else { |
|
259 |
obj[key] = ""; |
|
260 |
} |
|
261 |
} |
|
262 |
}, |
|
263 |
setDefaultFields(id, pointtypename) { |
|
264 |
this.dataForm.id = id || 0; |
|
265 |
this.dataForm.pointtypename = pointtypename || ""; |
|
266 |
this.expressionList = [ |
|
267 |
{ |
|
268 |
point: "", |
|
269 |
operator: "", |
|
270 |
}, |
|
271 |
]; |
|
272 |
}, |
|
273 |
}, |
|
274 |
}; |
|
275 |
</script> |
|
276 |
<style> |
|
277 |
.el-select { |
|
278 |
width: 100%; |
|
279 |
} |
|
280 |
.result-chart { |
|
281 |
height: 500px; |
|
282 |
} |
|
283 |
</style> |
|
284 |
|