<!-- Description: 设备管理列表页面 Author: 李亚光 Date: 2023-05-28 --> <script lang="ts" setup name="AlarmList"> import { ElMessage, ElMessageBox } from 'element-plus' import editlist from './editDevice.vue' import type { TableColumn } from '@/components/NormalTable/table_interface' import { delDevice, getDeviceListPage } from '@/api/device' const editDevice = ref() const listQuery = reactive({ deviceName: '', offset: 1, limit: 20, location: '', }) // 筛选条件 const columns = ref<TableColumn[]>([]) columns.value = [ { text: '名称', value: 'deviceName', align: 'center' }, { text: '连接类型', value: 'connectTypeName', align: 'center' }, { text: '位置', value: 'location', align: 'center' }, { text: 'IP', value: 'ip', align: 'center' }, { text: '端口', value: 'port', align: 'center' }, { text: '用户名', value: 'userName', align: 'center' }, { text: '密码', value: 'password', align: 'center' }, { text: '设备状态', value: 'statusName', align: 'center' }, ] const list = ref([]) // 列表数据 const total = ref(0)// 数据总数 const listLoading = ref(true)// 加载动画 const fetchData = () => { getDeviceListPage(listQuery).then(res => { list.value = res.data.rows total.value = res.data.total listLoading.value = false }) } fetchData() // 清空查询条件 const reset = () => { listQuery.deviceName = '' listQuery.location = '' fetchData } // 删除 const del = (row: any) => { ElMessageBox.confirm( '确定要删除该设备吗?', '确认操作', { confirmButtonText: '确定', cancelButtonText: '取消', type: 'warning', }, ).then(() => { delDevice(row.id).then((response) => { if (response.code === 200) { ElMessage({ message: '删除成功', type: 'success', }) fetchData() } }) }) } // 编辑 const edit = (row: any) => { editDevice.value.initDialog('update', row) } // 新建 const add = () => { editDevice.value.initDialog('create', {}) } // 新建 const detail = (row: any) => { editDevice.value.initDialog('detail', row) } // 查询数据 const search = () => { fetchData() } // 页数发生变化后的操作,可能是页码变化,可能是每页容量变化,此函数必写 const changePage = (val: { size: number; page: number }) => { if (val && val.size) { listQuery.limit = val.size } if (val && val.page) { listQuery.offset = val.page } fetchData() } const clear = () => { listQuery.deviceName = '' fetchData() } </script> <template> <app-container> <!-- 筛选条件 --> <editlist ref="editDevice" @close-refresh="search" /> <search-area :need-clear="true" @search="search" @clear="reset"> <search-item> <el-input v-model.trim="listQuery.deviceName" placeholder="设备名称" clearable /> </search-item> <search-item> <el-input v-model.trim="listQuery.location" placeholder="设备位置" clearable /> </search-item> </search-area> <table-container> <template #btns-right> <!-- <icon-button icon="icon-add" title="新增" @click="add" /> --> <el-button type="primary" @click="add">新增</el-button> </template> <!-- 查询结果Table显示 --> <normal-table :data="list" :columns="columns" :total="total" :query="listQuery" :list-loading="listLoading" @change="changePage"> <template #preColumns> <el-table-column label="#" width="55" align="center"> <template #default="scope"> {{ (listQuery.offset - 1) * listQuery.limit + scope.$index + 1 }} </template> </el-table-column> </template> <template #columns> <el-table-column label="操作" width="160" align="center"> <template #default="scope"> <el-button type="primary" link size="small" @click="detail(scope.row)"> 详情 </el-button> <el-button type="primary" link size="small" @click="edit(scope.row)"> 编辑 </el-button> <el-button type="danger" link size="small" @click="del(scope.row)"> 删除 </el-button> </template> </el-table-column> </template> </normal-table> </table-container> </app-container> </template> <style lang="scss" scoped> // 样式 </style>