sleep.vue 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202
  1. <template>
  2. <view class="bobox" :style="boxstyle">
  3. <view class="box-title">
  4. <view class="box-title-left">睡眠趋势</view>
  5. </view>
  6. <view class="loading" v-show="loading"><sleepLoading /></view>
  7. <view class="echartbox-header" v-if="this.sleepValue && this.sleepValue.length > 0">
  8. <view>{{touchValue.startTime.substring(5,16)}} 至 {{touchValue.endTime.substring(5,16)}}</view>
  9. <view class="echartbox-header-time">
  10. <text>{{touchValue.sleepStateText}}</text>
  11. <text class="echartbox-header-num">{{touchValue.hours}}</text>
  12. <text>小时</text>
  13. <text class="echartbox-header-num">{{touchValue.minutes}}</text>
  14. <text>分钟</text>
  15. <image src="@/static/images/pages_watch/icons/prompt_icon.png"></image>
  16. </view>
  17. </view>
  18. <view class="echartbox">
  19. <template v-if="this.sleepValue && this.sleepValue.length > 0">
  20. <view style="min-height: 446rpx;">
  21. <sleepCharts ref="sleepCharts" :type="2" :sleepValue="sleepValue" @handleItem="handleItem" />
  22. </view>
  23. <view class="legend border-line" v-show="!loading">
  24. <view class="legend-item">
  25. <view class="legend-dot" style="background-color: #8C37E6;"></view><text>深睡</text>
  26. </view>
  27. <view class="legend-item">
  28. <view class="legend-dot" style="background-color: #D138CF;"></view><text>浅睡</text>
  29. </view>
  30. <view class="legend-item">
  31. <view class="legend-dot" style="background-color: #F88082;"></view><text>快速眼动</text>
  32. </view>
  33. <view class="legend-item">
  34. <view class="legend-dot" style="background-color: #FDBD27;"></view><text>清醒</text>
  35. </view>
  36. </view>
  37. </template>
  38. <template v-else>
  39. <myEmpty />
  40. </template>
  41. </view>
  42. </view>
  43. </template>
  44. <script>
  45. import sleepLoading from "@/pages_watch/components/sleepCharts/sleepLoading.vue"
  46. import sleepCharts from "@/pages_watch/components/sleepCharts/sleepCharts.vue";
  47. import myEmpty from "@/pages_watch/components/myEmpty/myEmpty.vue";
  48. export default {
  49. name: "sleep",
  50. props: {
  51. loading: {
  52. type: Boolean,
  53. default: false
  54. },
  55. boxstyle: {
  56. type: Object,
  57. default: () => {}
  58. }
  59. },
  60. components: {
  61. sleepCharts,
  62. myEmpty,
  63. sleepLoading
  64. },
  65. data() {
  66. return {
  67. sleepData: {},
  68. touchValue: {
  69. startTime: "",
  70. endTime: "",
  71. type: "",
  72. sleepStateText: "",
  73. hours: "",
  74. minutes: ""
  75. },
  76. sleepValue:[]
  77. }
  78. },
  79. methods: {
  80. setChartData(data) {
  81. this.sleepValue = data.sleepSection || []
  82. if(this.sleepValue && this.sleepValue.length > 0) {
  83. this.$nextTick(()=>{
  84. this.$refs.sleepCharts.initData()
  85. })
  86. }
  87. },
  88. handleItem(item) {
  89. let diff = Math.abs(new Date(item.startTime).getTime() - new Date(item.endTime).getTime());
  90. this.touchValue = {
  91. ...item,
  92. hours: Math.floor(diff / (1000 * 60 * 60)),
  93. minutes: Math.floor((diff % (1000 * 60 * 60)) / (1000 * 60))
  94. }
  95. },
  96. }
  97. }
  98. </script>
  99. <style lang="scss" scoped>
  100. @mixin u-flex($flexD, $alignI, $justifyC) {
  101. display: flex;
  102. flex-direction: $flexD;
  103. align-items: $alignI;
  104. justify-content: $justifyC;
  105. }
  106. .loading {
  107. height: 90%;
  108. width: 100%;
  109. display: flex;
  110. align-items: center;
  111. justify-content: center;
  112. position: absolute;
  113. top: 42rpx;
  114. left: 0;
  115. background-color: #fff;
  116. z-index: 99;
  117. }
  118. .bobox {
  119. background: #fff;
  120. position: relative;
  121. }
  122. .box-title {
  123. font-family: PingFang SC, PingFang SC;
  124. font-weight: 400;
  125. font-size: 24rpx;
  126. color: #757575;
  127. @include u-flex(row, center, space-between);
  128. &-left {
  129. font-weight: 500;
  130. font-size: 36rpx;
  131. color: #222222;
  132. line-height: 42rpx;
  133. }
  134. &-right {
  135. @include u-flex(row, center, flex-start);
  136. image {
  137. height: 48rpx;
  138. width: 48rpx;
  139. }
  140. }
  141. }
  142. .echartbox {
  143. // height: 694rpx;
  144. width: 100%;
  145. overflow: hidden;
  146. &-header {
  147. font-family: PingFang SC, PingFang SC;
  148. font-weight: 400;
  149. font-size: 24rpx;
  150. color: #757575;
  151. text-align: center;
  152. &-time {
  153. font-weight: 400;
  154. font-size: 28rpx;
  155. color: #333333;
  156. }
  157. &-num {
  158. margin: 0 8rpx;
  159. font-family: DIN, DIN;
  160. font-weight: 500;
  161. font-size: 56rpx;
  162. color: #333333;
  163. }
  164. image {
  165. width: 32rpx;
  166. height: 32rpx;
  167. margin-left: 4rpx;
  168. }
  169. }
  170. }
  171. .legend {
  172. padding: 46rpx 0;
  173. box-sizing: border-box;
  174. @include u-flex(row, center, space-between);
  175. font-family: PingFang SC, PingFang SC;
  176. font-weight: 400;
  177. font-size: 24rpx;
  178. color: #757575;
  179. &-item {
  180. flex: 1;
  181. text-align: center;
  182. @include u-flex(row, center, center);
  183. }
  184. &-dot {
  185. width: 12rpx;
  186. height: 12rpx;
  187. border-radius: 50%;
  188. margin: 12rpx;
  189. }
  190. }
  191. </style>