Skip to content

Commit c65c056

Browse files
committed
【功能新增】IoT: 设备详情新增MQTT连接参数查看功能
1 parent ca791df commit c65c056

File tree

2 files changed

+32
-7
lines changed

2 files changed

+32
-7
lines changed

src/api/iot/device/device/index.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,13 @@ export interface IotDeviceDownstreamReqVO {
7272
data: any // 请求参数
7373
}
7474

75+
// MQTT连接参数 VO
76+
export interface MqttConnectionParamsVO {
77+
mqttClientId: string // MQTT 客户端 ID
78+
mqttUsername: string // MQTT 用户名
79+
mqttPassword: string // MQTT 密码
80+
}
81+
7582
// 设备 API
7683
export const DeviceApi = {
7784
// 查询设备分页
@@ -152,5 +159,10 @@ export const DeviceApi = {
152159
// 查询设备日志分页
153160
getDeviceLogPage: async (params: any) => {
154161
return await request.get({ url: `/iot/device/log/page`, params })
162+
},
163+
164+
// 获取设备MQTT连接参数
165+
getMqttConnectionParams: async (deviceId: number) => {
166+
return await request.get({ url: `/iot/device/mqtt-connection-params`, params: { deviceId } })
155167
}
156168
}

src/views/iot/device/device/detail/DeviceDetailsInfo.vue

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,11 @@
6363
</el-input>
6464
</el-form-item>
6565
<el-form-item label="passwd">
66-
<el-input v-model="mqttParams.mqttPassword" readonly type="password">
66+
<el-input v-model="mqttParams.mqttPassword" readonly :type="passwordVisible ? 'text' : 'password'">
6767
<template #append>
68+
<el-button @click="passwordVisible = !passwordVisible" type="primary">
69+
<Icon :icon="passwordVisible ? 'ph:eye-slash' : 'ph:eye'" />
70+
</el-button>
6871
<el-button @click="copyToClipboard(mqttParams.mqttPassword)" type="primary">
6972
<Icon icon="ph:copy" />
7073
</el-button>
@@ -85,13 +88,15 @@ import { DICT_TYPE } from '@/utils/dict'
8588
import { ProductVO } from '@/api/iot/product/product'
8689
import { formatDate } from '@/utils/formatTime'
8790
import { DeviceVO } from '@/api/iot/device/device'
91+
import { DeviceApi, MqttConnectionParamsVO } from '@/api/iot/device/device/index'
8892
8993
const message = useMessage() // 消息提示
9094
9195
const { product, device } = defineProps<{ product: ProductVO; device: DeviceVO }>() // 定义 Props
9296
const emit = defineEmits(['refresh']) // 定义 Emits
9397
9498
const mqttDialogVisible = ref(false) // 定义 MQTT 弹框的可见性
99+
const passwordVisible = ref(false) // 定义密码可见性状态
95100
const mqttParams = ref({
96101
mqttClientId: '',
97102
mqttUsername: '',
@@ -109,13 +114,21 @@ const copyToClipboard = async (text: string) => {
109114
}
110115
111116
/** 打开 MQTT 参数弹框的方法 */
112-
const openMqttParams = () => {
113-
mqttParams.value = {
114-
mqttClientId: device.mqttClientId || 'N/A',
115-
mqttUsername: device.mqttUsername || 'N/A',
116-
mqttPassword: device.mqttPassword || 'N/A'
117+
const openMqttParams = async () => {
118+
try {
119+
const res = await DeviceApi.getMqttConnectionParams(device.id)
120+
121+
// 根据API响应结构正确获取数据
122+
mqttParams.value = {
123+
mqttClientId: res.mqttClientId || 'N/A',
124+
mqttUsername: res.mqttUsername || 'N/A',
125+
mqttPassword: res.mqttPassword || 'N/A'
126+
}
127+
mqttDialogVisible.value = true
128+
} catch (error) {
129+
console.error('获取MQTT连接参数出错:', error)
130+
message.error('获取MQTT连接参数失败,请检查网络连接或联系管理员')
117131
}
118-
mqttDialogVisible.value = true
119132
}
120133
121134
/** 关闭 MQTT 弹框的方法 */

0 commit comments

Comments
 (0)