潘志宝
2024-11-14 da47a3349dcfd87db23ab8e64fbf35fe1aea5685
提交 | 用户 | 时间
031c25 1 <template>
D 2   <el-dialog
3     title="采集值"
4     :close-on-click-modal="false"
5     width="50%"
6     v-model="visible"
7   >
8     <el-form
9       :inline="true"
10       :model="dataForm"
11       @keydown.enter="getDataList()"
12     >
93ce03 13       <el-form-item label="开始时间">
031c25 14         <el-date-picker
93ce03 15           size="mini"
031c25 16           v-model="dataForm.startTime"
854c42 17           format="YYYY-MM-DD HH:mm:00"
D 18           value-format="YYYY-MM-DD HH:mm:00"
031c25 19           type="datetime"
93ce03 20           :clearable="false"
D 21           placeholder="选择日期时间"/>
031c25 22       </el-form-item>
93ce03 23       <el-form-item label="结束时间">
031c25 24         <el-date-picker
93ce03 25           size="mini"
031c25 26           v-model="dataForm.endTime"
0d21bc 27           format="YYYY-MM-DD HH:mm:00"
D 28           value-format="YYYY-MM-DD HH:mm:00"
031c25 29           type="datetime"
93ce03 30           :clearable="false"
D 31           placeholder="选择日期时间"/>
031c25 32       </el-form-item>
D 33       <el-form-item>
34         <el-button @click="getDataList()">查询</el-button>
35       </el-form-item>
36       <el-form-item>
37         <el-button
38           type="success"
39           plain
40           @click="handleExport"
41           :loading="exportLoading"
42           v-hasPermi="['data:point:export']"
43         >
44           <Icon icon="ep:download" />导出
45         </el-button>
46       </el-form-item>
47     </el-form>
48     <div ref="chartDom" class="result-chart"></div>
49   </el-dialog>
50 </template>
51
52 <script lang="ts" setup>
53   import {ref} from 'vue';
54   import * as echarts from 'echarts';
55   import * as DaPoint from '@/api/data/da/point/daPointChart'
0d21bc 56   import {getYMDHM0} from "@/utils/dateUtil"
031c25 57   import download from "@/utils/download";
D 58   const message = useMessage() // 消息弹窗
59   const visible = ref(false);
60   const chartDom = ref(null);
61   let myChart = null;
93ce03 62   const chartParams = reactive({
c9ff29 63     codes:[],
D 64     startDate : undefined,
65     endDate: undefined,
93ce03 66   })
D 67   const dataForm = ref({
68     id: "",
69     pointNo: "",
70     pointName: "",
71     pointTypeName: "",
0d21bc 72     startTime: getYMDHM0(new Date() - 60 * 60 * 1000),
0701f2 73     endTime: "",
93ce03 74   });
031c25 75
D 76   /** 打开弹窗 */
77   const open = async (row: object) => {
78     visible.value = true
79     dataForm.value.id = row.id;
80     dataForm.value.pointNo = row.pointNo;
81     dataForm.value.pointName = row.pointName;
82     getDataList();
83   }
84
85   defineExpose({open}) // 提供 open 方法,用于打开弹窗
86
87   async function getDataList() {
88     visible.value = true;
89     if (dataForm.value.id) {
90       try {
c9ff29 91         chartParams.codes=[dataForm.value.pointNo];
D 92         chartParams.startDate = dataForm.value.startTime;
93         chartParams.endDate = dataForm.value.endTime;
94         const data = await DaPoint.getPointDaChart(chartParams)
c4b4d2 95         let seriesData = []
96         data.series.forEach(item => {
97           seriesData.push({
98             name: item.name,
99             type: "line",
100             data: item.data,
101             showSymbol: true,
102             smooth: false,
103             lineStyle: {
104               normal: {
105                 color: "#5B8FF9",
106                 width: 1,
107               },
031c25 108             },
c4b4d2 109           });
110         })
111
031c25 112         myChart = echarts.init(chartDom.value);
D 113         const option = {
114           title: {
115             text: dataForm.value.pointName,
116             top: 0,
117             left: "1%",
118             textStyle: {
119               fontSize: 14,
120             },
121           },
122           tooltip: {
123             trigger: "axis",
124             axisPointer: {
125               type: "line",
126               lineStyle: {
127                 color: "#cccccc",
128                 width: "1",
129                 type: "dashed",
130               },
131             },
132           },
133           legend: {
134             show: false,
135             top: 10,
136           },
137           grid: {
138             top: 30,
139             left: "3%",
140             right: "5%",
141             bottom: 10,
142             containLabel: true,
143           },
144           xAxis: {
145             type: "category",
146             boundaryGap: false,
c4b4d2 147             data: data.categories,
031c25 148           },
D 149           yAxis: {
150             type: "value",
151           },
152           dataZoom: [
153             {
154               type: "inside",
155             },
156           ],
157           series: seriesData,
158         };
159         myChart.setOption(option);
160       } catch (error) {
161         console.error(error)
162       }
163     }
164   }
165   /** 导出按钮操作 */
166   const exportLoading = ref(false)
167   const handleExport = async () => {
c9ff29 168     chartParams.codes=[dataForm.value.pointNo];
D 169     chartParams.startDate = dataForm.value.startTime;
170     chartParams.endDate = dataForm.value.endTime;
031c25 171     try {
D 172       // 导出的二次确认
173       await message.exportConfirm()
174       // 发起导出
175       exportLoading.value = true
c9ff29 176       const data = await DaPoint.exportDaPointValue(chartParams)
031c25 177       download.excel(data, dataForm.value.pointName +'.xls')
D 178     } catch {
179     } finally {
180       exportLoading.value = false
181     }
182   }
183 </script>
184 <style>
185   .el-select {
186     width: 100%;
187   }
188
189   .result-chart {
190     height: 500px;
191   }
192 </style>