dengzedong
2024-10-18 8d7d29c212001f44c00230b8491a441c241eeade
提交 | 用户 | 时间
b05c43 1 <template>
2   <el-drawer
3     v-model="drawer"
4     size="50%"
5     title="ModBus 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="请输入Modbus地址"
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-modbus: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="tagDesc"
69           label="Tag描述"
70           header-align="center"
71           align="left"
72           min-width="150"
73         />
74         <el-table-column
75           prop="dataType"
76           label="数据类型"
77           header-align="center"
78           align="center"
79         />
80         <el-table-column
81           prop="address"
82           label="地址"
83           header-align="center"
84           align="center"
85         />
86         <el-table-column
87           prop="format"
88           label="大小端"
89           header-align="center"
90           align="center"
91         />
92         <el-table-column
93           prop="samplingRate"
94           label="采集频率"
95           header-align="center"
96           align="center"
97         />
98         <el-table-column
99           prop="enabled"
100           label="是否启用"
101           header-align="center"
102           align="center"
103         >
104           <template #default="scope">
105             <el-tag v-if="scope.row.enabled === true" size="small">是</el-tag>
106             <el-tag v-else size="small" type="danger">否</el-tag>
107           </template>
108         </el-table-column>
109         <el-table-column label="操作" align="center" min-width="110" fixed="right">
110           <template #default="scope">
111             <el-button
112               link
113               type="primary"
114               @click="openForm('update', scope.row.id)"
115               v-hasPermi="['data:channel-modbus:update']"
116             >
117               编辑
118             </el-button>
119             <el-button
120               link
121               type="danger"
122               @click="handleDelete(scope.row.id)"
123               v-hasPermi="['data:channel-modbus:delete']"
124             >
125               删除
126             </el-button>
127           </template>
128         </el-table-column>
129       </el-table>
130       <!-- 分页 -->
131       <Pagination
132         :total="total"
133         v-model:page="queryParams.pageNo"
134         v-model:limit="queryParams.pageSize"
135         @pagination="getList"
136       />
137     </ContentWrap>
138     <!-- 表单弹窗:添加/修改 -->
139     <TagForm ref="formRef" @success="getList" />
140   </el-drawer>
141 </template>
142 <script lang="ts" setup>
143   import type { DrawerProps } from 'element-plus'
144   import * as ModBusTagApi from "@/api/data/channel/modbus/tag";
145   import TagForm from './TagForm.vue'
146
147   defineOptions({name: 'ModBusTag'})
148
149   const message = useMessage() // 消息弹窗
150   const {t} = useI18n() // 国际化
151
152   const drawer = ref(false)
153   const direction = ref<DrawerProps['direction']>('rtl')
154   const loading = ref(true) // 列表的加载中
155   const total = ref(0) // 列表的总页数
156   const list = ref([]) // 列表的数据
157   const queryParams = reactive({
158     pageNo: 1,
159     pageSize: 10,
160     device: undefined,
161     tagName: undefined,
162     address: undefined
163   })
164   const queryFormRef = ref() // 搜索的表单
165   const exportLoading = ref(false) // 导出的加载中
166
167   /** 查询列表 */
168   const getList = async () => {
169     loading.value = true
170     try {
171       const page = await ModBusTagApi.getModBusTagPage(queryParams)
172       list.value = page.list
173       total.value = page.total
174     } finally {
175       loading.value = false
176     }
177   }
178
179   /** 搜索按钮操作 */
180   const handleQuery = () => {
181     queryParams.pageNo = 1
182     getList()
183   }
184
185   /** 重置按钮操作 */
186   const resetQuery = () => {
187     queryFormRef.value.resetFields()
188     handleQuery()
189   }
190
191   /** 添加/修改操作 */
192   const formRef = ref()
193   const openForm = (type: string, id?: number) => {
194     formRef.value.open(type, id, queryParams.device)
195   }
196
197   /** 删除按钮操作 */
198   const handleDelete = async (id: number) => {
199     try {
200       // 删除的二次确认
201       await message.delConfirm()
202       // 发起删除
203       await ModBusTagApi.deleteModBusTag(id)
204       message.success(t('common.delSuccess'))
205       // 刷新列表
206       await getList()
207     } catch {
208     }
209   }
210
211   /** 打开弹窗 */
212   const open = async (device?: string) => {
213     resetForm()
214     drawer.value = true
215     queryParams.device = device
216     if (device) {
217       getList()
218     }
219   }
220   defineExpose({open}) // 提供 open 方法,用于打开弹窗
221
222   /** 重置表单 */
223   const resetForm = () => {
224     queryParams.pageNo = 1
225     queryParams.pageSize = 10
226     queryParams.device = ''
227     queryParams.tagName = ''
228     queryParams.address = ''
229   }
230
231   const handleClose = (done: () => void) => {
232     drawer.value = false
233   }
234 </script>