【功能新增】IoT:设备管理界面增加批量删除功能

pull/620/MERGE
YunaiV 2024-12-14 19:12:28 +08:00
parent 8f1c660d1f
commit a2dec90edf
2 changed files with 42 additions and 2 deletions

View File

@ -82,11 +82,16 @@ export const DeviceApi = {
return await request.put({ url: `/iot/device/update-status`, data }) return await request.put({ url: `/iot/device/update-status`, data })
}, },
// 删除设备 // 删除单个设备
deleteDevice: async (id: number) => { deleteDevice: async (id: number) => {
return await request.delete({ url: `/iot/device/delete?id=` + id }) return await request.delete({ url: `/iot/device/delete?id=` + id })
}, },
// 删除多个设备
deleteDeviceList: async (ids: number[]) => {
return await request.delete({ url: `/iot/device/delete-list`, params: { ids: ids.join(',') } })
},
// 导出设备 // 导出设备
exportDeviceExcel: async (params: any) => { exportDeviceExcel: async (params: any) => {
return await request.download({ url: `/iot/device/export-excel`, params }) return await request.download({ url: `/iot/device/export-excel`, params })

View File

@ -113,13 +113,29 @@
> >
<Icon icon="ep:download" class="mr-5px" /> 导出 <Icon icon="ep:download" class="mr-5px" /> 导出
</el-button> </el-button>
<el-button
type="danger"
plain
@click="handleDeleteList"
:disabled="selectedIds.length === 0"
v-hasPermi="['iot:device:delete']"
>
<Icon icon="ep:delete" class="mr-5px" /> 批量删除
</el-button>
</el-form-item> </el-form-item>
</el-form> </el-form>
</ContentWrap> </ContentWrap>
<!-- 列表 --> <!-- 列表 -->
<ContentWrap> <ContentWrap>
<el-table v-loading="loading" :data="list" :stripe="true" :show-overflow-tooltip="true"> <el-table
v-loading="loading"
:data="list"
:stripe="true"
:show-overflow-tooltip="true"
@selection-change="handleSelectionChange"
>
<el-table-column type="selection" width="55" />
<el-table-column label="DeviceName" align="center" prop="deviceName"> <el-table-column label="DeviceName" align="center" prop="deviceName">
<template #default="scope"> <template #default="scope">
<el-link @click="openDetail(scope.row.id)">{{ scope.row.deviceName }}</el-link> <el-link @click="openDetail(scope.row.id)">{{ scope.row.deviceName }}</el-link>
@ -231,6 +247,7 @@ const queryFormRef = ref() // 搜索的表单
const exportLoading = ref(false) // const exportLoading = ref(false) //
const products = ref<ProductVO[]>([]) // const products = ref<ProductVO[]>([]) //
const deviceGroups = ref<DeviceGroupVO[]>([]) // const deviceGroups = ref<DeviceGroupVO[]>([]) //
const selectedIds = ref<number[]>([]) //
/** 查询列表 */ /** 查询列表 */
const getList = async () => { const getList = async () => {
@ -253,6 +270,7 @@ const handleQuery = () => {
/** 重置按钮操作 */ /** 重置按钮操作 */
const resetQuery = () => { const resetQuery = () => {
queryFormRef.value.resetFields() queryFormRef.value.resetFields()
selectedIds.value = [] //
handleQuery() handleQuery()
} }
@ -305,4 +323,21 @@ const handleExport = async () => {
exportLoading.value = false exportLoading.value = false
} }
} }
/** 多选框选中数据 */
const handleSelectionChange = (selection: DeviceVO[]) => {
selectedIds.value = selection.map((item) => item.id)
}
/** 批量删除按钮操作 */
const handleDeleteList = async () => {
try {
await message.delConfirm()
//
await DeviceApi.deleteDeviceList(selectedIds.value)
message.success(t('common.delSuccess'))
//
await getList()
} catch {}
}
</script> </script>