interactive-box.vue 11 KB

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