diff --git a/src/api/iot/device/device/index.ts b/src/api/iot/device/device/index.ts index 06d029f97..026525e4e 100644 --- a/src/api/iot/device/device/index.ts +++ b/src/api/iot/device/device/index.ts @@ -72,11 +72,11 @@ export interface IotDeviceDownstreamReqVO { data: any // 请求参数 } -// MQTT 连接参数 VO -export interface MqttConnectionParamsVO { - mqttClientId: string // MQTT 客户端 ID - mqttUsername: string // MQTT 用户名 - mqttPassword: string // MQTT 密码 +// 设备认证参数 VO +export interface IotDeviceAuthInfoVO { + clientId: string // 客户端 ID + username: string // 用户名 + password: string // 密码 } // 设备 API @@ -162,8 +162,8 @@ export const DeviceApi = { }, // 获取设备 MQTT 连接参数 - getMqttConnectionParams: async (deviceId: number) => { - return await request.get({ url: `/iot/device/mqtt-connection-params`, params: { deviceId } }) + getDeviceAuthInfo: async (id: number) => { + return await request.get({ url: `/iot/device/get-auth-info`, params: { id } }) }, // 根据 ProductKey 和 DeviceNames 获取设备列表 diff --git a/src/views/iot/device/device/detail/DeviceDetailsInfo.vue b/src/views/iot/device/device/detail/DeviceDetailsInfo.vue index 7b64a8a64..16cc55809 100644 --- a/src/views/iot/device/device/detail/DeviceDetailsInfo.vue +++ b/src/views/iot/device/device/detail/DeviceDetailsInfo.vue @@ -27,52 +27,52 @@ {{ formatDate(device.onlineTime) }} - + {{ formatDate(device.offlineTime) }} - - 查看 + + 查看 - + - + - + - + - + @@ -80,7 +80,7 @@ @@ -92,20 +92,16 @@ import { DICT_TYPE } from '@/utils/dict' import { ProductVO } from '@/api/iot/product/product' import { formatDate } from '@/utils/formatTime' import { DeviceVO } from '@/api/iot/device/device' -import { DeviceApi, MqttConnectionParamsVO } from '@/api/iot/device/device/index' +import { DeviceApi, IotDeviceAuthInfoVO } from '@/api/iot/device/device' const message = useMessage() // 消息提示 const { product, device } = defineProps<{ product: ProductVO; device: DeviceVO }>() // 定义 Props const emit = defineEmits(['refresh']) // 定义 Emits -const mqttDialogVisible = ref(false) // 定义 MQTT 弹框的可见性 -const passwordVisible = ref(false) // 定义密码可见性状态 -const mqttParams = ref({ - mqttClientId: '', - mqttUsername: '', - mqttPassword: '' -}) // 定义 MQTT 参数对象 +const authDialogVisible = ref(false) // 定义设备认证信息弹框的可见性 +const authPasswordVisible = ref(false) // 定义密码可见性状态 +const authInfo = ref({} as IotDeviceAuthInfoVO) // 定义设备认证信息对象 /** 复制到剪贴板方法 */ const copyToClipboard = async (text: string) => { @@ -117,28 +113,21 @@ const copyToClipboard = async (text: string) => { } } -/** 打开 MQTT 参数弹框的方法 */ -const openMqttParams = async () => { +/** 打开设备认证信息弹框的方法 */ +const handleAuthInfoDialogOpen = async () => { try { - const data = await DeviceApi.getMqttConnectionParams(device.id) - // 根据 API 响应结构正确获取数据 - // TODO @haohao:'N/A' 是不是在 ui 里处理哈 - mqttParams.value = { - mqttClientId: data.mqttClientId || 'N/A', - mqttUsername: data.mqttUsername || 'N/A', - mqttPassword: data.mqttPassword || 'N/A' - } + authInfo.value = await DeviceApi.getDeviceAuthInfo(device.id) - // 显示 MQTT 弹框 - mqttDialogVisible.value = true + // 显示设备认证信息弹框 + authDialogVisible.value = true } catch (error) { - console.error('获取 MQTT 连接参数出错:', error) - message.error('获取MQTT连接参数失败,请检查网络连接或联系管理员') + console.error('获取设备认证信息出错:', error) + message.error('获取设备认证信息失败,请检查网络连接或联系管理员') } } -/** 关闭 MQTT 弹框的方法 */ -const handleCloseMqttDialog = () => { - mqttDialogVisible.value = false +/** 关闭设备认证信息弹框的方法 */ +const handleAuthInfoDialogClose = () => { + authDialogVisible.value = false }