todaydata-box.vue 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334
  1. <template>
  2. <!-- 今日记录模块 -->
  3. <view class="module-container">
  4. <u-tabs :list="list" :current="current" @change="changeModule"
  5. :activeStyle="{color: '#5b7cff',fontWeight: 'bold',transform: 'scale(1.04)',}"
  6. :inactiveStyle="{fontWeight: 'bold',transform: 'scale(1)'}" lineColor="#5b7cff" lineWidth="60"></u-tabs>
  7. <!-- 记录模块 -->
  8. <view class="module-box" v-if="current == 0">
  9. <view class="module-item" v-for="(item,index) in moduleData" :key="index" :style="item.color"
  10. @click="setTime(index)">
  11. <view class="module-item-box">
  12. <text class="module-item-text">{{item.text}}</text>
  13. <view class="num-box">
  14. <text class="module-item-num">{{item.numData}}</text>
  15. </view>
  16. <view :class="item.icon"></view>
  17. </view>
  18. </view>
  19. </view>
  20. <!-- 记录表 -->
  21. <view class="module-box" v-if="current == 1">
  22. <view class="chart-item" style="width: 100%;">
  23. <view class="chart-info">
  24. <view class="t-icon t-icon-shuju1"></view>
  25. <text class="chart-info-text">近七天学习记录</text>
  26. </view>
  27. <view style=" width:100%; margin-top: -30rpx;">
  28. <qiun-data-charts type="column" :chartData="todayData.studyColumn" :loadingType="4"
  29. tooltipFormat='tooltipHour' :canvas2d="true" canvasId="canvasId9839618"/>
  30. </view>
  31. </view>
  32. <view class="chart-item">
  33. <view class="chart-info">
  34. <view class="t-icon t-icon-tiyu"></view>
  35. <text class="chart-info-text">近七天运动</text>
  36. </view>
  37. <view class="chart-view">
  38. <qiun-data-charts type="pie" :chartData="todayData.exercisePie" :loadingType="4"
  39. tooltipFormat='pieMinute' :canvas2d="true" canvasId="canvasId91234111" />
  40. </view>
  41. </view>
  42. <view class="chart-item">
  43. <view class="chart-info">
  44. <view class="t-icon t-icon-yejian"></view>
  45. <text class="chart-info-text">近七天睡眠</text>
  46. </view>
  47. <view class="chart-view">
  48. <qiun-data-charts type="ring" :chartData="todayData.sleepRing" :loadingType="4"
  49. tooltipFormat='tooltipHour' :canvas2d="true" canvasId="canvasId6312231" />
  50. </view>
  51. </view>
  52. </view>
  53. <!-- 时间选择器 -->
  54. <u-picker :show="setTimePicker" :columns="pickerList" ref="uPicker" @confirm="pickerConfirm"
  55. @cancel="pickerCancel" :closeOnClickOverlay="true" :immediateChange="true">
  56. </u-picker>
  57. </view>
  58. </template>
  59. <script>
  60. import {
  61. mapState,
  62. mapMutations
  63. } from 'vuex'
  64. export default {
  65. name: "todaydata-box",
  66. computed: {
  67. ...mapState('m_chart', ['todayData']),
  68. },
  69. watch: {
  70. historyData: {
  71. handler(newValue){
  72. this.saveToStudyChart()
  73. },
  74. immediate: true
  75. },
  76. },
  77. data() {
  78. return {
  79. //模块名
  80. list: [{
  81. name: '家庭记录'
  82. }, {
  83. name: '历史记录'
  84. }],
  85. //当前模块
  86. current: 0,
  87. //记录卡片
  88. moduleData: [{
  89. text: '自主学习记录',
  90. color: 'background-color: #5b7cff;',
  91. icon: 't-icon t-icon-bianjibi',
  92. numData: '记录一下',
  93. },
  94. {
  95. text: '娱乐放松记录',
  96. color: 'background-color: #00cca3;',
  97. icon: 't-icon t-icon-leimucuyule',
  98. numData: '记录一下',
  99. },
  100. {
  101. text: '运动锻炼记录',
  102. color: 'background-color: #ff8caf;',
  103. icon: 't-icon t-icon-yundong',
  104. numData: '记录一下',
  105. },
  106. {
  107. text: '每日睡眠记录',
  108. color: 'background-color: #f9c752;',
  109. icon: 't-icon t-icon-a-icon_wananyueliangshuimian',
  110. numData: '记录一下',
  111. }
  112. ],
  113. //当前记录卡片
  114. cardCurrent: 5,
  115. //选择器
  116. setTimePicker: false,
  117. //时间表
  118. pickerList: [
  119. ['0小时', '1小时', '2小时', '3小时', '4小时', '5小时', '6小时', '7小时', '8小时', '9小时', '10小时'],
  120. ['5分钟', '10分钟', '15分钟', '20分钟', '25分钟', '30分钟', '35分钟', '40分钟', '45分钟', '50分钟', '55分钟']
  121. ],
  122. //历史数据
  123. historyData: {
  124. study: [2, 3, 2.5, 3, 2, 1, 3],
  125. rest: [1, 2, 0.5, 3, 0.5, 3.5, 2],
  126. exercise: [0.1, 0.2, 0.5, 0.3, 0.5, 1.5, 0.2],
  127. sleep: [8, 9, 8, 8.5, 7.8, 8, 7.6]
  128. },
  129. };
  130. },
  131. created() {
  132. this.saveToStudyChart()
  133. },
  134. methods: {
  135. ...mapMutations('m_chart', ['updateStudyColumn', 'updateExercisePie', 'updateSleepRing']),
  136. //更改模块
  137. changeModule(index) {
  138. this.current = index.index
  139. },
  140. //点击卡片唤起picker
  141. setTime(index) {
  142. if (this.moduleData[index].numData === '记录一下') {
  143. this.cardCurrent = index
  144. this.setTimePicker = true
  145. } else {
  146. uni.$showMsg('今日已记录,明日再来吧')
  147. }
  148. },
  149. //记录数据
  150. pickerConfirm(e) {
  151. if (e.value[0] === '0小时') {
  152. this.moduleData[this.cardCurrent].numData = e.value[1]
  153. } else {
  154. this.moduleData[this.cardCurrent].numData = e.value[0] + e.value[1]
  155. }
  156. //转换为数据记录到图表中
  157. if (this.moduleData[this.cardCurrent].numData.search('小时') == -1) {
  158. let timeData = parseFloat(parseInt(this.moduleData[this.cardCurrent].numData.replace('分钟', '')) / 60).toFixed(1)
  159. console.log(timeData)
  160. switch (this.cardCurrent) {
  161. case 0:
  162. this.historyData.study.push(timeData)
  163. this.historyData.study.shift()
  164. break
  165. case 1:
  166. this.historyData.rest.push(timeData)
  167. this.historyData.rest.shift()
  168. break
  169. case 2:
  170. this.historyData.exercise.push(timeData)
  171. this.historyData.exercise.shift()
  172. break
  173. case 3:
  174. this.historyData.sleep.push(timeData)
  175. this.historyData.sleep.shift()
  176. break
  177. }
  178. } else {
  179. let timeTemp = this.moduleData[this.cardCurrent].numData.replace('小时', '.').replace('分钟', '').split('.')
  180. let timeData = parseInt(timeTemp[0]) + parseFloat((timeTemp[1] / 60).toFixed(1))
  181. console.log(timeData)
  182. switch (this.cardCurrent) {
  183. case 0:
  184. this.historyData.study.push(timeData)
  185. this.historyData.study.shift()
  186. break
  187. case 1:
  188. this.historyData.rest.push(timeData)
  189. this.historyData.rest.shift()
  190. break
  191. case 2:
  192. this.historyData.exercise.push(timeData)
  193. this.historyData.exercise.shift()
  194. break
  195. case 3:
  196. this.historyData.sleep.push(timeData)
  197. this.historyData.sleep.shift()
  198. break
  199. }
  200. }
  201. uni.$showMsg('记录完成', 1000)
  202. this.setTimePicker = false
  203. },
  204. //取消
  205. pickerCancel() {
  206. uni.$showMsg('取消选择', 1000)
  207. this.setTimePicker = false
  208. },
  209. //记录到图表
  210. saveToStudyChart() {
  211. let studyColumn = {
  212. categories: [],
  213. series: [{
  214. name: '自主学习',
  215. data: this.historyData.study
  216. }, {
  217. name: '娱乐放松',
  218. data: this.historyData.rest
  219. }]
  220. }
  221. //时间
  222. studyColumn.categories = this.$getRecentDateArray(7)
  223. //数据
  224. switch (this.cardCurrent) {
  225. case 0:
  226. studyColumn.series[0].data = this.historyData.study
  227. break
  228. case 1:
  229. studyColumn.series[1].data = this.historyData.rest
  230. break
  231. }
  232. //解除对象指向同一块内存(拷贝)
  233. // let studyColumnTemp = JSON.parse(JSON.stringify(studyColumn))
  234. //存储
  235. this.updateStudyColumn(studyColumn)
  236. }
  237. }
  238. }
  239. </script>
  240. <style lang="scss">
  241. .module-container {
  242. margin: -70rpx 20rpx 0 20rpx;
  243. }
  244. .module-box {
  245. display: flex;
  246. flex-direction: row;
  247. flex-wrap: wrap;
  248. justify-content: space-between;
  249. .module-item {
  250. margin: 2% 0;
  251. display: flex;
  252. flex-direction: column;
  253. background-color: #FFFFFF;
  254. border-radius: $card-border-radius;
  255. width: 48%;
  256. height: auto;
  257. overflow: hidden;
  258. .module-item-box {
  259. padding: 35rpx;
  260. width: 100%;
  261. display: flex;
  262. flex-direction: column;
  263. .t-icon {
  264. width: 250rpx;
  265. height: 250rpx;
  266. margin: -250rpx 0 0 150rpx;
  267. z-index: 1;
  268. }
  269. }
  270. }
  271. }
  272. .module-item-text {
  273. color: #FFF;
  274. font-size: 28rpx;
  275. font-weight: bold;
  276. z-index: 5;
  277. }
  278. .num-box {
  279. margin-top: 20rpx;
  280. z-index: 5;
  281. .module-item-num {
  282. color: #FFF;
  283. font-size: 42rpx;
  284. font-weight: bold;
  285. }
  286. }
  287. .chart-item {
  288. margin: 2% 0;
  289. display: flex;
  290. flex-direction: column;
  291. justify-content: space-between;
  292. background-color: #FFF;
  293. // box-shadow: 0 4rpx 8rpx rgba(0, 0, 0, 0.05);
  294. border-radius: $card-border-radius;
  295. width: 48%;
  296. height: auto;
  297. .chart-info {
  298. display: flex;
  299. align-items: center;
  300. padding: 20rpx;
  301. .chart-info-text {
  302. font-size: 30rpx;
  303. font-weight: bold;
  304. color: #3B4144;
  305. margin-left: 10rpx;
  306. }
  307. }
  308. .chart-view {
  309. height: 300rpx;
  310. }
  311. }
  312. </style>