|
@@ -104,27 +104,27 @@
|
|
|
<!-- home device -->
|
|
|
<view class="flex-col home-device space-y-15">
|
|
|
<view class="flex-row home-device-header">
|
|
|
-<!-- <view class="flex-row justify-between flex-auto equal-division">-->
|
|
|
-<!-- <view class="flex-row equal-division-item space-x-4">-->
|
|
|
-<!-- <text class="font_3 text_5">场景</text>-->
|
|
|
-<!-- <text class="font_3">老人房</text>-->
|
|
|
-<!-- </view>-->
|
|
|
-<!-- <view class="flex-row equal-division-item space-x-14">-->
|
|
|
-<!-- <view class="flex-row space-x-4">-->
|
|
|
-<!-- <image class="shrink-0 image_6" src="../../static/home/homeIconWifi.png" />-->
|
|
|
-<!-- <text class="font_3">在线</text>-->
|
|
|
-<!-- </view>-->
|
|
|
+ <view class="flex-row justify-between flex-auto equal-division">
|
|
|
+ <view class="flex-row equal-division-item space-x-4">
|
|
|
+ <text class="font_3 text_5">当前设备</text>
|
|
|
+ <text class="font_3">{{ homeFrom.nowDevice }}</text>
|
|
|
+ </view>
|
|
|
+ <view class="flex-row equal-division-item space-x-14">
|
|
|
+ <view class="flex-row space-x-4 margin-left-xl">
|
|
|
+ <image class="shrink-0 image_6" src="../../static/home/homeIconWifi.png" />
|
|
|
+ <text class="font_3">{{ homeFrom.status }}</text>
|
|
|
+ </view>
|
|
|
<!-- <view class="flex-row items-center space-x-6">-->
|
|
|
<!-- <text class="font_3 text_6">45%</text>-->
|
|
|
<!-- <image class="shrink-0 image_7" src="../../static/home/homeIconPower.png" />-->
|
|
|
<!-- </view>-->
|
|
|
-<!-- </view>-->
|
|
|
-<!-- </view>-->
|
|
|
+ </view>
|
|
|
+ </view>
|
|
|
|
|
|
-<!-- <view class="flex-row items-center section_5 space-x-4">-->
|
|
|
-<!-- <image class="shrink-0 image_8" src="../../static/home/homeIconChange.png"/>-->
|
|
|
-<!-- <text class="font_3">切换</text>-->
|
|
|
-<!-- </view>-->
|
|
|
+ <view class="flex-row items-center section_5 space-x-4">
|
|
|
+ <image class="shrink-0 image_8" src="../../static/home/homeIconChange.png"/>
|
|
|
+ <text class="font_3">切换</text>
|
|
|
+ </view>
|
|
|
</view>
|
|
|
|
|
|
<view class="flex-row justify-center self-center home-device-status space-x-8">
|
|
@@ -132,17 +132,17 @@
|
|
|
<text class="font_4">{{ sleepStatus }}</text>
|
|
|
</view>
|
|
|
|
|
|
- <view>
|
|
|
- <uni-steps :options="list1" :active="active" />
|
|
|
- </view>
|
|
|
+<!-- <view>-->
|
|
|
+<!-- <uni-steps :options="list1" :active="active" />-->
|
|
|
+<!-- </view>-->
|
|
|
|
|
|
- <view class="flex-row self-center items-center home-device-setting">
|
|
|
- <image
|
|
|
- class="shrink-0 image_8"
|
|
|
- src="../../static/home/homeIconSet.png"
|
|
|
- />
|
|
|
- <text>设置目标</text>
|
|
|
- </view>
|
|
|
+<!-- <view class="flex-row self-center items-center home-device-setting">-->
|
|
|
+<!-- <image-->
|
|
|
+<!-- class="shrink-0 image_8"-->
|
|
|
+<!-- src="../../static/home/homeIconSet.png"-->
|
|
|
+<!-- />-->
|
|
|
+<!-- <text>设置目标</text>-->
|
|
|
+<!-- </view>-->
|
|
|
</view>
|
|
|
|
|
|
<view class="home-report flex-col group_5 space-y-40">
|
|
@@ -221,28 +221,36 @@
|
|
|
</view>
|
|
|
|
|
|
<view class="flex-col home-alert space-y-4">
|
|
|
- <view @click="jumpToAlertSetting" class="flex-row items-center space-x-4 home-alert-header">
|
|
|
+ <view class="flex-row items-center space-x-4 home-alert-header">
|
|
|
<image
|
|
|
class="image_10"
|
|
|
src="../../static/home/homeIconHeart.png"
|
|
|
/>
|
|
|
<text class="font_1">实时预警</text>
|
|
|
</view>
|
|
|
-
|
|
|
- <view @click="handleAlertSetting" class="flex-col home-alert-list">
|
|
|
+ <view v-if="list_alerts.length === 0" @click="handleAlertSetting" class="flex-row items-center home_blank_alert space-x-16">
|
|
|
+ <image
|
|
|
+ class="image_8"
|
|
|
+ src="../../static/home/homeIconGift.png"
|
|
|
+ />
|
|
|
+ <view class="flex-col items-start flex-auto space-y-4">
|
|
|
+ <text class="font_5">昨晚您的睡眠质量很好</text>
|
|
|
+ <text class="font_5">暂时没有预警信息</text>
|
|
|
+ </view>
|
|
|
+ </view>
|
|
|
+ <view v-else @click="handleAlertSetting" class="flex-col home-alert-list">
|
|
|
<view class="flex-row justify-between items-center list-item" :key="i" v-for="(item, i) in list_alerts">
|
|
|
<view class="flex-row items-center space-x-6">
|
|
|
<image
|
|
|
class="shrink-0 image_11"
|
|
|
src="../../static/home/homeIconAlert.png"
|
|
|
/>
|
|
|
- <text class="font_8">心率警报</text>
|
|
|
- <text class="font_9 text_16">2:25</text>
|
|
|
+ <text class="font_8">{{ formatSosType(item.warn_type) }}</text>
|
|
|
+ <text class="font_9 text_16">{{ formatSosTime(item.warn_time) }}</text>
|
|
|
</view>
|
|
|
|
|
|
<view class="flex-row items-baseline space-x-4">
|
|
|
- <text class="font_10">102</text>
|
|
|
- <text class="font_8">次/分</text>
|
|
|
+ <text class="font_10">{{ item.warn_desc }}</text>
|
|
|
</view>
|
|
|
</view>
|
|
|
</view>
|
|
@@ -258,14 +266,17 @@
|
|
|
<script>
|
|
|
import echarts from '@/static/echarts.min.js'
|
|
|
import mpvueEcharts from '@/components/mpvue-echarts/src/echarts.vue'
|
|
|
+
|
|
|
+import Storage from '@/utils/storage'
|
|
|
+import * as API_deviceMemberBind from '@/api/device_member_bind'
|
|
|
export default {
|
|
|
components: {
|
|
|
mpvueEcharts
|
|
|
},
|
|
|
data() {
|
|
|
return {
|
|
|
- deviceAdded: true,
|
|
|
- list_alerts: [null, null],
|
|
|
+ deviceAdded: false,
|
|
|
+ list_alerts: [],
|
|
|
active: 4,
|
|
|
list1: [{
|
|
|
title: '昨日就寝 11:24PM'
|
|
@@ -289,21 +300,48 @@ export default {
|
|
|
sleepStatus: '离床',
|
|
|
connecting: false,
|
|
|
connected: false,
|
|
|
- mySocketTask: null
|
|
|
+ mySocketTask: null,
|
|
|
+ homeFrom: {
|
|
|
+ nowDevice: '', // 当前设备
|
|
|
+ status: '离线'
|
|
|
+ },
|
|
|
+ deviceList: [], // 设备列表
|
|
|
+ lastMsgTime: 0, // 最后一次设备消息时间
|
|
|
+ memberId: 50289 // 先写死
|
|
|
};
|
|
|
},
|
|
|
- created() {
|
|
|
-
|
|
|
- },
|
|
|
onLoad() {
|
|
|
- const _this = this
|
|
|
- setTimeout(() => {
|
|
|
- _this.nowChart1()
|
|
|
- _this.nowChart2()
|
|
|
- _this.connect()
|
|
|
- }, 800)
|
|
|
+ this.API_getDeviceList()
|
|
|
+ },
|
|
|
+ onUnload() {
|
|
|
+ this.mySocketTask.onClose(res => {
|
|
|
+ this.connected = false
|
|
|
+ clearInterval(this.timer)
|
|
|
+ })
|
|
|
},
|
|
|
methods: {
|
|
|
+ API_getDeviceList() {
|
|
|
+ const _this = this
|
|
|
+ API_deviceMemberBind.getDeviceByDtypeAndMemberId({dtype: '睡眠床垫', memberId: this.memberId}).then(res => {
|
|
|
+ if (res.length === 0) {
|
|
|
+ _this.deviceAdded = false
|
|
|
+ } else {
|
|
|
+ _this.deviceAdded = true
|
|
|
+ _this.deviceList = res
|
|
|
+ _this.homeFrom.nowDevice = res[0].imei
|
|
|
+ Storage.setItem("nowChangeDevice", _this.homeFrom.nowDevice)
|
|
|
+ _this.init()
|
|
|
+ }
|
|
|
+ })
|
|
|
+ },
|
|
|
+ init() {
|
|
|
+ const _this = this
|
|
|
+ setTimeout(() => {
|
|
|
+ _this.nowChart1()
|
|
|
+ _this.nowChart2()
|
|
|
+ _this.connect()
|
|
|
+ }, 800)
|
|
|
+ },
|
|
|
connect() {
|
|
|
let _this = this
|
|
|
if (this.connected || this.connecting) {
|
|
@@ -316,7 +354,7 @@ export default {
|
|
|
this.connecting = true
|
|
|
// let wsUrl = api.base.replace('http', 'ws')
|
|
|
this.mySocketTask = uni.connectSocket({
|
|
|
- url: 'ws://wdkl.natapp1.cc/sleep_report/monitor/50289', // 先写死
|
|
|
+ url: 'ws://wdkl.natapp1.cc/sleep_report/monitor/' + this.memberId,
|
|
|
success(res) {
|
|
|
// 这里是接口调用成功的回调,不是连接成功的回调,请注意
|
|
|
},
|
|
@@ -330,6 +368,12 @@ export default {
|
|
|
uni.hideLoading()
|
|
|
let _this = this
|
|
|
this.timer = setInterval(function () { //每隔5秒钟发送一次心跳,避免websocket连接因超时而自动断开
|
|
|
+ if (Date.parse(new Date()) - _this.lastMsgTime > 5000) { // 5秒没有收到新消息,则判断为离线
|
|
|
+ _this.homeFrom.status = '离线'
|
|
|
+ _this.sleepStatus = '离线'
|
|
|
+ _this.pjxl = '-'
|
|
|
+ _this.pjhx = '-'
|
|
|
+ }
|
|
|
_this.mySocketTask.send({data: 'ping'})
|
|
|
}, 30000) // 30秒的心跳包
|
|
|
})
|
|
@@ -345,8 +389,13 @@ export default {
|
|
|
})
|
|
|
this.mySocketTask.onMessage(res => {
|
|
|
let msg = res.data
|
|
|
- console.log('收到消息:', msg)
|
|
|
+ // console.log('收到消息:', msg)
|
|
|
if (msg.length === 30) {
|
|
|
+ if (this.homeFrom.nowDevice !== msg.substring(2, 14)) {
|
|
|
+ return
|
|
|
+ }
|
|
|
+ this.homeFrom.status = '在线'
|
|
|
+ this.lastMsgTime = Date.parse(new Date())
|
|
|
this.getValue1(parseInt(msg.substring(22, 24), 16))
|
|
|
this.getValue2(parseInt(msg.substring(24, 26), 16))
|
|
|
switch (msg.substring(26, 28)) {
|
|
@@ -365,6 +414,12 @@ export default {
|
|
|
default:
|
|
|
break;
|
|
|
}
|
|
|
+ } else {
|
|
|
+ const data = JSON.parse(res.data)
|
|
|
+ console.log('收到消息为:', data)
|
|
|
+ if (data.sn && this.homeFrom.nowDevice === data.sn) {
|
|
|
+ this.list_alerts.push(data)
|
|
|
+ }
|
|
|
}
|
|
|
})
|
|
|
this.mySocketTask.onClose(res => {
|
|
@@ -470,7 +525,7 @@ export default {
|
|
|
}
|
|
|
},
|
|
|
getValue1(value) {
|
|
|
- console.log("心率是", value)
|
|
|
+ // console.log("心率是", value)
|
|
|
this.pjxl = value
|
|
|
if (this.myData1.length > 60) {
|
|
|
this.myData1.splice(0,5)
|
|
@@ -484,7 +539,7 @@ export default {
|
|
|
} else {
|
|
|
for (let i = 0; i < 5; i++) {
|
|
|
this.myCount1 ++;
|
|
|
- value = 410
|
|
|
+ value = 410 + parseInt(Math.random() * 10 - 5)
|
|
|
this.myData1.push([this.myCount1, value])
|
|
|
}
|
|
|
}
|
|
@@ -492,7 +547,7 @@ export default {
|
|
|
this.myChart1.setOption(this.options1)
|
|
|
},
|
|
|
getValue2(value) {
|
|
|
- console.log("呼吸值是", value)
|
|
|
+ // console.log("呼吸值是", value)
|
|
|
this.pjhx = value
|
|
|
if (this.myData2.length > 60) {
|
|
|
this.myData2.splice(0,5)
|
|
@@ -500,7 +555,7 @@ export default {
|
|
|
if (value === 0) {
|
|
|
for (let i = 0; i < 5; i++) {
|
|
|
this.myCount2 ++;
|
|
|
- value = 220
|
|
|
+ value = 220 + parseInt(Math.random() * 10 - 5)
|
|
|
this.myData2.push([this.myCount2, value])
|
|
|
}
|
|
|
} else {
|
|
@@ -516,9 +571,32 @@ export default {
|
|
|
},
|
|
|
handleAlertSetting() {
|
|
|
uni.navigateTo({
|
|
|
- url: "/pages/alertSetting/alertSetting"
|
|
|
+ url: "/pages/alertSetting/alertSetting?imei=" + this.homeFrom.nowDevice
|
|
|
});
|
|
|
- }
|
|
|
+ },
|
|
|
+ formatSosType(value) {
|
|
|
+ switch (value) {
|
|
|
+ case 1:
|
|
|
+ return '心率过速'
|
|
|
+ case 2:
|
|
|
+ return '心率过缓'
|
|
|
+ case 3:
|
|
|
+ return '呼吸过速'
|
|
|
+ case 4:
|
|
|
+ return '呼吸过缓'
|
|
|
+ case 5:
|
|
|
+ return '离床预警'
|
|
|
+ case 6:
|
|
|
+ return '一键预警'
|
|
|
+ case 7:
|
|
|
+ return '离线预警'
|
|
|
+ default:
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ },
|
|
|
+ formatSosTime(value) {
|
|
|
+ return value.substring(10, value.length - 3)
|
|
|
+ }
|
|
|
}
|
|
|
};
|
|
|
</script>
|
|
@@ -1039,7 +1117,7 @@ export default {
|
|
|
font-size: 0.88rem;
|
|
|
font-family: PingFangSC;
|
|
|
line-height: 0.69rem;
|
|
|
- color: #167df2;
|
|
|
+ color: #ced5dc;
|
|
|
}
|
|
|
.text_16 {
|
|
|
line-height: 0.63rem;
|