Jay
2024-09-24 74f2c0c7f3de951b6c21d2e423da5c7663df6f31
提交 | 用户 | 时间
24d32b 1 <template>
2   <el-drawer
3     v-model="drawer"
4     size="50%"
5     title="Opcua 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 label="地址" prop="address">
28           <el-input
29             v-model="queryParams.address"
30             placeholder="请输入地址"
31             clearable
32             @keyup.enter="handleQuery"
33             class="!w-240px"
34           />
35         </el-form-item>
36         <el-form-item>
37           <el-button @click="handleQuery">
38             <Icon icon="ep:search" class="mr-5px" />
39             搜索
40           </el-button>
41           <el-button @click="resetQuery">
42             <Icon icon="ep:refresh" class="mr-5px" />
43             重置
44           </el-button>
45           <el-button
46             type="primary"
47             plain
48             @click="openForm('create')"
49             v-hasPermi="['data:channel-opcua:create']"
50           >
51             <Icon icon="ep:plus" class="mr-5px" />
52             新增
53           </el-button>
54         </el-form-item>
55       </el-form>
56     </ContentWrap>
57     <!-- 列表 -->
58     <ContentWrap>
59       <el-table v-loading="loading" :data="list">
60         <el-table-column
61           prop="tagName"
62           label="Tag名称"
63           header-align="center"
64           align="left"
65           min-width="150"
66         />
67         <el-table-column
68           prop="dataType"
69           label="数据类型"
70           header-align="center"
71           align="center"
72         />
73         <el-table-column
74           prop="address"
75           label="地址"
76           header-align="center"
77           align="center"
78         />
79         <el-table-column
80           prop="samplingRate"
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">
92             <el-tag v-if="scope.row.enabled === true" size="small">是</el-tag>
93             <el-tag v-else size="small" type="danger">否</el-tag>
94           </template>
95         </el-table-column>
96         <el-table-column label="操作" align="center" min-width="110" fixed="right">
97           <template #default="scope">
98             <el-button
99               link
100               type="primary"
101               @click="openForm('update', scope.row.id)"
102               v-hasPermi="['data:channel-opcua:update']"
103             >
104               编辑
105             </el-button>
106             <el-button
107               link
108               type="danger"
109               @click="handleDelete(scope.row.id)"
110               v-hasPermi="['data:channel-opcua:delete']"
111             >
112               删除
113             </el-button>
114           </template>
115         </el-table-column>
116       </el-table>
117       <!-- 分页 -->
118       <Pagination
119         :total="total"
120         v-model:page="queryParams.pageNo"
121         v-model:limit="queryParams.pageSize"
122         @pagination="getList"
123       />
124     </ContentWrap>
125     <!-- 表单弹窗:添加/修改 -->
126     <TagForm ref="formRef" @success="getList" />
127   </el-drawer>
128 </template>
129 <script lang="ts" setup>
130   import type { DrawerProps } from 'element-plus'
131   import * as OpcuaTagApi from "@/api/data/channel/opcua/tag";
132   import TagForm from './TagForm.vue'
133
134   defineOptions({name: 'OpcuaTag'})
135
136   const message = useMessage() // 消息弹窗
137   const {t} = useI18n() // 国际化
138
139   const drawer = ref(false)
140   const direction = ref<DrawerProps['direction']>('rtl')
141   const loading = ref(true) // 列表的加载中
142   const total = ref(0) // 列表的总页数
143   const list = ref([]) // 列表的数据
144   const queryParams = reactive({
145     pageNo: 1,
146     pageSize: 10,
147     device: undefined,
148     tagName: undefined,
149     address: undefined
150   })
151   const queryFormRef = ref() // 搜索的表单
152   const exportLoading = ref(false) // 导出的加载中
153
154   /** 查询列表 */
155   const getList = async () => {
156     loading.value = true
157     try {
158       const page = await OpcuaTagApi.getOpcuaTagPage(queryParams)
159       list.value = page.list
160       total.value = page.total
161     } finally {
162       loading.value = false
163     }
164   }
165
166   /** 搜索按钮操作 */
167   const handleQuery = () => {
168     queryParams.pageNo = 1
169     getList()
170   }
171
172   /** 重置按钮操作 */
173   const resetQuery = () => {
174     queryFormRef.value.resetFields()
175     handleQuery()
176   }
177
178   /** 添加/修改操作 */
179   const formRef = ref()
180   const openForm = (type: string, id?: number) => {
181     formRef.value.open(type, id, queryParams.device)
182   }
183
184   /** 删除按钮操作 */
185   const handleDelete = async (id: number) => {
186     try {
187       // 删除的二次确认
188       await message.delConfirm()
189       // 发起删除
190       await OpcuaTagApi.deleteOpcuaTag(id)
191       message.success(t('common.delSuccess'))
192       // 刷新列表
193       await getList()
194     } catch {
195     }
196   }
197
198   /** 打开弹窗 */
199   const open = async (device?: string) => {
200     resetForm()
201     drawer.value = true
202     queryParams.device = device
203     if (device) {
204       getList()
205     }
206   }
207   defineExpose({open}) // 提供 open 方法,用于打开弹窗
208
209   /** 重置表单 */
210   const resetForm = () => {
211     queryParams.pageNo = 1
212     queryParams.pageSize = 10
213     queryParams.device = ''
214     queryParams.tagName = ''
215     queryParams.address = ''
216   }
217
218   const handleClose = (done: () => void) => {
219     drawer.value = false
220   }
221 </script>