潘志宝
2024-11-22 df90c0c5cfa4de114798015b92120ad8ba8b4826
提交 | 用户 | 时间
24d32b 1 <template>
2   <el-drawer
3     v-model="drawer"
ebf2c1 4     size="60%"
6c2636 5     title="OpcDA Tag"
24d32b 6     :direction="direction"
7     :before-close="handleClose"
8   >
9     <!-- 搜索 -->
10     <ContentWrap>
11       <el-form
12         class="-mb-15px"
13         :model="queryParams"
14         ref="queryFormRef"
15         :inline="true"
16         label-width="68px"
17       >
18         <el-form-item label="Tag名称" prop="tagName">
19           <el-input
20             v-model="queryParams.tagName"
21             placeholder="请输入Tag名称"
22             clearable
23             @keyup.enter="handleQuery"
24             class="!w-240px"
25           />
26         </el-form-item>
27         <el-form-item>
28           <el-button @click="handleQuery">
29             <Icon icon="ep:search" class="mr-5px" />
30             搜索
31           </el-button>
32           <el-button @click="resetQuery">
33             <Icon icon="ep:refresh" class="mr-5px" />
34             重置
35           </el-button>
36           <el-button
37             type="primary"
38             plain
39             @click="openForm('create')"
6c2636 40             v-hasPermi="['data:channel-opcda:create']"
24d32b 41           >
42             <Icon icon="ep:plus" class="mr-5px" />
43             新增
6c2636 44           </el-button>
J 45           <el-button
46             type="warning"
47             plain
48             @click="handleImport"
49             v-hasPermi="['data:channel-opcda-tag:import']">
50             <Icon icon="ep:upload" /> 导入
51           </el-button>
52           <el-button
53             type="success"
54             plain
55             @click="handleExport"
56             :loading="exportLoading"
57             v-hasPermi="['data:channel-opcda-tag:export']">
58             <Icon icon="ep:download" />导出
24d32b 59           </el-button>
60         </el-form-item>
93ce03 61         <el-form-item label="更新当前值" label-width="100px">
D 62           <el-switch
63             v-model="queryParams.currentValue"
64             active-color="#13ce66"
65             inactive-color="#ff4949"/>
66         </el-form-item>
24d32b 67       </el-form>
68     </ContentWrap>
69     <!-- 列表 -->
70     <ContentWrap>
71       <el-table v-loading="loading" :data="list">
72         <el-table-column
73           prop="tagName"
74           label="Tag名称"
75           header-align="center"
76           align="left"
77           min-width="150"
78         />
79         <el-table-column
80           prop="dataType"
81           label="数据类型"
82           header-align="center"
83           align="center"
84         />
85         <el-table-column
86           prop="enabled"
87           label="是否启用"
88           header-align="center"
89           align="center"
90         >
91           <template #default="scope">
6c2636 92             <el-tag v-if="scope.row.enabled === 1" size="small">是</el-tag>
24d32b 93             <el-tag v-else size="small" type="danger">否</el-tag>
93ce03 94           </template>
D 95         </el-table-column>
96         <el-table-column
97           prop="dataValue"
98           label="数据值"
99           header-align="center"
100           align="center"
ebf2c1 101           min-width="100"
93ce03 102           :formatter="(row) => {if (row.dataValue === -2.0) {return '--';}return row.dataValue;}"
D 103         />
104         <el-table-column
ebf2c1 105           prop="dataTime"
106           label="数据时间"
107           header-align="center"
108           align="center"
109           min-width="150"
110         />
111         <el-table-column
112           prop="dataQuality"
93ce03 113           label="数据质量"
D 114           header-align="center"
115           align="center"
ebf2c1 116         />
24d32b 117         <el-table-column label="操作" align="center" min-width="110" fixed="right">
118           <template #default="scope">
119             <el-button
120               link
121               type="primary"
122               @click="openForm('update', scope.row.id)"
123               v-hasPermi="['data:channel-modbus:update']"
124             >
125               编辑
126             </el-button>
127             <el-button
128               link
129               type="danger"
130               @click="handleDelete(scope.row.id)"
131               v-hasPermi="['data:channel-modbus:delete']"
132             >
133               删除
134             </el-button>
135           </template>
136         </el-table-column>
137       </el-table>
138       <!-- 分页 -->
139       <Pagination
140         :total="total"
141         v-model:page="queryParams.pageNo"
142         v-model:limit="queryParams.pageSize"
143         @pagination="getList"
144       />
145     </ContentWrap>
146     <!-- 表单弹窗:添加/修改 -->
147     <TagForm ref="formRef" @success="getList" />
6c2636 148     <TagImportForm ref="importFormRef" @success="getList" />
24d32b 149   </el-drawer>
150 </template>
151 <script lang="ts" setup>
152   import type { DrawerProps } from 'element-plus'
6c2636 153   import * as OpcDaTagApi from "@/api/data/channel/opcda/tag";
24d32b 154   import TagForm from './TagForm.vue'
6c2636 155   import download from "@/utils/download";
J 156   import {ref,reactive} from "vue";
157   import TagImportForm from '../../common/tag/TagImportForm.vue'
93ce03 158   import {onBeforeUnmount, onMounted} from "vue";
24d32b 159
160   defineOptions({name: 'ModBusTag'})
161
162   const message = useMessage() // 消息弹窗
163   const {t} = useI18n() // 国际化
164
165   const drawer = ref(false)
166   const direction = ref<DrawerProps['direction']>('rtl')
167   const loading = ref(true) // 列表的加载中
168   const total = ref(0) // 列表的总页数
169   const list = ref([]) // 列表的数据
170   const queryParams = reactive({
171     pageNo: 1,
172     pageSize: 10,
173     serverId: undefined,
6c2636 174     tagName: undefined,
4c535b 175     serverName: undefined,
93ce03 176     currentValue:false,
24d32b 177   })
178   const queryFormRef = ref() // 搜索的表单
179   const exportLoading = ref(false) // 导出的加载中
93ce03 180
24d32b 181   /** 查询列表 */
182   const getList = async () => {
183     loading.value = true
184     try {
6c2636 185       const page = await OpcDaTagApi.getOpcdaTagPage(queryParams)
24d32b 186       list.value = page.list
187       total.value = page.total
188     } finally {
189       loading.value = false
190     }
191   }
192
193   /** 搜索按钮操作 */
194   const handleQuery = () => {
195     queryParams.pageNo = 1
196     getList()
197   }
198
199   /** 重置按钮操作 */
200   const resetQuery = () => {
201     queryFormRef.value.resetFields()
202     handleQuery()
203   }
204
205   /** 添加/修改操作 */
206   const formRef = ref()
207   const openForm = (type: string, id?: number) => {
208     formRef.value.open(type, id, queryParams.serverId)
209   }
210
211   /** 删除按钮操作 */
212   const handleDelete = async (id: number) => {
213     try {
214       // 删除的二次确认
215       await message.delConfirm()
216       // 发起删除
6c2636 217       await OpcDaTagApi.deleteOpcdaTag(id)
24d32b 218       message.success(t('common.delSuccess'))
219       // 刷新列表
220       await getList()
221     } catch {
222     }
223   }
224
225   /** 打开弹窗 */
6c2636 226   const open = async (serverId?: string, serverName?: string) => {
24d32b 227     resetForm()
228     drawer.value = true
229     queryParams.serverId = serverId
6c2636 230     queryParams.serverName = serverName
24d32b 231     if (serverId) {
232       getList()
233     }
234   }
235   defineExpose({open}) // 提供 open 方法,用于打开弹窗
236
237   /** 重置表单 */
238   const resetForm = () => {
239     queryParams.pageNo = 1
240     queryParams.pageSize = 10
241     queryParams.serverId = ''
242     queryParams.tagName = ''
243   }
244
245   const handleClose = (done: () => void) => {
246     drawer.value = false
247   }
6c2636 248
J 249   /** tag导入 */
250   const importFormRef = ref()
251   const handleImport = () => {
252     if(queryParams.serverId){
253       importFormRef.value.open(queryParams.serverName, '/data/channel/opcda/tag/import',OpcDaTagApi.importOpcDaTagTemplate(), 'OpcDa', queryParams.serverId)
254     }
255   }
256
257   /** 导出按钮操作 */
258   const handleExport = async () => {
259     try {
260       // 导出的二次确认
261       await message.exportConfirm()
262       // 发起导出
263       exportLoading.value = true
264       const data = await OpcDaTagApi.exportOpcDaTag(queryParams)
265       download.excel(data, 'OpcDa_' + queryParams.serverName + '_Tag列表.xlsx')
266     } catch {
267     } finally {
268       exportLoading.value = false
269     }
270   }
93ce03 271   let intervalId;
D 272
273   onMounted(async () => {
274     // 创建定时器
275     intervalId = setInterval(async () => {
276       if(queryParams.currentValue){
050ddd 277         const page = await OpcDaTagApi.getOpcdaTagPage(queryParams)
93ce03 278         list.value = page.list
D 279         total.value = page.total
280       }
281     }, 10000);
282   });
283
284   // 在组件卸载时清除定时器
285   onBeforeUnmount(() => {
286     if (intervalId) {
287       clearInterval(intervalId);
288     }
289   });
24d32b 290 </script>