houzhongjian
2024-07-23 8501060c4f921d1e744c477e4dc08eb47b52693c
提交 | 用户 | 时间
850106 1 <template>
H 2   <el-drawer
3       direction="rtl"
4       :visible.sync="visible"
5       @close="handleClose"
6       size="50%"
7       append-to-body>
8     <div style="padding: 10px;">
9       <el-form
10           :inline="true"
11           :model="dataForm"
12           ref="dataForm"
13           @keyup.enter.native="getDataList()"
14       >
15         <el-form-item prop="tagName">
16           <el-input
17               v-model="dataForm.tagName"
18               placeholder="Tag名称"
19               clearable>
20           </el-input>
21         </el-form-item>
22         <el-form-item prop="tagDesc">
23           <el-input
24               v-model="dataForm.tagDesc"
25               placeholder="Tag描述"
26               clearable>
27           </el-input>
28         </el-form-item>
29         <el-form-item prop="address">
30           <el-input
31               v-model="dataForm.address"
32               placeholder="Modbus地址"
33               clearable>
34           </el-input>
35         </el-form-item>
36         <el-form-item>
37           <el-button @click="getDataList()"
38           >{{ $t("query") }}
39           </el-button>
40         </el-form-item>
41         <el-form-item>
42           <el-button type="primary" @click="addOrUpdateHandle()"
43           >新增
44           </el-button>
45         </el-form-item>
46         <el-form-item>
47           <el-upload
48               class="upload-demo"
49               :action="importUrl"
50               :on-success="onSuccess"
51               multiple
52               :limit="20"
53               :show-file-list="false"
54               :file-list="fileList">
55             <el-button type="success">导入</el-button>
56           </el-upload>
57         </el-form-item>
58       </el-form>
59       <el-table
60           v-loading="dataListLoading"
61           :data="dataList"
62           border
63           style="width: 100%"
64       >
65         <el-table-column
66             prop="tagName"
67             label="Tag名称"
68             header-align="center"
69             align="left"
70             min-width="150"
71         ></el-table-column>
72         <el-table-column
73             prop="tagDesc"
74             label="Tag描述"
75             header-align="center"
76             align="left"
77             min-width="150"
78         ></el-table-column>
79         <el-table-column
80             prop="dataType"
81             label="数据类型"
82             header-align="center"
83             align="center"
84         ></el-table-column>
85         <el-table-column
86             prop="address"
87             label="Modbus地址"
88             header-align="center"
89             align="center"
90         >
91         </el-table-column>
92         <el-table-column
93             prop="format"
94             label="大小端"
95             header-align="center"
96             align="center"
97         >
98         </el-table-column>
99         <el-table-column
100             prop="samplingRate"
101             label="采集频率"
102             header-align="center"
103             align="center"
104         >
105         </el-table-column>
106         <el-table-column
107             prop="enabled"
108             label="是否启用"
109             header-align="center"
110             align="center"
111         >
112           <template slot-scope="scope">
113             <el-tag v-if="scope.row.enabled === true" size="small">是</el-tag>
114             <el-tag v-else size="small" type="danger">否</el-tag>
115           </template>
116         </el-table-column>
117         <el-table-column
118             :label="$t('handle')"
119             fixed="right"
120             header-align="center"
121             align="center"
122             width="180"
123         >
124           <template slot-scope="scope">
125             <el-button
126                 type="text"
127                 size="small"
128                 @click="addOrUpdateHandle(scope.row.id)"
129             >{{ $t("update") }}
130             </el-button>
131             <el-button
132                 type="text"
133                 size="small"
134                 @click="deleteHandle(scope.row.id)"
135             >{{ $t("delete") }}
136             </el-button>
137             <el-button type="text" size="small" @click="chartHandle(scope.row)">历史值</el-button>
138             <el-button type="text" size="small" @click="currentHandle(scope.row)">当前值</el-button>
139           </template>
140         </el-table-column>
141       </el-table>
142       <el-pagination
143           @size-change="sizeChangeHandle"
144           @current-change="currentChangeHandle"
145           :current-page="pageIndex"
146           :page-sizes="[10, 20, 50, 100]"
147           :page-size="pageSize"
148           :total="totalPage"
149           layout="total, sizes, prev, pager, next, jumper"
150       >
151       </el-pagination>
152     </div>
153     <!-- 弹窗, 新增 / 修改 -->
154     <add-or-update
155         v-if="addOrUpdateVisible"
156         ref="addOrUpdate"
157         @refreshDataList="getDataList"
158     ></add-or-update>
159     <!-- 弹窗, 历史数据 -->
160     <chart-view v-if="chartViewVisible" ref="chartView"></chart-view>
161     <!-- 弹窗, 当前数据 -->
162     <current-view v-if="currentViewVisible" ref="currentView"></current-view>
163   </el-drawer>
164 </template>
165
166 <script>
167   import AddOrUpdate from "./modbus-tag-add-or-update";
168   import ChartView from "./components/data-tag-chart";
169   import CurrentView from "./components/data-tag-current.vue";
170
171   export default {
172     props: {
173       address: String,
174     },
175     data() {
176       return {
177         visible: false,
178         dataForm: {
179           id: "",
180           tagName: "",
181           dataType: "",
182           enabled: "",
183           format: "",
184           device: "",
185           address: "",
186           tagDesc: "",
187         },
188         dataList: [],
189         pageIndex: 1,
190         pageSize: 10,
191         totalPage: 0,
192         dataListLoading: false,
193         dataListSelections: [],
194         addOrUpdateVisible: false,
195         chartViewVisible: false,
196         currentViewVisible: false,
197         importUrl: '',
198         fileList: [],
199       };
200     },
201
202     components: {
203       AddOrUpdate,
204       ChartView,
205       CurrentView
206     },
207     mounted() {
208       this.getDataList();
209     },
210
211     methods: {
212       init(name, address) {
213         this.dataForm.device = name;
214         this.importUrl = '/proxyApi/data/channel/modbus/tag/import/' + name
215         this.visible = true;
216         this.$nextTick(() => {
217           this.getDataList();
218         });
219       },
220       handleClose() {
221         this.$refs["dataForm"].resetFields();
222         this.dataList = [];
223       },
224       // 获取数据列表
225       getDataList() {
226         this.dataListLoading = true;
227         this.$http({
228           url: "/data/channel/modbus/tag/list",
229           method: "get",
230           params: this.$http.adornParams({
231             page: this.pageIndex,
232             limit: this.pageSize,
233             device: this.dataForm.device,
234             tagName: this.dataForm.tagName,
235             address: this.dataForm.address,
236             tagDesc: this.dataForm.tagDesc,
237           }),
238         }).then(({data}) => {
239           if (data && data.code === 0) {
240             this.dataList = data.page.list;
241             this.totalPage = data.page.totalCount;
242           } else {
243             this.dataList = [];
244             this.totalPage = 0;
245           }
246           this.dataListLoading = false;
247         });
248       },
249       // 每页数
250       sizeChangeHandle(val) {
251         this.pageSize = val;
252         this.pageIndex = 1;
253         this.getDataList();
254       },
255       // 当前页
256       currentChangeHandle(val) {
257         this.pageIndex = val;
258         this.getDataList();
259       },
260       // 多选
261       selectionChangeHandle(val) {
262         this.dataListSelections = val;
263       },
264       // 新增 / 修改
265       addOrUpdateHandle(id) {
266         this.addOrUpdateVisible = true;
267         this.$nextTick(() => {
268           this.$refs.addOrUpdate.init(
269             id,
270             this.dataForm.device,
271             this.dataForm.address
272           );
273         });
274       },
275       // 删除
276       deleteHandle(id) {
277         this.$confirm(`确定对选中项进行删除操作?`, "提示", {
278           confirmButtonText: "确定",
279           cancelButtonText: "取消",
280           type: "warning",
281         })
282           .then(() => {
283             this.$http({
284               headers: {
285                 "Content-Type": "application/json",
286               },
287               url: `/data/channel/modbus/tag/delete`,
288               method: "post",
289               data: this.$http.adornData({
290                 id: id,
291               }),
292             }).then(({data}) => {
293               if (data && data.code === 0) {
294                 this.$message({
295                   message: "操作成功",
296                   type: "success",
297                   duration: 1500,
298                   onClose: () => {
299                     this.getDataList();
300                   },
301                 });
302               } else {
303                 this.$message.error(data.msg);
304               }
305             });
306           })
307           .catch(() => {
308           });
309       },
310       //历史数据
311       chartHandle(row) {
312         this.chartViewVisible = true;
313         this.$nextTick(() => {
314           this.$refs.chartView.init(row);
315         });
316       },
317       //当前数据
318       currentHandle(row) {
319         this.currentViewVisible = true;
320         this.$nextTick(() => {
321           this.$refs.currentView.init(row);
322         });
323       },
324       onSuccess(response, file, fileList) {
325         this.getDataList()
326         this.$message({
327           message: '上传成功',
328           type: 'success',
329           duration: 1500
330         })
331       },
332     },
333   };
334 </script>