houzhongjian
2024-07-23 8501060c4f921d1e744c477e4dc08eb47b52693c
提交 | 用户 | 时间
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         id: "",
64         cdbm: "",
65         cdmc: "",
66         lcsx: "",
67         lcxx: "",
68         startTime: this.getYMDHMS(),
69         endTime: "",
70       },
71       pointsValue: [],
72     };
73   },
74   created() {
75     this.setDialogWidth();
76   },
77   mounted() {
78     window.onresize = () => {
79       return (() => {
80         this.setDialogWidth();
81       })();
82     };
83   },
84   methods: {
85     setDialogWidth() {
86       let val = document.body.clientWidth;
87       const def = 1300; // 默认宽度
88       if (val < def) {
89         this.dialogWidth = "70%";
90       } else {
91         this.dialogWidth = "50%";
92       }
93     },
94
95     /**
96      * 根据时间戳获取时间
97      *
98      * @param {*} timestamp
99      * @returns
100      */
101     getYMDHMS() {
102       let timestamp = new Date().getTime();
103       let time = new Date(timestamp - 1000 * 60 * 30);
104       let year = time.getFullYear();
105       let month = time.getMonth() + 1;
106       let date = time.getDate();
107       let hours = time.getHours();
108       let minute = time.getMinutes();
109       let second = time.getSeconds();
110
111       if (month < 10) {
112         month = "0" + month;
113       }
114       if (date < 10) {
115         date = "0" + date;
116       }
117       if (hours < 10) {
118         hours = "0" + hours;
119       }
120       if (minute < 10) {
121         minute = "0" + minute;
122       }
123       if (second < 10) {
124         second = "0" + second;
125       }
126       return (
127         year +
128         "-" +
129         month +
130         "-" +
131         date +
132         " " +
133         hours +
134         ":" +
135         minute +
136         ":" +
137         "00"
138       );
139     },
140
141     init(row) {
142       this.dataForm.id = row.id;
143       this.dataForm.cdbm = row.cdbm;
144       this.dataForm.cdmc = row.cdmc;
145       this.dataForm.lcsx = row.lcsx;
146       this.dataForm.lcxx = row.lcxx;
147       this.dataForm.bjxx = row.bjxx;
148       this.dataForm.bjsx = row.bjsx;
149       this.dataForm.startTime = this.getYMDHMS();
150       this.dataForm.endTime = "";
151       this.getDataList();
152     },
153     exportPointsValue() {
154       let that = this;
155       this.$axios
156         .post(
157           `/data/data/pointRelation/points-value/excel`,
158           {
159             id: this.dataForm.id,
160             startTime: this.dataForm.startTime,
161             endTime: this.dataForm.endTime,
162           },
163           {
164             responseType: "blob",
165           }
166         )
167         .then(function (res) {
168           let blob = res.data;
169           // FileReader主要用于将文件内容读入内存
170           let reader = new FileReader();
171           reader.readAsDataURL(blob);
172           // onload当读取操作成功完成时调用
173           reader.onload = function (e) {
174             let a = document.createElement("a");
175             a.download = that.dataForm.cdmc + "PointValue.xls";
176             a.href = e.target.result;
177             document.body.appendChild(a);
178             a.click();
179             document.body.removeChild(a);
180           };
181         });
182     },
183     getDataList() {
184       this.visible = true;
185       if (this.dataForm.id) {
186         let params = {
187           pointNos: [this.dataForm.cdbm],
188           start: this.dataForm.startTime,
189           end: this.dataForm.endTime,
190         };
191         this.$http["post"](
192           `/data/api/data/pointRelation/history`,
193           params
194         )
195           .then(({ data: res }) => {
196             if (res.code !== 0) {
197               return this.$message.error(res.msg);
198             }
199             let dataList = [];
200             let xAxisData = [];
201             res.data[this.dataForm.cdbm].forEach(function (value) {
202               //判断数据是否为布尔型
203               if (typeof value["value"] === "boolean") {
204                 value["value"] = value["value"] ? 1 : 0;
205               }
206               dataList.push([value["time"], value["value"]]);
207               xAxisData.push(value["time"]);
208             });
209             let rangeH = this.dataForm.lcsx;
210             let rangeL = this.dataForm.lcxx;
211             let myChart = this.$echarts.init(
212               document.getElementById("chartDom")
213             );
214             let seriesData = [];
215             seriesData.push({
216               name: "采集值",
217               type: "line",
218               data: dataList,
219               showSymbol: false,
220               smooth: false,
221               lineStyle: {
222                 normal: {
223                   color: "#5B8FF9",
224                   width: 1,
225                 },
226               },
227             });
228             if (this.dataForm.bjsx) {
229               seriesData.push({
230                 name: "",
231                 data: [null],
232                 type: "line",
233                 smooth: false,
234                 markLine: {
235                   silent: true,
236                   lineStyle: {
237                     normal: {
238                       color: "#d87a80", // 这儿设置安全基线颜色
239                       width: 1,
240                     },
241                   },
242                   data: [
243                     {
244                       yAxis: this.dataForm.bjsx,
245                     },
246                   ],
247                   label: {
248                     show: true,
249                     position: "insideEndTop",
250                     color: "#d87a80",
251                     distance: [-25, 1],
252                     formatter: "{c}",
253                   },
254                   symbol: ["none", "none"],
255                 },
256               });
257             }
258             if (this.dataForm.bjxx) {
259               seriesData.push({
260                 name: "",
261                 data: [null],
262                 type: "line",
263                 smooth: false,
264                 showSymbol: true,
265                 markLine: {
266                   silent: true,
267                   lineStyle: {
268                     normal: {
269                       color: "#d87a80", // 这儿设置安全基线颜色
270                       width: 1,
271                     },
272                   },
273                   data: [
274                     {
275                       yAxis: this.dataForm.bjxx,
276                     },
277                   ],
278                   label: {
279                     show: true,
280                     position: "insideEndBottom",
281                     color: "#d87a80",
282                     distance: [-25, 1],
283                     formatter: "{c}",
284                   },
285                   symbol: ["none", "none"],
286                 },
287               });
288             }
289
290             let option = {
291               title: {
292                 text: this.dataForm.cdmc,
293                 top: 0,
294                 left: "1%",
295                 textStyle: {
296                   fontSize: 14,
297                 },
298               },
299               tooltip: {
300                 trigger: "axis",
301                 axisPointer: {
302                   type: "line",
303                   lineStyle: {
304                     color: "#cccccc",
305                     width: "1",
306                     type: "dashed",
307                   },
308                 },
309               },
310               legend: {
311                 show: false,
312                 top: 10,
313               },
314               grid: {
315                 top: 30,
316                 left: "3%",
317                 right: "5%",
318                 bottom: 10,
319                 containLabel: true,
320               },
321               xAxis: {
322                 type: "category",
323                 boundaryGap: false,
324                 data: xAxisData,
325               },
326               yAxis: {
327                 type: "value",
328                 // max: rangeH,
329                 // min: rangeL
330               },
331               dataZoom: [
332                 {
333                   type: "inside",
334                 },
335               ],
336               series: seriesData,
337             };
338             myChart.clear();
339             myChart.setOption(option);
340           })
341           .catch(() => {});
342       }
343     },
344     resetFields(obj) {
345       for (let key in obj) {
346         if (key === "pointtypename") {
347           continue;
348         }
349         if (obj[key] instanceof Array) {
350           obj[key] = [];
351         } else if (obj[key] instanceof Object) {
352           this.resetFields(obj[key]);
353         } else {
354           obj[key] = "";
355         }
356       }
357     },
358     setDefaultFields(id, pointtypename) {
359       this.dataForm.id = id || 0;
360       this.dataForm.pointtypename = pointtypename || "";
361       this.expressionList = [
362         {
363           point: "",
364           operator: "",
365         },
366       ];
367     },
368   },
369 };
370 </script>
371 <style>
372 .el-select {
373   width: 100%;
374 }
375
376 .result-chart {
377   height: 500px;
378 }
379 </style>
380