潘志宝
2024-11-22 df90c0c5cfa4de114798015b92120ad8ba8b4826
提交 | 用户 | 时间
24d32b 1 <template>
2   <el-drawer
3     v-model="drawer"
ebf2c1 4     size="60%"
24d32b 5     title="Kio Tag"
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')"
40             v-hasPermi="['data:channel-kio:create']"
41           >
42             <Icon icon="ep:plus" class="mr-5px" />
43             新增
44           </el-button>
6c2636 45           <el-button
J 46             type="warning"
47             plain
48             @click="handleImport"
49             v-hasPermi="['data:channel-kio-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-kio-tag:export']">
58             <Icon icon="ep:download" />导出
59           </el-button>
24d32b 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="tagDesc"
81           label="Tag描述"
82           header-align="center"
83           align="left"
84           min-width="150"
85         />
86         <el-table-column
87           prop="dataType"
88           label="数据类型"
89           header-align="center"
90           align="center"
91         />
92         <el-table-column
93           prop="enabled"
94           label="是否启用"
95           header-align="center"
96           align="center"
97         >
98           <template #default="scope">
6c2636 99             <el-tag v-if="scope.row.enabled === 1" size="small">是</el-tag>
24d32b 100             <el-tag v-else size="small" type="danger">否</el-tag>
93ce03 101           </template>
D 102         </el-table-column>
103         <el-table-column
104           prop="dataValue"
105           label="数据值"
106           header-align="center"
107           align="center"
ebf2c1 108           min-width="100"
93ce03 109           :formatter="(row) => {if (row.dataValue === -2.0) {return '--';}return row.dataValue;}"
D 110         />
111         <el-table-column
ebf2c1 112           prop="dataTime"
113           label="数据时间"
114           header-align="center"
115           align="center"
116           min-width="150"
117         />
118         <el-table-column
119           prop="dataQuality"
93ce03 120           label="数据质量"
D 121           header-align="center"
122           align="center"
ebf2c1 123         />
24d32b 124         <el-table-column label="操作" align="center" min-width="110" fixed="right">
125           <template #default="scope">
126             <el-button
127               link
128               type="primary"
129               @click="openForm('update', scope.row.id)"
130               v-hasPermi="['data:channel-kio:update']"
131             >
132               编辑
133             </el-button>
134             <el-button
135               link
136               type="danger"
137               @click="handleDelete(scope.row.id)"
138               v-hasPermi="['data:channel-kio:delete']"
139             >
140               删除
141             </el-button>
142           </template>
143         </el-table-column>
144       </el-table>
145       <!-- 分页 -->
146       <Pagination
147         :total="total"
148         v-model:page="queryParams.pageNo"
149         v-model:limit="queryParams.pageSize"
150         @pagination="getList"
151       />
152     </ContentWrap>
153     <!-- 表单弹窗:添加/修改 -->
154     <TagForm ref="formRef" @success="getList" />
6c2636 155     <TagImportForm ref="importFormRef" @success="getList" />
24d32b 156   </el-drawer>
157 </template>
158 <script lang="ts" setup>
159   import type { DrawerProps } from 'element-plus'
160   import * as KioTagApi from "@/api/data/channel/kio/tag";
161   import TagForm from './TagForm.vue'
6c2636 162   import download from "@/utils/download";
J 163   import TagImportForm from '../../common/tag/TagImportForm.vue'
93ce03 164   import {ref, onBeforeUnmount, onMounted} from "vue";
D 165   import * as HttpTagApi from "@/api/data/channel/http/tag";
24d32b 166
167   defineOptions({name: 'KioTag'})
168
169   const message = useMessage() // 消息弹窗
170   const {t} = useI18n() // 国际化
171
172   const drawer = ref(false)
173   const direction = ref<DrawerProps['direction']>('rtl')
174   const loading = ref(true) // 列表的加载中
175   const total = ref(0) // 列表的总页数
176   const list = ref([]) // 列表的数据
177   const queryParams = reactive({
178     pageNo: 1,
179     pageSize: 10,
180     device: undefined,
93ce03 181     deviceId: undefined,
D 182     currentValue:false,
24d32b 183     tagName: undefined
184   })
185   const queryFormRef = ref() // 搜索的表单
186   const exportLoading = ref(false) // 导出的加载中
187
188   /** 查询列表 */
189   const getList = async () => {
190     loading.value = true
191     try {
192       const page = await KioTagApi.getKioTagPage(queryParams)
193       list.value = page.list
194       total.value = page.total
195     } finally {
196       loading.value = false
197     }
198   }
199
200   /** 搜索按钮操作 */
201   const handleQuery = () => {
202     queryParams.pageNo = 1
203     getList()
204   }
205
206   /** 重置按钮操作 */
207   const resetQuery = () => {
208     queryFormRef.value.resetFields()
209     handleQuery()
210   }
211
212   /** 添加/修改操作 */
213   const formRef = ref()
214   const openForm = (type: string, id?: number) => {
215     formRef.value.open(type, id, queryParams.device)
216   }
217
218   /** 删除按钮操作 */
219   const handleDelete = async (id: number) => {
220     try {
221       // 删除的二次确认
222       await message.delConfirm()
223       // 发起删除
224       await KioTagApi.deleteKioTag(id)
225       message.success(t('common.delSuccess'))
226       // 刷新列表
227       await getList()
228     } catch {
229     }
230   }
231
232   /** 打开弹窗 */
93ce03 233   const open = async (deviceId?: string,device?: string) => {
24d32b 234     resetForm()
235     drawer.value = true
236     queryParams.device = device
93ce03 237     queryParams.deviceId = deviceId
24d32b 238     if (device) {
239       getList()
240     }
241   }
242   defineExpose({open}) // 提供 open 方法,用于打开弹窗
243
244   /** 重置表单 */
245   const resetForm = () => {
246     queryParams.pageNo = 1
247     queryParams.pageSize = 10
248     queryParams.device = ''
249     queryParams.tagName = ''
250   }
251
252   const handleClose = (done: () => void) => {
253     drawer.value = false
254   }
6c2636 255
J 256   /** tag导入 */
257   const importFormRef = ref()
258   const handleImport = () => {
259     if(queryParams.device){
260       importFormRef.value.open(queryParams.device, '/data/channel/kio/tag/import',KioTagApi.importKioTagTemplate(), 'Kio', queryParams.device)
261     }
262   }
263
264   /** 导出按钮操作 */
265   const handleExport = async () => {
266     try {
267       // 导出的二次确认
268       await message.exportConfirm()
269       // 发起导出
270       exportLoading.value = true
271       const data = await KioTagApi.exportKioTag(queryParams)
272       download.excel(data, 'Kio_' + queryParams.device + '_Tag列表.xlsx')
273     } catch {
274     } finally {
275       exportLoading.value = false
276     }
277   }
93ce03 278
D 279   let intervalId;
280
281   onMounted(async () => {
282     // 创建定时器
283     intervalId = setInterval(async () => {
284       if(queryParams.currentValue){
285         const page = await KioTagApi.getKioTagPage(queryParams)
286         list.value = page.list
287         total.value = page.total
288       }
289     }, 10000);
290   });
291
292   // 在组件卸载时清除定时器
293   onBeforeUnmount(() => {
294     if (intervalId) {
295       clearInterval(intervalId);
296     }
297   });
24d32b 298 </script>