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