diff --git a/src/api/iot/device/index.ts b/src/api/iot/device/index.ts
index 3dbc001f..9932dfcf 100644
--- a/src/api/iot/device/index.ts
+++ b/src/api/iot/device/index.ts
@@ -7,6 +7,7 @@ export interface DeviceVO {
deviceName: string // 设备名称
deviceType: string // 设备类型
status: string // 状态
+ isConnect?: string | number
readTopic: string // 读主题
writeTopic: string // 写主题
gatewayId: number // 网关id
@@ -25,6 +26,11 @@ export interface DeviceVO {
secretKey?: string // 秘钥
}
+export interface DeviceConnectParams {
+ id: string | number
+ isConnect: string | number
+}
+
// 物联设备 API
export const DeviceApi = {
// 查询物联设备分页
@@ -60,6 +66,10 @@ export const DeviceApi = {
return await request.post({ url: `/iot/device/copy`, params: { id } })
},
+ connectDevice: async (params: DeviceConnectParams) => {
+ return await request.post({ url: `/iot/device/connect`, data: params })
+ },
+
// 导出物联设备 Excel
exportDevice: async (params) => {
return await request.download({ url: `/iot/device/export-excel`, params })
@@ -89,10 +99,5 @@ export const DeviceApi = {
// 获得设备属性
getDeviceAttribute: async (id: number) => {
return await request.get({ url: `/iot/device-contact-model/get?id=` + id })
- },
-
- // 导出设备属性 Excel
- exportDeviceAttribute: async (params) => {
- return await request.download({ url: `/iot/device-contact-model/export-excel`, params })
}
}
diff --git a/src/views/iot/device/components/DeviceAttributeList.vue b/src/views/iot/device/components/DeviceAttributeList.vue
index 310d7814..2b7ce2e3 100644
--- a/src/views/iot/device/components/DeviceAttributeList.vue
+++ b/src/views/iot/device/components/DeviceAttributeList.vue
@@ -2,11 +2,13 @@
-
-
@@ -24,7 +26,8 @@
新增
-
导出
@@ -36,7 +39,8 @@
-
@@ -59,7 +63,8 @@
-
@@ -78,7 +83,8 @@
-
@@ -89,6 +95,7 @@ import { DICT_TYPE } from '@/utils/dict'
import { dateFormatter } from '@/utils/formatTime'
import download from '@/utils/download'
import { DeviceApi } from '@/api/iot/device'
+import { DeviceModelAttributeApi } from '@/api/iot/devicemodelattribute'
import DeviceAttributeForm from './DeviceAttributeForm.vue'
import { DeviceAttributeTypeApi, DeviceAttributeTypeVO } from '@/api/iot/deviceattributetype'
@@ -226,7 +233,7 @@ const handleExport = async () => {
try {
await message.exportConfirm()
exportLoading.value = true
- const data = await DeviceApi.exportDeviceAttribute({ ids: selectedIds.value.join(',') })
+ const data = await DeviceModelAttributeApi.exportDeviceModelAttribute({ ids: selectedIds.value.join(',') })
download.excel(data, '采集设备-点位管理.xls')
} catch {
} finally {
diff --git a/src/views/iot/device/index.vue b/src/views/iot/device/index.vue
index 2cb22589..6703ad4e 100644
--- a/src/views/iot/device/index.vue
+++ b/src/views/iot/device/index.vue
@@ -137,7 +137,7 @@
-
+
点位
编辑
+
+ {{ isRowConnected(scope.row) ? '断开连接' : '连接' }}
+
{
attributeDeviceName.value = row?.deviceName ?? ''
}
+const connectLoadingMap = reactive>({})
+
+const getRowConnectValue = (row: any) => {
+ return row?.isConnect ?? row?.status
+}
+
+const isRowConnected = (row: any) => {
+ return String(getRowConnectValue(row)) === '1'
+}
+
+const handleToggleConnect = async (row: DeviceVO) => {
+ const id = row?.id
+ if (!id) {
+ message.error('设备信息不完整')
+ return
+ }
+
+ const nextIsConnect = isRowConnected(row) ? '2' : '1'
+ const actionText = nextIsConnect === '1' ? '连接' : '断开连接'
+
+ try {
+ await message.confirm(`确认${actionText}设备“${row.deviceName ?? ''}”吗?`)
+ connectLoadingMap[id] = true
+
+ const params: DeviceConnectParams = { id: String(id), isConnect: nextIsConnect }
+ await DeviceApi.connectDevice(params)
+ message.success(`${actionText}成功`)
+ await getList()
+ } catch {
+ } finally {
+ connectLoadingMap[id] = false
+ }
+}
+
let timer: any = null;
/** 初始化 **/
onMounted(() => {
diff --git a/src/views/iot/devicemodel/components/ModelAttributeList.vue b/src/views/iot/devicemodel/components/ModelAttributeList.vue
index defc8605..83e6a8a2 100644
--- a/src/views/iot/devicemodel/components/ModelAttributeList.vue
+++ b/src/views/iot/devicemodel/components/ModelAttributeList.vue
@@ -3,11 +3,13 @@
-
-
@@ -45,7 +47,8 @@
新增
-
导出
@@ -59,7 +62,8 @@
-
@@ -75,7 +79,8 @@
-
编辑
@@ -86,7 +91,8 @@
-