123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334 |
- <template>
- <!-- 今日记录模块 -->
- <view class="module-container">
- <u-tabs :list="list" :current="current" @change="changeModule"
- :activeStyle="{color: '#5b7cff',fontWeight: 'bold',transform: 'scale(1.04)',}"
- :inactiveStyle="{fontWeight: 'bold',transform: 'scale(1)'}" lineColor="#5b7cff" lineWidth="60"></u-tabs>
- <!-- 记录模块 -->
- <view class="module-box" v-if="current == 0">
- <view class="module-item" v-for="(item,index) in moduleData" :key="index" :style="item.color"
- @click="setTime(index)">
- <view class="module-item-box">
- <text class="module-item-text">{{item.text}}</text>
- <view class="num-box">
- <text class="module-item-num">{{item.numData}}</text>
- </view>
- <view :class="item.icon"></view>
- </view>
- </view>
- </view>
- <!-- 记录表 -->
- <view class="module-box" v-if="current == 1">
- <view class="chart-item" style="width: 100%;">
- <view class="chart-info">
- <view class="t-icon t-icon-shuju1"></view>
- <text class="chart-info-text">近七天学习记录</text>
- </view>
- <view style=" width:100%; margin-top: -30rpx;">
- <qiun-data-charts type="column" :chartData="todayData.studyColumn" :loadingType="4"
- tooltipFormat='tooltipHour' :canvas2d="true" canvasId="canvasId9839618"/>
- </view>
- </view>
- <view class="chart-item">
- <view class="chart-info">
- <view class="t-icon t-icon-tiyu"></view>
- <text class="chart-info-text">近七天运动</text>
- </view>
- <view class="chart-view">
- <qiun-data-charts type="pie" :chartData="todayData.exercisePie" :loadingType="4"
- tooltipFormat='pieMinute' :canvas2d="true" canvasId="canvasId91234111" />
- </view>
- </view>
- <view class="chart-item">
- <view class="chart-info">
- <view class="t-icon t-icon-yejian"></view>
- <text class="chart-info-text">近七天睡眠</text>
- </view>
- <view class="chart-view">
- <qiun-data-charts type="ring" :chartData="todayData.sleepRing" :loadingType="4"
- tooltipFormat='tooltipHour' :canvas2d="true" canvasId="canvasId6312231" />
- </view>
- </view>
- </view>
- <!-- 时间选择器 -->
- <u-picker :show="setTimePicker" :columns="pickerList" ref="uPicker" @confirm="pickerConfirm"
- @cancel="pickerCancel" :closeOnClickOverlay="true" :immediateChange="true">
- </u-picker>
- </view>
- </template>
- <script>
- import {
- mapState,
- mapMutations
- } from 'vuex'
- export default {
- name: "todaydata-box",
- computed: {
- ...mapState('m_chart', ['todayData']),
- },
- watch: {
- historyData: {
- handler(newValue){
- this.saveToStudyChart()
- },
- immediate: true
- },
- },
- data() {
- return {
- //模块名
- list: [{
- name: '家庭记录'
- }, {
- name: '历史记录'
- }],
- //当前模块
- current: 0,
- //记录卡片
- moduleData: [{
- text: '自主学习记录',
- color: 'background-color: #5b7cff;',
- icon: 't-icon t-icon-bianjibi',
- numData: '记录一下',
- },
- {
- text: '娱乐放松记录',
- color: 'background-color: #00cca3;',
- icon: 't-icon t-icon-leimucuyule',
- numData: '记录一下',
- },
- {
- text: '运动锻炼记录',
- color: 'background-color: #ff8caf;',
- icon: 't-icon t-icon-yundong',
- numData: '记录一下',
- },
- {
- text: '每日睡眠记录',
- color: 'background-color: #f9c752;',
- icon: 't-icon t-icon-a-icon_wananyueliangshuimian',
- numData: '记录一下',
- }
- ],
- //当前记录卡片
- cardCurrent: 5,
- //选择器
- setTimePicker: false,
- //时间表
- pickerList: [
- ['0小时', '1小时', '2小时', '3小时', '4小时', '5小时', '6小时', '7小时', '8小时', '9小时', '10小时'],
- ['5分钟', '10分钟', '15分钟', '20分钟', '25分钟', '30分钟', '35分钟', '40分钟', '45分钟', '50分钟', '55分钟']
- ],
- //历史数据
- historyData: {
- study: [2, 3, 2.5, 3, 2, 1, 3],
- rest: [1, 2, 0.5, 3, 0.5, 3.5, 2],
- exercise: [0.1, 0.2, 0.5, 0.3, 0.5, 1.5, 0.2],
- sleep: [8, 9, 8, 8.5, 7.8, 8, 7.6]
- },
- };
- },
- created() {
- this.saveToStudyChart()
- },
- methods: {
- ...mapMutations('m_chart', ['updateStudyColumn', 'updateExercisePie', 'updateSleepRing']),
- //更改模块
- changeModule(index) {
- this.current = index.index
- },
- //点击卡片唤起picker
- setTime(index) {
- if (this.moduleData[index].numData === '记录一下') {
- this.cardCurrent = index
- this.setTimePicker = true
- } else {
- uni.$showMsg('今日已记录,明日再来吧')
- }
- },
- //记录数据
- pickerConfirm(e) {
- if (e.value[0] === '0小时') {
- this.moduleData[this.cardCurrent].numData = e.value[1]
- } else {
- this.moduleData[this.cardCurrent].numData = e.value[0] + e.value[1]
- }
- //转换为数据记录到图表中
- if (this.moduleData[this.cardCurrent].numData.search('小时') == -1) {
- let timeData = parseFloat(parseInt(this.moduleData[this.cardCurrent].numData.replace('分钟', '')) / 60).toFixed(1)
- console.log(timeData)
- switch (this.cardCurrent) {
- case 0:
- this.historyData.study.push(timeData)
- this.historyData.study.shift()
- break
- case 1:
- this.historyData.rest.push(timeData)
- this.historyData.rest.shift()
- break
- case 2:
- this.historyData.exercise.push(timeData)
- this.historyData.exercise.shift()
- break
- case 3:
- this.historyData.sleep.push(timeData)
- this.historyData.sleep.shift()
- break
- }
- } else {
- let timeTemp = this.moduleData[this.cardCurrent].numData.replace('小时', '.').replace('分钟', '').split('.')
- let timeData = parseInt(timeTemp[0]) + parseFloat((timeTemp[1] / 60).toFixed(1))
- console.log(timeData)
- switch (this.cardCurrent) {
- case 0:
- this.historyData.study.push(timeData)
- this.historyData.study.shift()
- break
- case 1:
- this.historyData.rest.push(timeData)
- this.historyData.rest.shift()
- break
- case 2:
- this.historyData.exercise.push(timeData)
- this.historyData.exercise.shift()
- break
- case 3:
- this.historyData.sleep.push(timeData)
- this.historyData.sleep.shift()
- break
- }
- }
- uni.$showMsg('记录完成', 1000)
- this.setTimePicker = false
- },
- //取消
- pickerCancel() {
- uni.$showMsg('取消选择', 1000)
- this.setTimePicker = false
- },
- //记录到图表
- saveToStudyChart() {
- let studyColumn = {
- categories: [],
- series: [{
- name: '自主学习',
- data: this.historyData.study
- }, {
- name: '娱乐放松',
- data: this.historyData.rest
- }]
- }
- //时间
- studyColumn.categories = this.$getRecentDateArray(7)
- //数据
- switch (this.cardCurrent) {
- case 0:
- studyColumn.series[0].data = this.historyData.study
- break
- case 1:
- studyColumn.series[1].data = this.historyData.rest
- break
- }
- //解除对象指向同一块内存(拷贝)
- // let studyColumnTemp = JSON.parse(JSON.stringify(studyColumn))
- //存储
- this.updateStudyColumn(studyColumn)
- }
- }
- }
- </script>
- <style lang="scss">
- .module-container {
- margin: -70rpx 20rpx 0 20rpx;
- }
- .module-box {
- display: flex;
- flex-direction: row;
- flex-wrap: wrap;
- justify-content: space-between;
- .module-item {
- margin: 2% 0;
- display: flex;
- flex-direction: column;
- background-color: #FFFFFF;
- border-radius: $card-border-radius;
- width: 48%;
- height: auto;
- overflow: hidden;
- .module-item-box {
- padding: 35rpx;
- width: 100%;
- display: flex;
- flex-direction: column;
- .t-icon {
- width: 250rpx;
- height: 250rpx;
- margin: -250rpx 0 0 150rpx;
- z-index: 1;
- }
- }
- }
- }
- .module-item-text {
- color: #FFF;
- font-size: 28rpx;
- font-weight: bold;
- z-index: 5;
- }
- .num-box {
- margin-top: 20rpx;
- z-index: 5;
- .module-item-num {
- color: #FFF;
- font-size: 42rpx;
- font-weight: bold;
- }
- }
- .chart-item {
- margin: 2% 0;
- display: flex;
- flex-direction: column;
- justify-content: space-between;
- background-color: #FFF;
- // box-shadow: 0 4rpx 8rpx rgba(0, 0, 0, 0.05);
- border-radius: $card-border-radius;
- width: 48%;
- height: auto;
- .chart-info {
- display: flex;
- align-items: center;
- padding: 20rpx;
- .chart-info-text {
- font-size: 30rpx;
- font-weight: bold;
- color: #3B4144;
- margin-left: 10rpx;
- }
- }
- .chart-view {
- height: 300rpx;
- }
- }
- </style>
|