From 1927899fc0c9443ea61b22f13923edb885c93235 Mon Sep 17 00:00:00 2001 From: hwj Date: Tue, 30 Dec 2025 14:32:49 +0800 Subject: [PATCH] =?UTF-8?q?feat=EF=BC=9A=E9=87=87=E9=9B=86=E8=AE=BE?= =?UTF-8?q?=E5=A4=87/=E5=AD=90=E5=88=97=E8=A1=A8=E6=B7=BB=E5=8A=A0?= =?UTF-8?q?=E6=89=B9=E9=87=8F=E5=88=A0=E9=99=A4=E6=8C=89=E9=92=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/api/iot/device/index.ts | 8 +-- src/api/iot/devicemodel/index.ts | 5 ++ src/views/iot/device/DeviceForm.vue | 4 +- .../device/components/DeviceAttributeList.vue | 24 ++++++- src/views/iot/device/index.vue | 49 ++++++++++++--- .../components/ModelAttributeList.vue | 24 +++---- src/views/iot/devicemodel/index.vue | 63 ++++++++++++++----- 7 files changed, 135 insertions(+), 42 deletions(-) diff --git a/src/api/iot/device/index.ts b/src/api/iot/device/index.ts index 46e18c29..5ab9bdb7 100644 --- a/src/api/iot/device/index.ts +++ b/src/api/iot/device/index.ts @@ -51,8 +51,8 @@ export const DeviceApi = { }, // 删除物联设备 - deleteDevice: async (id: number) => { - return await request.delete({ url: `/iot/device/delete?id=` + id }) + deleteDevice: async (ids: string) => { + return await request.delete({ url: `/iot/device/delete?ids=` + ids }) }, // 复制物联设备 @@ -82,8 +82,8 @@ export const DeviceApi = { }, // 删除设备属性 - deleteDeviceAttribute: async (id: number) => { - return await request.delete({ url: `/iot/device-contact-model/delete?id=` + id }) + deleteDeviceAttribute: async (ids: string) => { + return await request.delete({ url: `/iot/device-contact-model/delete?ids=` + ids }) }, // 获得设备属性 diff --git a/src/api/iot/devicemodel/index.ts b/src/api/iot/devicemodel/index.ts index e49cc52a..77aa1048 100644 --- a/src/api/iot/devicemodel/index.ts +++ b/src/api/iot/devicemodel/index.ts @@ -36,6 +36,11 @@ export const DeviceModelApi = { return await request.delete({ url: `/iot/device-model/delete?id=` + id }) }, + // 复制采集设备模型 + copyDeviceModel: async (id: number) => { + return await request.post({ url: `/iot/device-model/copy`, params: { id } }) + }, + // 导出采集设备模型 Excel exportDeviceModel: async (params) => { return await request.download({ url: `/iot/device-model/export-excel`, params }) diff --git a/src/views/iot/device/DeviceForm.vue b/src/views/iot/device/DeviceForm.vue index 597b02de..c40f6c77 100644 --- a/src/views/iot/device/DeviceForm.vue +++ b/src/views/iot/device/DeviceForm.vue @@ -76,9 +76,9 @@ - + 新增 + + 批量删除 + () @@ -227,18 +233,32 @@ const openForm = (type: string, id?: number) => { } /** 删除按钮操作 */ -const handleDelete = async (id: number) => { +const buildIdsParam = (ids: number | number[]) => { + return Array.isArray(ids) ? ids.join(',') : String(ids) +} + +const handleDelete = async (ids: number | number[]) => { try { // 删除的二次确认 await message.delConfirm() // 发起删除 - await DeviceApi.deleteDeviceAttribute(id) + await DeviceApi.deleteDeviceAttribute(buildIdsParam(ids)) message.success(t('common.delSuccess')) + selectedIds.value = [] + tableRef.value?.clearSelection?.() // 刷新列表 await getList() } catch {} } +const handleBatchDelete = async () => { + if (!selectedIds.value.length) { + message.error('请选择需要删除的数据') + return + } + await handleDelete(selectedIds.value) +} + onMounted(async () => { try { const data = await DeviceAttributeTypeApi.getDeviceAttributeTypePage({ pageNo: 1, pageSize: 10 }) diff --git a/src/views/iot/device/index.vue b/src/views/iot/device/index.vue index 55ad5899..f72ac725 100644 --- a/src/views/iot/device/index.vue +++ b/src/views/iot/device/index.vue @@ -74,6 +74,9 @@ > 导出 + + 批量删除 + @@ -81,13 +84,17 @@ - - + + + - + - + - + @@ -205,6 +212,8 @@ defineOptions({ name: 'Device' }) const message = useMessage() // 消息弹窗 const { t } = useI18n() // 国际化 +const tableRef = ref() + const loading = ref(true) // 列表的加载中 const list = ref([]) // 列表的数据 const total = ref(0) // 列表的总页数 @@ -228,6 +237,11 @@ const queryParams = reactive({ const queryFormRef = ref() // 搜索的表单 const exportLoading = ref(false) // 导出的加载中 +const selectedIds = ref([]) +const handleSelectionChange = (rows: any[]) => { + selectedIds.value = rows?.map((row) => row.id).filter((id) => id !== undefined) ?? [] +} + /** 查询列表 */ const getList = async () => { loading.value = true @@ -259,18 +273,37 @@ const openForm = (type: string, id?: number) => { } /** 删除按钮操作 */ -const handleDelete = async (id: number) => { +const buildIdsParam = (ids: number | number[]) => { + return Array.isArray(ids) ? ids.join(',') : String(ids) +} + +const handleDelete = async (ids: number | number[]) => { try { // 删除的二次确认 await message.delConfirm() // 发起删除 - await DeviceApi.deleteDevice(id) + const idsParam = buildIdsParam(ids) + await DeviceApi.deleteDevice(idsParam) message.success(t('common.delSuccess')) + selectedIds.value = [] + tableRef.value?.clearSelection?.() + if (attributeDeviceId.value && idsParam.split(',').includes(String(attributeDeviceId.value))) { + attributeDeviceId.value = undefined + attributeDeviceName.value = '' + } // 刷新列表 await getList() } catch {} } +const handleBatchDelete = async () => { + if (!selectedIds.value.length) { + message.error('请选择需要删除的数据') + return + } + await handleDelete(selectedIds.value) +} + const handleCopy = async (id: number) => { try { await DeviceApi.copyDevice(id) diff --git a/src/views/iot/devicemodel/components/ModelAttributeList.vue b/src/views/iot/devicemodel/components/ModelAttributeList.vue index 25294714..58c894f8 100644 --- a/src/views/iot/devicemodel/components/ModelAttributeList.vue +++ b/src/views/iot/devicemodel/components/ModelAttributeList.vue @@ -42,7 +42,7 @@ /> - + + 搜索 重置 @@ -78,7 +78,7 @@ plain @click="handleExport" :loading="exportLoading" - v-hasPermi="['iot:device-model-attribute:export']" + v-hasPermi="['iot:device-model:export']" > 导出 @@ -89,7 +89,7 @@ - + @@ -106,13 +106,13 @@ :formatter="dateFormatter" width="180px" /> - +