|
@@ -366,7 +366,9 @@ export default {
|
|
bindShow: false,
|
|
bindShow: false,
|
|
modalName: false,
|
|
modalName: false,
|
|
activeBreak: false,
|
|
activeBreak: false,
|
|
- isConnect: false
|
|
|
|
|
|
+ isConnect: false,
|
|
|
|
+ mySns: '',
|
|
|
|
+ closed: false
|
|
};
|
|
};
|
|
},
|
|
},
|
|
// onLoad() {
|
|
// onLoad() {
|
|
@@ -413,9 +415,6 @@ export default {
|
|
this.closeWebsocket()
|
|
this.closeWebsocket()
|
|
},
|
|
},
|
|
onShow() {
|
|
onShow() {
|
|
- if (this.memberId) {
|
|
|
|
- this.API_getDeviceList()
|
|
|
|
- }
|
|
|
|
const imei = Storage.getItem('nowChangeDevice')
|
|
const imei = Storage.getItem('nowChangeDevice')
|
|
if (imei) {
|
|
if (imei) {
|
|
this.homeFrom.nowDevice = imei
|
|
this.homeFrom.nowDevice = imei
|
|
@@ -424,6 +423,7 @@ export default {
|
|
this.deviceAdded = false
|
|
this.deviceAdded = false
|
|
}
|
|
}
|
|
if (this.memberId) {
|
|
if (this.memberId) {
|
|
|
|
+ this.API_getDeviceList()
|
|
if (this.connected) {
|
|
if (this.connected) {
|
|
console.log('发送确认在线消息...')
|
|
console.log('发送确认在线消息...')
|
|
this.mySocketTask.send({data: '1'})
|
|
this.mySocketTask.send({data: '1'})
|
|
@@ -440,8 +440,10 @@ export default {
|
|
}
|
|
}
|
|
}, 1000)
|
|
}, 1000)
|
|
} else {
|
|
} else {
|
|
- console.log('重新连接...')
|
|
|
|
- this.connect()
|
|
|
|
|
|
+ if (this.deviceList.length > 0) {
|
|
|
|
+ console.log('重新连接...')
|
|
|
|
+ this.connect()
|
|
|
|
+ }
|
|
}
|
|
}
|
|
}
|
|
}
|
|
},
|
|
},
|
|
@@ -451,13 +453,18 @@ export default {
|
|
const _this = this
|
|
const _this = this
|
|
API_deviceMemberBind.getDeviceByDtypeAndMemberId({dtype: deviceDtypeEnum.DEVICE_TYPE.SMCD, memberId: this.memberId}).then(res => {
|
|
API_deviceMemberBind.getDeviceByDtypeAndMemberId({dtype: deviceDtypeEnum.DEVICE_TYPE.SMCD, memberId: this.memberId}).then(res => {
|
|
if (res) {
|
|
if (res) {
|
|
|
|
+ _this.deviceList = res
|
|
if (res.length === 0) {
|
|
if (res.length === 0) {
|
|
_this.deviceAdded = false
|
|
_this.deviceAdded = false
|
|
|
|
+ if (this.homeFrom.nowDevice) {
|
|
|
|
+ _this.homeFrom.nowDevice = ''
|
|
|
|
+ _this.sendSns()
|
|
|
|
+ }
|
|
Storage.removeItem("nowChangeDevice")
|
|
Storage.removeItem("nowChangeDevice")
|
|
Storage.removeItem("myBindDevices")
|
|
Storage.removeItem("myBindDevices")
|
|
} else {
|
|
} else {
|
|
_this.deviceAdded = true
|
|
_this.deviceAdded = true
|
|
- _this.deviceList = res
|
|
|
|
|
|
+ _this.sendSns()
|
|
let nowDevice = Storage.getItem("nowChangeDevice")
|
|
let nowDevice = Storage.getItem("nowChangeDevice")
|
|
if (!nowDevice) {
|
|
if (!nowDevice) {
|
|
Storage.setItem("nowChangeDevice", res[0].imei)
|
|
Storage.setItem("nowChangeDevice", res[0].imei)
|
|
@@ -489,10 +496,10 @@ export default {
|
|
}
|
|
}
|
|
this.connecting = true
|
|
this.connecting = true
|
|
let wsUrl = API.base.replace('http', 'ws')
|
|
let wsUrl = API.base.replace('http', 'ws')
|
|
- const time = Math.round(new Date()) + "" + Math.round(Math.random()*100)
|
|
|
|
|
|
+ const time = Math.round(new Date()) + "" + Math.round(Math.random()*100000)
|
|
this.mySocketTask = uni.connectSocket({
|
|
this.mySocketTask = uni.connectSocket({
|
|
- url: wsUrl + '/sleep_report/monitor/' + time + '/' + this.memberId,
|
|
|
|
- // url: 'ws://wdkl.natapp1.cc/sleep_report/monitor/' + this.memberId,
|
|
|
|
|
|
+ // url: wsUrl + '/sleep_report/monitor/' + time + '/' + this.memberId,
|
|
|
|
+ url: wsUrl + '/sleep_report/monitor/' + time ,
|
|
success(res) {
|
|
success(res) {
|
|
// 这里是接口调用成功的回调,不是连接成功的回调,请注意
|
|
// 这里是接口调用成功的回调,不是连接成功的回调,请注意
|
|
},
|
|
},
|
|
@@ -513,7 +520,8 @@ export default {
|
|
_this.pjhx = '--'
|
|
_this.pjhx = '--'
|
|
}
|
|
}
|
|
_this.mySocketTask.send({data: 'ping'})
|
|
_this.mySocketTask.send({data: 'ping'})
|
|
- }, 30000) // 30秒的心跳包
|
|
|
|
|
|
+ }, 60000) // 60秒的心跳包
|
|
|
|
+ this.sendSns()
|
|
})
|
|
})
|
|
this.mySocketTask.onError(err => {
|
|
this.mySocketTask.onError(err => {
|
|
this.connecting = false
|
|
this.connecting = false
|
|
@@ -531,9 +539,11 @@ export default {
|
|
// console.log('收到消息:', msg)
|
|
// console.log('收到消息:', msg)
|
|
switch (msg.length) {
|
|
switch (msg.length) {
|
|
case 1:
|
|
case 1:
|
|
|
|
+ // 判断是否连接
|
|
this.isConnect = true
|
|
this.isConnect = true
|
|
- break
|
|
|
|
|
|
+ break
|
|
case 234:
|
|
case 234:
|
|
|
|
+ // 实时睡眠数据
|
|
if (this.homeFrom.nowDevice !== msg.substring(2, 14)) {
|
|
if (this.homeFrom.nowDevice !== msg.substring(2, 14)) {
|
|
return
|
|
return
|
|
}
|
|
}
|
|
@@ -563,7 +573,7 @@ export default {
|
|
case 13: // REMOVE_DEVICE 有其他人绑定了这台设备
|
|
case 13: // REMOVE_DEVICE 有其他人绑定了这台设备
|
|
_this.API_getDeviceList()
|
|
_this.API_getDeviceList()
|
|
break
|
|
break
|
|
- default:
|
|
|
|
|
|
+ default: // 报警信息
|
|
const data = JSON.parse(res.data)
|
|
const data = JSON.parse(res.data)
|
|
console.log('收到消息为:', data)
|
|
console.log('收到消息为:', data)
|
|
if (data.sn && this.homeFrom.nowDevice === data.sn) {
|
|
if (data.sn && this.homeFrom.nowDevice === data.sn) {
|
|
@@ -575,10 +585,40 @@ export default {
|
|
this.mySocketTask.onClose(res => {
|
|
this.mySocketTask.onClose(res => {
|
|
console.log('webSocket关闭了...')
|
|
console.log('webSocket关闭了...')
|
|
this.connected = false
|
|
this.connected = false
|
|
- this.msg = false
|
|
|
|
|
|
+ this.closed = true
|
|
clearInterval(this.timer)
|
|
clearInterval(this.timer)
|
|
})
|
|
})
|
|
},
|
|
},
|
|
|
|
+ sendSns() {
|
|
|
|
+ if (this.connected) {
|
|
|
|
+ console.log('......................')
|
|
|
|
+ if (this.deviceList.length > 0) {
|
|
|
|
+ let sns = []
|
|
|
|
+ this.deviceList.forEach(item => {
|
|
|
|
+ sns.push(item.imei)
|
|
|
|
+ })
|
|
|
|
+ const data = sns.join(',')
|
|
|
|
+ console.log(data)
|
|
|
|
+ console.log(this.mySns)
|
|
|
|
+ if (!this.mySns) {
|
|
|
|
+ this.mySns = data
|
|
|
|
+ } else {
|
|
|
|
+ if (data === this.mySns && !this.closed) {
|
|
|
|
+ return
|
|
|
|
+ } else {
|
|
|
|
+ this.closed = false
|
|
|
|
+ this.mySns = data
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ console.log('发送imei给服务器...')
|
|
|
|
+ this.mySocketTask.send({data: data})
|
|
|
|
+ } else {
|
|
|
|
+ this.mySns = ''
|
|
|
|
+ this.mySocketTask.send({data: ''})
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ },
|
|
nowChart1() {
|
|
nowChart1() {
|
|
this.onInit1(this.chartObj1)
|
|
this.onInit1(this.chartObj1)
|
|
let canvas = this.$refs.xinlvRefChart.canvas
|
|
let canvas = this.$refs.xinlvRefChart.canvas
|
|
@@ -922,7 +962,7 @@ export default {
|
|
})
|
|
})
|
|
return
|
|
return
|
|
}
|
|
}
|
|
- this.closeWebsocket()
|
|
|
|
|
|
+ // this.closeWebsocket()
|
|
uni.navigateTo({
|
|
uni.navigateTo({
|
|
url: '/pages/user/shareUser/index'
|
|
url: '/pages/user/shareUser/index'
|
|
})
|
|
})
|