sleep.vue 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511
  1. <template>
  2. <view class="container">
  3. <uni-nav-bar fixed :border="false" :backgroundColor="`rgba(255,255,255,${opacity})`" title="睡眠监测" :statusBar="true"
  4. left-icon="left" @clickLeft="back"></uni-nav-bar>
  5. <image class="page-bg" src="@/static/images/pages_watch/images/sleep_top_bg.png" mode="widthFix"></image>
  6. <view class="container-body">
  7. <dateTimePicker @onChange="onChangeTime"/>
  8. <!-- 睡眠情况 -->
  9. <view class="box">
  10. <view class="echartbox-header" v-if="!loading &&sleepValue && sleepValue.length > 0">
  11. <view>{{touchValue.startTime.substring(5,16)}} 至 {{touchValue.endTime.substring(5,16)}}</view>
  12. <view class="echartbox-header-time">
  13. <text>{{touchValue.sleepStateText}}</text>
  14. <text class="echartbox-header-num">{{touchValue.hours}}</text>
  15. <text>小时</text>
  16. <text class="echartbox-header-num">{{touchValue.minutes}}</text>
  17. <text>分钟</text>
  18. <!-- <image src="@/static/images/pages_watch/icons/prompt_icon.png"></image> -->
  19. </view>
  20. </view>
  21. <view class="echartbox">
  22. <template v-if="!loading && sleepValue && sleepValue.length > 0">
  23. <view style="min-height: 446rpx;">
  24. <sleepCharts ref="sleepCharts" :type="2" :sleepData="sleepData" :sleepValue="sleepValue" @handleItem="handleItem" />
  25. </view>
  26. <view class="legend border-line" v-show="!loading">
  27. <view class="legend-item">
  28. <view class="legend-dot" style="background-color: #8C37E6;"></view><text>深睡</text>
  29. </view>
  30. <view class="legend-item">
  31. <view class="legend-dot" style="background-color: #D138CF;"></view><text>浅睡</text>
  32. </view>
  33. <view class="legend-item">
  34. <view class="legend-dot" style="background-color: #F88082;"></view><text>快速眼动</text>
  35. </view>
  36. <view class="legend-item">
  37. <view class="legend-dot" style="background-color: #FDBD27;"></view><text>清醒</text>
  38. </view>
  39. </view>
  40. </template>
  41. <template v-else>
  42. <myEmpty />
  43. </template>
  44. </view>
  45. <view class="pie-echartbox" v-if="!loading && sleepValue && sleepValue.length > 0">
  46. <myRing class="myRing" ref="myRing" :info="ringData"/>
  47. <view class="ring-info">
  48. <view class="ring-infoitem">
  49. <view class="ring-infoitem-type type1">深睡</view>
  50. <view>{{convertMinutes(sleepData.deepSleep || 0)}}</view>
  51. </view>
  52. <view class="ring-infoitem">
  53. <view class="ring-infoitem-type type2">浅睡</view>
  54. <view>{{convertMinutes(sleepData.lightSleep || 0)}}</view>
  55. </view>
  56. <view class="ring-infoitem">
  57. <view class="ring-infoitem-type type3">快速眼动</view>
  58. <view>{{convertMinutes(sleepData.eyemoveSleep || 0)}}</view>
  59. </view>
  60. <view class="ring-infoitem">
  61. <view class="ring-infoitem-type type4">清醒</view>
  62. <view>{{convertMinutes(sleepData.weakSleep || 0)}}</view>
  63. </view>
  64. </view>
  65. </view>
  66. <view class="sleep-list">
  67. <view class="sleep-list-item">
  68. <view class="sleep-list-iteml">
  69. <view class="sleep-list-itemtitle">清醒次数 {{sleepData.weakTime || 0}} 次</view>
  70. <view>参考值:0-1 次</view>
  71. </view>
  72. <view class="sleep-list-itemr">
  73. <view :class="['sleep-list-tag',_interval(sleepData.weakTime,0,1)[1]]">
  74. {{_interval(sleepData.weakTime,0,1)[0]}}
  75. </view>
  76. <image src="@/static/images/pages_watch/icons/my_right_arrow_right_icon.png"></image>
  77. </view>
  78. </view>
  79. <view class="sleep-list-item">
  80. <view class="sleep-list-iteml">
  81. <view class="sleep-list-itemtitle">
  82. 夜间睡眠 {{convertMinutes(sleepData.sleepTime || 0)}}
  83. </view>
  84. <view>参考值:6-10 小时</view>
  85. </view>
  86. <view class="sleep-list-itemr">
  87. <view :class="['sleep-list-tag',_interval(sleepData.sleepTime,360,600)[1]]">
  88. {{_interval(sleepData.sleepTime,360,600)[0]}}
  89. </view>
  90. <image src="@/static/images/pages_watch/icons/my_right_arrow_right_icon.png"></image>
  91. </view>
  92. </view>
  93. <view class="sleep-list-item">
  94. <view class="sleep-list-iteml">
  95. <view class="sleep-list-itemtitle">深睡连续性 {{sleepData.deepScore || 0}} 分</view>
  96. <view>参考值:70-100 分</view>
  97. </view>
  98. <view class="sleep-list-itemr">
  99. <view :class="['sleep-list-tag',_interval(sleepData.deepScore,70,100)[1]]">
  100. {{_interval(sleepData.deepScore,70,100)[0]}}
  101. </view>
  102. <image src="@/static/images/pages_watch/icons/my_right_arrow_right_icon.png"></image>
  103. </view>
  104. </view>
  105. <view class="sleep-list-item">
  106. <view class="sleep-list-iteml">
  107. <view class="sleep-list-itemtitle">深睡比例 {{sleepData.deepScale || 0}}%</view>
  108. <view>参考值:20-60%</view>
  109. </view>
  110. <view class="sleep-list-itemr">
  111. <view :class="['sleep-list-tag',_interval(sleepData.deepScale,20,60)[1]]">
  112. {{_interval(sleepData.deepScale,20,60)[0]}}
  113. </view>
  114. <image src="@/static/images/pages_watch/icons/my_right_arrow_right_icon.png"></image>
  115. </view>
  116. </view>
  117. <view class="sleep-list-item">
  118. <view class="sleep-list-iteml">
  119. <view class="sleep-list-itemtitle">浅睡比例 {{sleepData.lightScale || 0}}%</view>
  120. <!-- 小于55% ,&lt;微信开发者工具报错-->
  121. <view>参考值:{{'<'}}55% </view>
  122. </view>
  123. <view class="sleep-list-itemr">
  124. <view :class="['sleep-list-tag',_lightInterval(sleepData.lightScale,55)[1]]">
  125. {{_lightInterval(sleepData.lightScale,55)[0]}}
  126. </view>
  127. <image src="@/static/images/pages_watch/icons/my_right_arrow_right_icon.png"></image>
  128. </view>
  129. </view>
  130. <view class="sleep-list-item">
  131. <view class="sleep-list-iteml">
  132. <view class="sleep-list-itemtitle">快速眼动比例 {{sleepData.eyemoveScale || 0}}%</view>
  133. <view>参考值:10-30%</view>
  134. </view>
  135. <view class="sleep-list-itemr">
  136. <view :class="['sleep-list-tag',_interval(sleepData.eyemoveScale,10,30)[1]]">
  137. {{_interval(sleepData.eyemoveScale,10,30)[0]}}
  138. </view>
  139. <image src="@/static/images/pages_watch/icons/my_right_arrow_right_icon.png"></image>
  140. </view>
  141. </view>
  142. <view class="sleep-list-item">
  143. <view class="sleep-list-iteml">
  144. <view class="sleep-list-itemtitle">呼吸质量 {{sleepData.breathScore || 0}}分</view>
  145. <view>参考值:70-100 分</view>
  146. </view>
  147. <view class="sleep-list-itemr">
  148. <view :class="['sleep-list-tag',_interval(sleepData.breathScore,70,100)[1]]">
  149. {{_interval(sleepData.breathScore,70,100)[0]}}
  150. </view>
  151. <image src="@/static/images/pages_watch/icons/my_right_arrow_right_icon.png"></image>
  152. </view>
  153. </view>
  154. </view>
  155. </view>
  156. </view>
  157. </view>
  158. </template>
  159. <script>
  160. import {sleepInfo} from "@/api/pages_watch/healthMonitoring.js"
  161. import myEmpty from "@/pages_watch/components/myEmpty/myEmpty.vue"
  162. import dateTimePicker from "@/pages_watch/components/dateTimePicker/dateTimePicker.vue"
  163. import sleepCharts from "@/pages_watch/components/sleepCharts/sleepCharts.vue"
  164. import myRing from "@/pages_watch/components/myRing/myRing.vue"
  165. export default {
  166. components: {
  167. myEmpty,
  168. dateTimePicker,
  169. sleepCharts,
  170. myRing
  171. },
  172. data() {
  173. return {
  174. opacity: 0,
  175. sleepData: {},
  176. ringData: {},
  177. loading: false,
  178. touchValue: {
  179. startTime: "",
  180. endTime: "",
  181. type: "",
  182. sleepStateText: "",
  183. hours: "",
  184. minutes: ""
  185. },
  186. sleepValue:[]
  187. }
  188. },
  189. computed: {
  190. _interval() {
  191. return (val, min, max)=>{
  192. const Num = Number(val || 0)
  193. if(val >= min && val <= max) {
  194. return ['正常','green']
  195. } else if(0 <= val && val < min) {
  196. return ['偏低','blue']
  197. } else if(val > max) {
  198. return ['偏高','red']
  199. } else {
  200. return ['','']
  201. }
  202. }
  203. },
  204. _lightInterval() {
  205. return (val, interval)=>{
  206. const Num = Number(val || 0)
  207. if(val > interval) {
  208. return ['异常','red']
  209. } else if(0 <= val && val < interval) {
  210. return ['正常','green']
  211. } else {
  212. return ['','']
  213. }
  214. }
  215. },
  216. },
  217. methods: {
  218. back() {
  219. uni.navigateBack({
  220. delta: 1
  221. })
  222. },
  223. handleItem(item,type) {
  224. if(type=='init'){
  225. this.touchValue = item
  226. } else {
  227. let diff = Math.abs(new Date(item.startTime).getTime() - new Date(item.endTime).getTime());
  228. this.touchValue = {
  229. ...item,
  230. hours: Math.floor(diff / (1000 * 60 * 60)),
  231. minutes: Math.floor((diff % (1000 * 60 * 60)) / (1000 * 60))
  232. }
  233. }
  234. },
  235. // 分钟转换成小时分,type: 默认不传带文字,2,返回时分数字
  236. convertMinutes(val,type) {
  237. if (val) {
  238. const seconds = val * 60
  239. const hours = Math.floor(seconds / 3600); // 3600秒等于1小时
  240. const minutes = Math.floor((seconds % 3600) / 60); // 余数部分除以60秒得到分钟数
  241. const hoursTxt = hours > 0 ? `${hours} 小时` : ''
  242. const minutesTxt = minutes > 0 ? `${minutes} 分钟` : ''
  243. if(type == 2) {
  244. return [hours,minutes]
  245. } else {
  246. return `${hoursTxt} ${minutesTxt}`
  247. }
  248. } else {
  249. if(type == 2) {
  250. return [0,0]
  251. } else {
  252. return "--小时--分钟"
  253. }
  254. }
  255. },
  256. onChangeTime(time) {
  257. const param = {
  258. startTime: this.$timeFormat(time[0],'yyyy/mm/dd hh:MM:ss'),
  259. endTime: this.$timeFormat(time[1],'yyyy/mm/dd hh:MM:ss'),
  260. deviceId: uni.getStorageSync("deviceId") || ""
  261. }
  262. this.getServerData(param)
  263. },
  264. getServerData(param) {
  265. this.loading = true
  266. uni.showLoading({
  267. title: '加载中'
  268. })
  269. sleepInfo(param).then((res) => {
  270. this.loading = false
  271. uni.hideLoading();
  272. if (res.code == 200 && res.data) {
  273. this.sleepData = res.data
  274. this.sleepValue = res.data.sleepSection
  275. this.ringData = {
  276. deepPre: res.data.deepSleep,
  277. lightPre: res.data.lightSleep,
  278. eyemovePre: res.data.eyemoveSleep,
  279. weakPre: res.data.weakSleep,
  280. }
  281. this.$nextTick(()=>{
  282. if(this.sleepValue && this.sleepValue.length > 0) {
  283. this.$refs.sleepCharts.initData()
  284. this.$refs.myRing.initData(this.ringData)
  285. }
  286. })
  287. }
  288. }).catch((err) => {
  289. this.loading = false
  290. uni.hideLoading();
  291. });
  292. },
  293. },
  294. onPageScroll(e) {
  295. if (e.scrollTop <= 44) {
  296. this.opacity = e.scrollTop / 44 * 1
  297. } else if (e.scrollTop > 44) {
  298. this.opacity = 1
  299. }
  300. }
  301. }
  302. </script>
  303. <style lang="scss" scoped>
  304. @mixin u-flex($flexD, $alignI, $justifyC) {
  305. display: flex;
  306. flex-direction: $flexD;
  307. align-items: $alignI;
  308. justify-content: $justifyC;
  309. }
  310. .container {
  311. // padding: 0 24rpx;
  312. position: relative;
  313. }
  314. .page-bg {
  315. width: 100%;
  316. height: auto;
  317. position: absolute;
  318. top: 0;
  319. left: 0;
  320. }
  321. .container-body {
  322. position: relative;
  323. z-index: 1;
  324. padding: 0 24rpx
  325. }
  326. .box {
  327. padding: 24rpx;
  328. margin-bottom: 20rpx;
  329. box-sizing: border-box;
  330. background: #FFFFFF;
  331. border-radius: 16rpx 16rpx 16rpx 16rpx;
  332. position: relative;
  333. }
  334. .echartbox {
  335. // height: 694rpx;
  336. width: 100%;
  337. overflow: hidden;
  338. &-header {
  339. font-family: PingFang SC, PingFang SC;
  340. font-weight: 400;
  341. font-size: 24rpx;
  342. color: #757575;
  343. text-align: center;
  344. &-time {
  345. font-weight: 400;
  346. font-size: 28rpx;
  347. color: #333333;
  348. }
  349. &-num {
  350. margin: 0 8rpx;
  351. font-family: DIN, DIN;
  352. font-weight: 500;
  353. font-size: 56rpx;
  354. color: #333333;
  355. }
  356. image {
  357. width: 32rpx;
  358. height: 32rpx;
  359. margin-left: 4rpx;
  360. }
  361. }
  362. }
  363. .legend {
  364. padding: 46rpx 0;
  365. box-sizing: border-box;
  366. @include u-flex(row, center, space-between);
  367. font-family: PingFang SC, PingFang SC;
  368. font-weight: 400;
  369. font-size: 24rpx;
  370. color: #757575;
  371. &-item {
  372. flex: 1;
  373. text-align: center;
  374. @include u-flex(row, center, center);
  375. }
  376. &-dot {
  377. width: 12rpx;
  378. height: 12rpx;
  379. border-radius: 50%;
  380. margin: 12rpx;
  381. }
  382. }
  383. .pie-echartbox {
  384. height: 302rpx;
  385. width: 100%;
  386. box-sizing: border-box;
  387. @include u-flex(row, center, space-between);
  388. .myRing {
  389. flex-shrink: 0;
  390. }
  391. .ring-info {
  392. flex: 1;
  393. margin-left: 60rpx;
  394. @include u-flex(column, flex-start, flex-start);
  395. // gap: 20rpx;
  396. margin-bottom: -20rpx;
  397. .ring-infoitem {
  398. width: 100%;
  399. margin-bottom: 20rpx;
  400. @include u-flex(row, center, space-between);
  401. font-family: PingFang SC, PingFang SC;
  402. font-weight: 400;
  403. font-size: 24rpx;
  404. color: #333333;
  405. &-type {
  406. width: 96rpx;
  407. flex-shrink: 0;
  408. padding-left: 20rpx;
  409. box-sizing: border-box;
  410. position: relative;
  411. &::after {
  412. position: absolute;
  413. left: 0;
  414. top: 50%;
  415. transform: translateY(-50%);
  416. content: "";
  417. width: 12rpx;
  418. height: 12rpx;
  419. border-radius: 50%;
  420. }
  421. }
  422. .type1::after {
  423. background: #8C37E6;
  424. }
  425. .type2::after {
  426. background: #D138CF;
  427. }
  428. .type3::after {
  429. background:#F88082;
  430. }
  431. .type4::after {
  432. background: #FDBD27;
  433. }
  434. view {
  435. flex: 1;
  436. }
  437. }
  438. }
  439. }
  440. .sleep-list {
  441. font-family: PingFang SC, PingFang SC;
  442. font-weight: 400;
  443. font-size: 24rpx;
  444. color: #757575;
  445. &-item {
  446. width: 100%;
  447. margin-bottom: 16rpx;
  448. padding: 16rpx 24rpx 20rpx 24rpx;
  449. box-sizing: border-box;
  450. background: #F5F7FA;
  451. border-radius: 16rpx 16rpx 16rpx 16rpx;
  452. border: 2rpx solid #F5F7FA;
  453. @include u-flex(row, center, space-between);
  454. }
  455. &-itemtitle {
  456. font-weight: 500;
  457. font-size: 28rpx;
  458. color: #333333;
  459. margin-bottom: 10rpx;
  460. }
  461. &-itemr {
  462. flex-shrink: 0;
  463. @include u-flex(row, center, flex-start);
  464. image {
  465. height: 48rpx;
  466. width: 48rpx;
  467. }
  468. }
  469. &-tag {
  470. width: 96rpx;
  471. height: 50rpx;
  472. border-radius: 26rpx 26rpx 26rpx 26rpx;
  473. color: #FFFFFF;
  474. line-height: 50rpx;
  475. text-align: center;
  476. }
  477. .red {
  478. background: #FF5558;
  479. }
  480. .blue {
  481. background: #96CBFA;
  482. }
  483. .green {
  484. background: #52D087;
  485. }
  486. }
  487. </style>