interactive-box.vue 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370
  1. <template>
  2. <!-- 今日记录模块 -->
  3. <view class="module-container">
  4. <u-tabs :list="list" :current="current" @change="changeModule"
  5. :activeStyle="{color: '#4169E1',fontWeight: 'bold',transform: 'scale(1.08)',}"
  6. :inactiveStyle="{fontWeight: 'bold',transform: 'scale(1)'}" lineColor="#4169E1" 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="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="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="pie" :chartData="sleepRing" :loadingType="4"
  49. tooltipFormat='tooltipHour' :canvas2d="true" canvasId="canvasId6312231" />
  50. </view>
  51. </view>
  52. <view class="chart-item" style="width: 100%;">
  53. <view class="chart-info">
  54. <view class="t-icon t-icon-qingjiashenqing"></view>
  55. <text class="chart-info-text">运动睡眠对比</text>
  56. </view>
  57. <view style=" width:100%;margin-top: -30rpx;height: 450rpx;">
  58. <qiun-data-charts type="area" :chartData="exerciseSleepArea" :loadingType="4"
  59. tooltipFormat='tooltipHourCom' :canvas2d="true" canvasId="canvasId983131231"/>
  60. </view>
  61. </view>
  62. </view>
  63. <!-- 时间选择器 -->
  64. <u-picker :show="setTimePicker" :columns="pickerList" ref="uPicker" @confirm="pickerConfirm"
  65. @cancel="pickerCancel" :closeOnClickOverlay="true" :immediateChange="true">
  66. </u-picker>
  67. </view>
  68. </template>
  69. <script>
  70. export default {
  71. name: "interactive-box",
  72. data() {
  73. return {
  74. //学习记录表
  75. studyColumn: {},
  76. //锻炼时间表
  77. exercisePie: {},
  78. //睡眠时间表
  79. sleepRing: {},
  80. //运动睡眠比
  81. exerciseSleepArea: {},
  82. //模块名
  83. list: [{
  84. name: '每日记录'
  85. }, {
  86. name: '记录分析'
  87. }],
  88. //当前模块
  89. current: 0,
  90. //记录卡片
  91. moduleData: [{
  92. text: '自主学习记录',
  93. color: 'background-color: #4169E1;',
  94. icon: 't-icon t-icon-bianjibi',
  95. numData: '记录一下',
  96. },
  97. {
  98. text: '娱乐放松记录',
  99. color: 'background-color: #ff5959;',
  100. icon: 't-icon t-icon-leimucuyule',
  101. numData: '记录一下',
  102. },
  103. {
  104. text: '运动锻炼记录',
  105. color: 'background-color: #ff8caf;',
  106. icon: 't-icon t-icon-yundong',
  107. numData: '记录一下',
  108. },
  109. {
  110. text: '每日睡眠记录',
  111. color: 'background-color: #f9c752;',
  112. icon: 't-icon t-icon-a-icon_wananyueliangshuimian',
  113. numData: '记录一下',
  114. }
  115. ],
  116. //当前记录卡片
  117. cardCurrent: 5,
  118. //选择器
  119. setTimePicker: false,
  120. //时间表
  121. pickerList: [
  122. ['0小时', '1小时', '2小时', '3小时', '4小时', '5小时', '6小时', '7小时', '8小时', '9小时', '10小时'],
  123. ['5分', '10分', '15分', '20分', '25分', '30分', '35分', '40分', '45分', '50分', '55分']
  124. ],
  125. //历史数据
  126. historyData: {
  127. study: [2, 3, 2.5, 3, 2, 1, 3],
  128. rest: [1, 2, 0.5, 3, 0.5, 3.5, 2],
  129. exercise: [0.1, 0.2, 0.5, 0.3, 0.5, 1.5, 0.2],
  130. sleep: [8, 9, 8, 8.5, 7.8, 8, 7.6]
  131. },
  132. };
  133. },
  134. created() {
  135. this.saveToStudyChart()
  136. },
  137. methods: {
  138. //更改模块
  139. changeModule(index) {
  140. this.current = index.index
  141. },
  142. //点击卡片唤起picker
  143. setTime(index) {
  144. if (this.moduleData[index].numData === '记录一下') {
  145. this.cardCurrent = index
  146. this.setTimePicker = true
  147. } else {
  148. uni.$showMsg('今日已记录,明日再来吧')
  149. }
  150. },
  151. //记录数据
  152. pickerConfirm(e) {
  153. if (e.value[0] === '0小时') {
  154. this.moduleData[this.cardCurrent].numData = e.value[1]
  155. } else {
  156. this.moduleData[this.cardCurrent].numData = e.value[0] + e.value[1]
  157. }
  158. //转换为数据记录到图表中
  159. if (this.moduleData[this.cardCurrent].numData.search('小时') == -1) {
  160. let timeData = parseFloat((parseInt(this.moduleData[this.cardCurrent].numData.replace('分', '')) / 60).toFixed(1))
  161. switch (this.cardCurrent) {
  162. case 0:
  163. this.historyData.study.push(timeData)
  164. this.historyData.study.shift()
  165. break
  166. case 1:
  167. this.historyData.rest.push(timeData)
  168. this.historyData.rest.shift()
  169. break
  170. case 2:
  171. let numExercise = parseInt(this.moduleData[this.cardCurrent].numData.replace('分', ''))/60
  172. this.historyData.exercise.push(numExercise)
  173. this.historyData.exercise.shift()
  174. console.log(this.historyData.exercise);
  175. break
  176. case 3:
  177. this.historyData.sleep.push(timeData)
  178. this.historyData.sleep.shift()
  179. console.log(this.historyData.sleep);
  180. break
  181. }
  182. this.saveToStudyChart()
  183. } else {
  184. let timeTemp = this.moduleData[this.cardCurrent].numData.replace('小时', '.').replace('分', '').split('.')
  185. let timeData = parseInt(timeTemp[0]) + parseFloat((timeTemp[1] / 60).toFixed(1))
  186. switch (this.cardCurrent) {
  187. case 0:
  188. this.historyData.study.push(timeData)
  189. this.historyData.study.shift()
  190. break
  191. case 1:
  192. this.historyData.rest.push(timeData)
  193. this.historyData.rest.shift()
  194. break
  195. case 2:
  196. this.historyData.exercise.push(timeData)
  197. this.historyData.exercise.shift()
  198. console.log(this.historyData.exercise);
  199. break
  200. case 3:
  201. this.historyData.sleep.push(timeData)
  202. this.historyData.sleep.shift()
  203. console.log(this.historyData.sleep);
  204. break
  205. }
  206. this.saveToStudyChart()
  207. }
  208. uni.$showMsg('记录完成', 1000)
  209. this.setTimePicker = false
  210. },
  211. //取消
  212. pickerCancel() {
  213. uni.$showMsg('取消选择', 1000)
  214. this.setTimePicker = false
  215. },
  216. //记录到图表
  217. saveToStudyChart() {
  218. let studyColumn = {
  219. categories: [],
  220. series: [{name: '自主学习',data: this.historyData.study},
  221. {name: '娱乐放松',data: this.historyData.rest}]
  222. }
  223. //时间
  224. studyColumn.categories = this.$getRecentDateArray(7)
  225. //学习记录表数据记录
  226. switch (this.cardCurrent) {
  227. case 0:
  228. studyColumn.series[0].data = this.historyData.study
  229. break
  230. case 1:
  231. studyColumn.series[1].data = this.historyData.rest
  232. break
  233. }
  234. //学习记录表赋值
  235. this.studyColumn = studyColumn
  236. //运动记录表
  237. let exercisePie = {
  238. series: [{
  239. data: [{},{},{},{},{},{},{}]
  240. }]
  241. }
  242. //睡眠记录表
  243. let sleepRing = {
  244. series: [{
  245. data: [{},{},{},{},{},{},{}]
  246. }]
  247. }
  248. studyColumn.categories.forEach((value,index)=>{
  249. exercisePie.series[0].data[index].name = value
  250. exercisePie.series[0].data[index].value = parseFloat((this.historyData.exercise[index]*60).toFixed(1))
  251. sleepRing.series[0].data[index].name = value
  252. sleepRing.series[0].data[index].value = this.historyData.sleep[index]
  253. })
  254. this.exercisePie = exercisePie
  255. this.sleepRing = sleepRing
  256. let exerciseSleepArea = {
  257. categories: [],
  258. series:
  259. [{name: "每日锻炼时间",data: []},
  260. {name: "每日睡眠时间",data: []}]
  261. }
  262. exerciseSleepArea.categories = studyColumn.categories
  263. exerciseSleepArea.series[0].data = this.historyData.exercise
  264. exerciseSleepArea.series[1].data = this.historyData.sleep
  265. this.exerciseSleepArea = exerciseSleepArea
  266. }
  267. }
  268. }
  269. </script>
  270. <style lang="scss">
  271. .module-container {
  272. margin: -70rpx 20rpx 0 20rpx;
  273. }
  274. .module-box {
  275. display: flex;
  276. flex-direction: row;
  277. flex-wrap: wrap;
  278. justify-content: space-between;
  279. .module-item {
  280. margin: 2% 0;
  281. display: flex;
  282. flex-direction: column;
  283. background-color: #FFFFFF;
  284. border-radius: $card-border-radius;
  285. width: 48%;
  286. height: auto;
  287. overflow: hidden;
  288. .module-item-box {
  289. padding: 35rpx 30rpx 20rpx 30rpx;
  290. width: 100%;
  291. display: flex;
  292. flex-direction: column;
  293. justify-content: space-around;
  294. height: 170rpx;
  295. .t-icon {
  296. width: 250rpx;
  297. height: 250rpx;
  298. margin: -250rpx 0 0 150rpx;
  299. z-index: 1;
  300. }
  301. }
  302. }
  303. }
  304. .module-item-text {
  305. color: #FFF;
  306. font-size: 30rpx;
  307. font-weight: bold;
  308. z-index: 5;
  309. }
  310. .num-box {
  311. margin-top: 20rpx;
  312. z-index: 5;
  313. .module-item-num {
  314. color: #FFF;
  315. font-size: 45rpx;
  316. font-weight: bold;
  317. }
  318. }
  319. .chart-item {
  320. margin: 2% 0;
  321. display: flex;
  322. flex-direction: column;
  323. justify-content: space-between;
  324. background-color: #FFF;
  325. // box-shadow: 0 4rpx 8rpx rgba(0, 0, 0, 0.05);
  326. border-radius: $card-border-radius;
  327. width: 48%;
  328. height: auto;
  329. .chart-info {
  330. display: flex;
  331. align-items: center;
  332. padding: 20rpx;
  333. .chart-info-text {
  334. font-size: 30rpx;
  335. font-weight: bold;
  336. color: $color-title;
  337. margin-left: 10rpx;
  338. }
  339. }
  340. .chart-view {
  341. height: 320rpx;
  342. width: 100%;
  343. }
  344. }
  345. </style>