interactive-box.vue 11 KB

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