houzhongjian
2024-07-23 8501060c4f921d1e744c477e4dc08eb47b52693c
提交 | 用户 | 时间
850106 1 <template>
H 2   <el-card shadow="never" class="aui-card--fill">
3     <div class="mod-channel-modbus">
4       <el-form
5         :inline="true"
6         :model="dataForm"
7         @keyup.enter.native="getDataList()"
8       >
9         <el-form-item>
10           <el-input
11             v-model="dataForm.name"
12             placeholder="设备名称"
13             clearable
14           ></el-input>
15         </el-form-item>
16         <el-form-item>
17           <el-button @click="getDataList()">{{ $t("query") }}</el-button>
18         </el-form-item>
19         <el-form-item>
20           <el-button
21             v-hasPermi="['configinfo:modbus:add']"
22             type="primary"
23             @click="addOrUpdateHandle()"
24             >新增
25           </el-button>
26         </el-form-item>
27         <el-form-item>
28           <el-button
29             v-hasPermi="['configinfo:modbus:publish']"
30             type="primary"
31             @click="writeConfigHandle()"
32             >发布
33           </el-button>
34         </el-form-item>
35       </el-form>
36       <el-table
37         v-loading="dataListLoading"
38         :data="dataList"
39         border
40         style="width: 100%"
41       >
42         <el-table-column
43           prop="name"
44           label="设备名称"
45           header-align="center"
46           align="center"
47         >
48         </el-table-column>
49         <el-table-column
50           prop="address"
51           label="IP地址"
52           header-align="center"
53           align="center"
54         ></el-table-column>
55         <el-table-column
56           prop="port"
57           label="端口"
58           header-align="center"
59           align="center"
60         ></el-table-column>
61         <el-table-column
62           prop="connectInactivityTimeout"
63           label="不活动超时(ms)"
64           header-align="center"
65           align="center"
66         ></el-table-column>
67         <el-table-column
68           prop="reconnectInterval"
69           label="重连超时(ms)"
70           header-align="center"
71           align="center"
72         ></el-table-column>
73         <el-table-column
74           prop="attemptsBeforeTimeout"
75           label="重试次数"
76           header-align="center"
77           align="center"
78         ></el-table-column>
79         <el-table-column
80           prop="waitToRetryMilliseconds"
81           label="重试间隔(ms)"
82           header-align="center"
83           align="center"
84         ></el-table-column>
85         <el-table-column
86           prop="readTimeout"
87           label="读超时(ms)"
88           header-align="center"
89           align="center"
90         ></el-table-column>
91         <el-table-column
92           prop="writeTimeout"
93           label="写超时(ms)"
94           header-align="center"
95           align="center"
96         ></el-table-column>
97         <el-table-column
98           prop="useOptimizedBlockRead"
99           label="是否使用优化"
100           header-align="center"
101           align="center"
102         >
103           <template slot-scope="scope">
104             <el-tag v-if="scope.row.useOptimizedBlockRead === true" size="small"
105               >是</el-tag
106             >
107             <el-tag v-else size="small" type="danger">否</el-tag>
108           </template>
109         </el-table-column>
110         <el-table-column
111           :label="$t('handle')"
112           fixed="right"
113           header-align="center"
114           align="center"
115           width="160"
116         >
117           <template slot-scope="scope">
118             <el-button
119               v-hasPermi="['configinfo:modbus:update']"
120               type="text"
121               size="small"
122               @click="addOrUpdateHandle(scope.row.id)"
123               >{{ $t("update") }}
124             </el-button>
125             <el-button
126               v-hasPermi="['configinfo:modbus:delete']"
127               type="text"
128               size="small"
129               @click="deleteHandle(scope.row.id)"
130               >{{ $t("delete") }}
131             </el-button>
132             <el-button
133               v-hasPermi="['configinfo:modbus:tag']"
134               type="text"
135               size="small"
136               @click="tagItemHandle(scope.row.name, scope.row.address)"
137               >Tag
138             </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       <!-- 弹窗, 新增 / 修改 -->
153       <add-or-update
154         v-if="addOrUpdateVisible"
155         ref="addOrUpdate"
156         @refreshDataList="getDataList"
157       ></add-or-update>
158       <!-- 弹窗, tag -->
159       <tag-item
160         v-if="tagItemVisible"
161         ref="tagItem"
162         @refreshDataList="getDataList"
163       ></tag-item>
164     </div>
165   </el-card>
166 </template>
167 <script>
168 import mixinViewModule from '@/mixins/view-module'
169 import AddOrUpdate from "./modbus-add-or-update";
170 import TagItem from "./modbus-tag";
171
172 export default {
173   mixins: [mixinViewModule],
174   data() {
175     return {
176       mixinViewModuleOptions: {
177         getDataListURL: '/data/channel/modbus/device/list',
178         getDataListIsPage: true,
179         deleteURL: '/channel/modbus/device/delete',
180         deleteIsBatch: true
181       },
182       dataForm: {
183         id: "",
184         name: "",
185         address: "",
186         port: "",
187         connectInactivityTimeout: "",
188         reconnectInterval: "",
189         attemptsBeforeTimeout: "",
190         waitToRetryMilliseconds: "",
191         readTimeout: "",
192         writeTimeout: "",
193         useOptimizedBlockRead: "",
194         projectReference: "",
195       },
196       tagItemVisible: false,
197       dataList: [],
198       pageIndex: 1,
199       pageSize: 10,
200       totalPage: 0,
201       dataListLoading: false,
202       dataListSelections: [],
203       addOrUpdateVisible: false,
204     };
205   },
206
207   components: {
208     AddOrUpdate,
209     TagItem,
210   },
211   mounted() {
212     this.getDataList();
213   },
214   methods: {
215     // 获取数据列表
216     getDataList() {
217       this.dataListLoading = true;
218       this.$http({
219         url: "/data/channel/modbus/device/list",
220         method: "get",
221         params: this.$http.adornParams({
222           page: this.pageIndex,
223           limit: this.pageSize,
224           name: this.dataForm.name,
225         })
226       }).then(({ code, page }) => {
227         if (page && code === 0) {
228           this.dataList = page.list;
229           this.totalPage = page.totalCount;
230         } else {
231           this.dataList = [];
232           this.totalPage = 0;
233         }
234         this.dataListLoading = false;
235       });
236     },
237     // 每页数
238     sizeChangeHandle(val) {
239       this.pageSize = val;
240       this.pageIndex = 1;
241       this.getDataList();
242     },
243     // 当前页
244     currentChangeHandle(val) {
245       this.pageIndex = val;
246       this.getDataList();
247     },
248     // 新增 / 修改
249     addOrUpdateHandle(id) {
250       this.addOrUpdateVisible = true;
251       this.$nextTick(() => {
252         this.$refs.addOrUpdate.init(id);
253       });
254     },
255     //  tag方法
256     tagItemHandle(name, address) {
257       this.tagItemVisible = true;
258       this.$nextTick(() => {
259         this.$refs.tagItem.init(name, address);
260       });
261     },
262
263     // 删除
264     deleteHandle(id) {
265       this.$confirm(`确定对选中项进行删除操作?`, "提示", {
266         confirmButtonText: "确定",
267         cancelButtonText: "取消",
268         type: "warning",
269       })
270         .then(() => {
271           this.$http({
272             headers: {
273               "Content-Type": "application/json",
274             },
275             url: `/channel/modbus/device/delete`,
276             method: "post",
277             data: this.$http.adornData({
278               id: id,
279             }),
280           }).then(({ data }) => {
281             if (data && data.code === 0) {
282               this.$message({
283                 message: "操作成功",
284                 type: "success",
285                 duration: 1500,
286                 onClose: () => {
287                   this.getDataList();
288                 },
289               });
290             } else {
291               this.$message.error(data.msg);
292             }
293           });
294         })
295         .catch(() => {});
296     },
297     //写配置
298     writeConfigHandle() {
299       this.$confirm(`确定将当前配置写入oadp?`, "提示", {
300         confirmButtonText: "确定",
301         cancelButtonText: "取消",
302         type: "warning",
303       })
304         .then(() => {
305           this.$http({
306             url: `/queryConfig`,
307             method: "post",
308           }).then(({ data }) => {
309             if (data && data.code === 0) {
310               this.$message({
311                 message: "操作成功",
312                 type: "success",
313                 duration: 1500,
314                 onClose: () => {
315                   this.getDataList();
316                 },
317               });
318             } else {
319               this.$message.error(data.msg);
320             }
321           });
322         })
323         .catch(() => {});
324     },
325   },
326 };
327 </script>