congming_huose-apk/common/mixins/deviceOffline.js

45 lines
1.2 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

/**
* 设备详情接口字段 onlineStatus
* - 0或字符串 '0')→ 离线,显示顶部离线横幅
* - 1或字符串 '1')→ 在线,不显示横幅
* - 未返回 / 无法解析 → 不显示横幅
*
* 数据来源xqobj / sbobj若根级无 onlineStatus再读 iotOnlineData.onlineStatus
*/
function pickDeviceRecord(vm) {
if (vm.xqobj && typeof vm.xqobj === 'object' && Object.keys(vm.xqobj).length) {
return vm.xqobj
}
if (vm.sbobj && typeof vm.sbobj === 'object' && Object.keys(vm.sbobj).length) {
return vm.sbobj
}
return null
}
function normalizeOnlineStatus(raw) {
if (raw === undefined || raw === null || raw === '') return null
const n = Number(raw)
if (Number.isNaN(n)) return null
return n
}
export default {
computed: {
isDeviceOffline() {
const d = pickDeviceRecord(this)
if (!d) return false
let s = d.onlineStatus
if ((s === undefined || s === null || s === '') && d.iotOnlineData) {
s = d.iotOnlineData.onlineStatus
}
const n = normalizeOnlineStatus(s)
if (n === null) return false
return n === 0
},
/** 自定义导航 + 固定离线条时,给占位 view 增加的高度 (rpx) */
offlineBannerExtraRpx() {
return this.isDeviceOffline ? 56 : 0
},
},
}