123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393 |
- <template>
- <!-- 今日记录模块 -->
- <view class="module-container">
- <u-tabs :list="list" :current="current" @change="changeModule"
- :activeStyle="{color: '#4169E1',fontWeight: 'bold',transform: 'scale(1.08)',}"
- :inactiveStyle="{fontWeight: 'bold',transform: 'scale(1)'}" lineColor="#4169E1" 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">
-
- <view style="display: flex;align-items: baseline;" v-if="item.numData === '记录一下'">
- <text class="module-item-num">记录</text>
- <text class="module-item-num" style="font-size: 30rpx;opacity:0.8;margin-left: 6rpx">今日时长</text>
- </view>
- <view style="display: flex;align-items: baseline;" v-else>
- <text class="module-item-num">{{item.numData.split('小时')[0]}}</text>
- <text class="module-item-num" style="font-size: 30rpx;opacity:0.8;margin-left: 6rpx">小时</text>
- <text class="module-item-num" style="margin-left: 6rpx">{{item.numData.split('小时')[1].replace('分','')}}</text>
- <text class="module-item-num" style="font-size: 30rpx;opacity:0.8;margin-left: 6rpx">分钟</text>
- </view>
- </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="studyColumn" :loadingType="4"
- tooltipFormat='tooltipHourColum' :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="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="pie" :chartData="sleepRing" :loadingType="4" tooltipFormat='pieHour' :canvas2d="true" canvasId="canvasId6312231" />
- </view>
- </view>
- <view class="chart-item" style="width: 100%;">
- <view class="chart-info">
- <view class="t-icon t-icon-qingjiashenqing"></view>
- <text class="chart-info-text">运动睡眠对比</text>
- </view>
- <view style=" width:100%;margin-top: -30rpx;height: 420rpx;">
- <qiun-data-charts type="area" :chartData="exerciseSleepArea" :loadingType="4"
- tooltipFormat='sleepExerciseCom' :canvas2d="true" canvasId="canvasId983131231" />
- </view>
- </view>
- </view>
- <!-- 时间选择器 -->
- <u-picker :show="setTimePicker" :columns="pickerList" ref="uPicker" @confirm="pickerConfirm"
- @cancel="pickerCancel" :closeOnClickOverlay="true" :immediateChange="true">
- </u-picker>
- </view>
- </template>
- <script>
- export default {
- name: "interactive-box",
- data() {
- return {
- //学习记录表
- studyColumn: {},
- //锻炼时间表
- exercisePie: {},
- //睡眠时间表
- sleepRing: {},
- //运动睡眠比
- exerciseSleepArea: {},
- //模块名
- list: [{
- name: '每日记录'
- }, {
- name: '记录分析'
- }],
- //当前模块
- current: 0,
- //记录卡片
- moduleData: [{
- text: '学习时长',
- color: 'background-color: #4169E1;',
- icon: 't-icon t-icon-bianjibi',
- numData: '记录一下',
- },
- {
- text: '娱乐时长',
- color: 'background-color: #ff5959;',
- 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: {
- //更改模块
- 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))
- 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:
- let numExercise = parseInt(this.moduleData[this.cardCurrent].numData.replace('分', '')) / 60
- this.historyData.exercise.push(numExercise)
- this.historyData.exercise.shift()
- console.log(this.historyData.exercise);
- break
- case 3:
- this.historyData.sleep.push(timeData)
- this.historyData.sleep.shift()
- console.log(this.historyData.sleep);
- break
- }
- this.saveToStudyChart()
- } else {
- let timeTemp = this.moduleData[this.cardCurrent].numData.replace('小时', '.').replace('分', '').split('.')
- let timeData = parseInt(timeTemp[0]) + parseFloat((timeTemp[1] / 60).toFixed(1))
- 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()
- console.log(this.historyData.exercise);
- break
- case 3:
- this.historyData.sleep.push(timeData)
- this.historyData.sleep.shift()
- console.log(this.historyData.sleep);
- break
- }
- this.saveToStudyChart()
- }
- 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(this.historyData.study.length)
- //学习记录表数据记录
- switch (this.cardCurrent) {
- case 0:
- studyColumn.series[0].data = this.historyData.study
- break
- case 1:
- studyColumn.series[1].data = this.historyData.rest
- break
- }
- //学习记录表赋值
- this.studyColumn = studyColumn
- //运动记录表
- let exercisePie = {
- series: [{
- data: [{}, {}, {}, {}, {}, {}, {}]
- }]
- }
- //睡眠记录表
- let sleepRing = {
- series: [{
- data: [{}, {}, {}, {}, {}, {}, {}]
- }]
- }
- studyColumn.categories.forEach((value, index) => {
- exercisePie.series[0].data[index].name = value
- exercisePie.series[0].data[index].value = parseFloat((this.historyData.exercise[index] * 60)
- .toFixed(1))
- sleepRing.series[0].data[index].name = value
- sleepRing.series[0].data[index].value = this.historyData.sleep[index]
- })
- this.exercisePie = exercisePie
- this.sleepRing = sleepRing
- let exerciseSleepArea = {
- categories: [],
- series: [{
- name: "运动睡眠时间比",
- data: []
- }]
- }
- exerciseSleepArea.categories = this.$getRecentDateArray(this.historyData.sleep.length)
- let tempArr = []
- for (let i = 0; i < this.historyData.sleep.length; i++) {
- let num = parseFloat(((this.historyData.exercise[i] / this.historyData.sleep[i]) * 100).toFixed(1))
- tempArr.push(num)
- }
- console.log(tempArr);
- exerciseSleepArea.series[0].data = tempArr
- this.exerciseSleepArea = exerciseSleepArea
- }
- }
- }
- </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 30rpx 20rpx 30rpx;
- width: 100%;
- display: flex;
- flex-direction: column;
- justify-content: space-around;
- height: 160rpx;
- .t-icon {
- width: 250rpx;
- height: 250rpx;
- margin: -250rpx 0 0 160rpx;
- z-index: 1;
- }
- }
- }
- }
- .module-item-text {
- color: #FFF;
- font-size: 30rpx;
- font-weight: bold;
- z-index: 5;
- }
- .num-box {
- margin-top: 20rpx;
- z-index: 5;
- .module-item-num {
- color: #FFF;
- font-size: 50rpx;
- 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: $color-title;
- margin-left: 10rpx;
- }
- }
- .chart-view {
- height: 320rpx;
- width: 100%;
- }
- }
- </style>
|