@ -22,7 +22,9 @@
< view class = "row" >
< image class = "img" src = "/static/images/6155/DeviceDetail/time.png" mode = "aspectFit" > < / image >
< view class = "txt" >
< view class = "bigTxt" > { { Math . floor ( ( Number ( deviceInfo . batteryRemainingTime ) || 0 ) / 60 ) } } 小时 { { ( Number ( deviceInfo . batteryRemainingTime ) || 0 ) % 60 } } 分钟
< view class = "bigTxt" >
{ { Math . floor ( ( Number ( deviceInfo . batteryRemainingTime ) || 0 ) / 60 ) } } 小时
{ { ( Number ( deviceInfo . batteryRemainingTime ) || 0 ) % 60 } } 分钟
< / view >
< view class = "smallTxt" > 续航时间 < / view >
< / view >
@ -51,8 +53,8 @@
{ { deviceInfo && deviceInfo . latitude ? Number ( deviceInfo . latitude ) . toFixed ( 4 ) : '' } }
< / view >
< view class = "info-value status-running locationGPS" >
< uni-icons type = "location" size = "17"
color = "rgba(255, 255, 255, 0.8)" style = "vertical-align: bottom;" / >
< uni-icons type = "location" size = "17" color = "rgba(255, 255, 255, 0.8)"
style = "vertical-align: bottom;" / >
{ { deviceInfo . address } }
< / view >
< / view >
@ -60,7 +62,7 @@
< / view >
< view class = "lampMode" >
< view class = "sosContent" >
< view class = "btnSos openSos center" : class = "{ active: formData.sta_SOSType === 1 }"
< view class = "btnSos openSos center" : class = "{ active: deviceInfo.voiceStrobeAlarm === 1 }"
@click ="sosSetting(1)" >
{{ deviceInfo.voiceStrobeAlarm = = = 1 ? ' 报警中 ' : ' 强制报警 ' }}
< / view >
@ -312,7 +314,6 @@
lightBrightness : 10 ,
sta _system : '' ,
warnTime : 0 ,
sta _SOSType : 0
} ,
dic : {
sta _VoiceType : {
@ -464,19 +465,109 @@
}
this . mqttClient = new MqttClient ( ) ;
// this.mqttClient.connect(() => {
// // 订阅来自设备的状态更新
// const statusTopic = `status/894078/HBY100/${data.data.deviceImei}`;
// this.mqttClient.subscribe(statusTopic, (payload) => {
// try {
// // 解析MQTT返回的payload
// const payloadObj = typeof payload === 'string' ? JSON.parse(
// payload) : payload;
// } catch (e) {
// }
// })
// })
this . mqttClient . connect ( ( ) => {
// 订阅来自设备的状态更新
const statusTopic = ` status/894078/HBY100/ ${ data . data . deviceImei } ` ;
this . mqttClient . subscribe ( statusTopic , ( payload ) => {
try {
// 解析MQTT返回的payload
const payloadObj = typeof payload === 'string' ? JSON . parse (
payload ) : payload ;
console . log ( payloadObj , '这是我的数据类型么' ) ;
const data = payloadObj . data ? ? { } ;
const funcType = payloadObj . funcType ? ? '' ; // 从顶层获取funcType
const {
siren _alarm = {
enable : 0 ,
mode : 0
} ,
led _strobe = {
enable : 0 ,
mode : 0 ,
frequency : 0
} ,
volume = 0 ,
brightness = {
red : 0 ,
green : 0 ,
blue : 0
} ,
} = data ;
// 3. 赋值对应的字段
// 续航时间相关
if ( funcType == '4' ) {
these . deviceInfo . batteryPercentage = data . level //电量
these . deviceInfo . batteryRemainingTime = data
. battery _remaining _time //续航时间
} else if ( funcType == '14' ) {
// 调节相关字段
these . formData . strobeFrequency = led _strobe . frequency ||
0.5 ; //频率
these . formData . volume = volume || 10 ; //音量
these . formData . lightBrightness = brightness . red ||
10 ; //亮度值
// 报警模式,选中,首次上报值,或者切换设备按键上报值
const enable = siren _alarm . enable ? ? 0 ; // 报警开关: 1=开, 0=关
const mode = siren _alarm . mode ? ? 0 ; // 模式: 0/1/2/3/4/5/6
if ( these . formData . sta _VoiceType != 7 ) {
if ( enable === 1 ) {
// 开启状
these . formData . sta _VoiceType = mode + '' ;
} else {
// 关闭状态:赋值-1, 表示关闭
these . formData . sta _VoiceType = mode + '' ;
}
} else {
// 播放语音,上报消息
const voiceStrobeAlarm = data . voice _broadcast ? ? 0 ;
if ( voiceStrobeAlarm === 1 ) {
these . formData . sta _VoiceType = '7'
} else {
these . formData . sta _VoiceType = '-1'
}
}
}
// 报警模式相关字段赋值
// 是语音播放根据这个字段
if ( funcType === '6' ) {
console . log ( '我是谁' , data . voice _broadcast ) ;
// 语音频闪报警: 0=关闭, 1=开启 ui7是播放的状态
const voiceStrobeAlarm = data . voice _broadcast ? ? 0 ;
if ( voiceStrobeAlarm === 1 ) {
these . formData . sta _VoiceType = '7'
} else {
these . formData . sta _VoiceType = '-1'
}
} else if ( funcType === '12' ) {
// 报警模式: 直接用alarmMode作为sta_VoiceType
const alarmMode = data . mode ? ? 0 ;
these . formData . sta _VoiceType = alarmMode + '' ; // 转字符串匹配key
}
// 警示灯模式选中切换
if ( funcType === '10' ) {
const enable = data . enable ? ? 0 ; // 开关: 1=开, 0=关
const mode = data . mode ? ? 0 ; // 模式: 0/1/2/3/4/5/6
if ( enable === 1 ) {
// 开启状
these . formData . sta _LightType = mode + '' ;
} else {
// 关闭状态:赋值-1, 表示关闭
these . formData . sta _LightType = '-1' ;
}
}
// 报警模式相关字段
console . log ( 'formData赋值完成: ' , these . formData ) ;
} catch ( e ) {
// 捕获异常并打印, 方便排查问题( 不要空catch)
console . log ( '解析MQTT payload失败: ' , e ) ;
}
} )
} )
console . log ( data , 'datatatatat' ) ;
these . fetchDeviceDetail ( data . data . id )
} ) ;
@ -502,6 +593,7 @@
} ,
// 获取设备详情(普通详情)
fetchDeviceDetail ( id ) {
let that = this
deviceDetail ( id ) . then ( ( res ) => {
if ( res . code == 200 ) {
const validData = Object . fromEntries (
@ -511,13 +603,17 @@
} )
) ;
Object . assign ( this . formData , validData ) ;
this . deviceInfo = res . data ;
// 0 红色爆闪, 1 蓝色爆闪, 2 黄色爆闪, 3, 红色顺时针旋转爆闪, 4黄色顺时针旋转爆闪, 5, 红蓝顺时针旋转爆闪, 6 红蓝交替爆闪
this . formData . sta _LightTyp e = ( res . data . strobeMode ? ? 0 ) + ''
// 0爆闪关闭, 1爆闪开启
const strobeEnable = res . data . strobeEnable ? ? 0 ;
this . formData . sta _LightType = strobeEnable === 1 ? 1 : - 1 ;
if ( res . data . alarmMode == 7 ) {
that . deviceInfo = res . data ;
const strobeEnable = res . data . strobeEnable ? ? 0 ; // 0=关闭, 1=开启
const strobeMod e = res . data . strobeMode ? ? 0 ; // 0=红闪、1=蓝闪、3=红色顺时针...
if ( strobeEnable === 1 ) {
// 开启状态
that . formData . sta _LightType = strobeMode + '' ;
} else {
// 关闭状态
that . formData . sta _LightType = '-1' ;
}
if ( this . formData _VoiceType == 7 ) {
this . formData . sta _VoiceType = res . data . voiceStrobeAlarm ? ? 0 ;
} else {
this . formData . sta _VoiceType = res . data . alarmMode + ''
@ -553,7 +649,6 @@
} ,
// 语音管理
audioManager ( item ) {
this . formData . sta _VoiceType = - 1
if ( this . Status . apiType !== 'listA' ) { }
uni . navigateTo ( {
url : '/pages/100J/audioManager/AudioList' ,
@ -687,6 +782,7 @@
} ,
// 警示灯开关闭
lightTypeSet ( item , index ) {
console . log ( '走了么' ) ;
let val = item . key ;
// 切换选中/取消选中逻辑
if ( this . formData . sta _LightType === val ) {
@ -731,9 +827,11 @@
val = '-1' ;
}
this . formData . sta _VoiceType = val ;
console . log ( this . formData . sta _VoiceType , 'this.formData.sta_VoiceType' )
// 模式类型为7时才去判断
if ( val === '7' || val === '-1 ' ) {
console . log ( val , 'valllll ') ;
const voiceStrobeAlarm = this . deviceInfo ? . voiceStrobeAlarm ? ? 0 ; // 兜底0, 避免undefined
const isVoiceOperate = val === '7' || val === '-1' ; // 标记是否是语音开启/关闭操作
if ( voiceStrobeAlarm === 0 && isVoiceOperate ) {
let data = {
deviceId : this . deviceInfo . deviceId ,
voiceBroadcast : Number ( this . formData . sta _VoiceType ) === - 1 ? 0 : 1
@ -751,6 +849,28 @@
} ) ;
}
} )
} else if ( this . deviceInfo . voiceStrobeAlarm == 1 ) {
console . log ( '走到这里了没' ) ;
// 如果强制报警已经开启了,那么切换下面的模式需要时,需要触发报警指令
const data = {
deviceIds : [ this . deviceInfo . deviceId ] ,
// 声光报警开关开启传1
voiceStrobeAlarm : 1 ,
mode : this . formData . sta _VoiceType
} ;
deviceForceAlarmActivation ( data ) . then ( ( res ) => {
if ( res . code === 200 ) {
uni . showToast ( {
title : '强制报警已开启' ,
icon : 'none'
} ) ;
} else {
uni . showToast ( {
title : res . msg ,
icon : 'none'
} ) ;
}
} )
}
} ,
@ -775,8 +895,7 @@
showCancel : true ,
buttonCancelText : '取消' ,
okCallback : ( ) => {
console . log ( this . formData . sta _SOSType , 'this.formData.sta_SOSType' ) ;
this . formData . sta _SOSType = isClose ? 0 : 1 ;
this . deviceInfo . voiceStrobeAlarm = isClose ? 0 : 1 ; //强制报警,报警中 0是强制报警,1是报警中
const data = {
deviceIds : [ this . deviceInfo . deviceId ] ,
// 声光报警开关: 关闭传0, 开启传1
@ -789,18 +908,16 @@
title : isClose ? '声光报警已解除' : '强制报警已开启' ,
icon : 'none'
} ) ;
if ( isClose && this . formData . sta _VoiceType === '7' ) {
this . formData . sta _VoiceType = '-1' ;
}
} else {
uni . showToast ( {
title : res . msg ,
icon : 'none'
} ) ;
}
} ) . catch ( ( err ) => {
uni . showToast ( {
title : '请求失败,请重试' ,
icon : 'none'
} ) ;
} ) ;
} ) . catch ( ( err ) => { } ) ;
}
} ;
} ,
@ -814,7 +931,7 @@
if ( receive . deviceId !== this . formData . deviceId ) {
return ;
}
if ( this . formData . sta _battery <= 20 ) {
if ( this . deviceInfo . batteryPercentage <= 20 ) {
this . showMsg ( "设备电量低" ) ;
}
} ,
@ -1307,8 +1424,6 @@
. proinfo . item . img {
width : 50 rpx ;
height : 50 rpx ;
}
. proinfo . item . txt {
@ -1321,14 +1436,10 @@
text - align : left ;
}
. slider - container {
padding : 0 px ;
}
. addIco {
width : 100 % ;
height : 360 rpx ;
@ -1749,6 +1860,7 @@
width : 100 % ;
font - size : 32 rpx ;
}
. info - row {
display : flex ;
justify - content : space - between ;