KELECHUAN преди 3 години
родител
ревизия
a0425e7d6a
променени са 2 файла, в които са добавени 79 реда и са изтрити 14 реда
  1. 78 14
      components/todaydata-box/todaydata-box.vue
  2. 1 0
      pages/homework/homework.vue

+ 78 - 14
components/todaydata-box/todaydata-box.vue

@@ -28,7 +28,7 @@
 				</view>
 				<view style=" width:100%; margin-top: -30rpx;">
 					<qiun-data-charts type="column" :chartData="todayData.studyColumn" :loadingType="4"
-						tooltipFormat='tooltipHour' :canvas2d="true" canvasId="canvasId9839618" />
+						tooltipFormat='tooltipHour' :canvas2d="true" canvasId="canvasId9839618"/>
 				</view>
 			</view>
 
@@ -72,6 +72,14 @@
 		computed: {
 			...mapState('m_chart', ['todayData']),
 		},
+		watch: {
+			historyData: {
+				handler(newValue){
+					this.saveToStudyChart()
+				},
+				immediate: true
+			},
+		},
 		data() {
 			return {
 				//模块名
@@ -121,9 +129,10 @@
 				historyData: {
 					study: [2, 3, 2.5, 3, 2, 1, 3],
 					rest: [1, 2, 0.5, 3, 0.5, 3.5, 2],
-					exercise: [],
-					sleep: []
-				}
+					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]
+				},
+
 
 			};
 		},
@@ -138,16 +147,66 @@
 			},
 			//点击卡片唤起picker
 			setTime(index) {
-				this.cardCurrent = index
-				this.setTimePicker = true
+				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
 			},
@@ -155,9 +214,6 @@
 			pickerCancel() {
 				uni.$showMsg('取消选择', 1000)
 				this.setTimePicker = false
-			},
-			stringToNum(){
-				
 			},
 			//记录到图表
 			saveToStudyChart() {
@@ -165,17 +221,25 @@
 					categories: [],
 					series: [{
 						name: '自主学习',
-						data: []
+						data: this.historyData.study
 					}, {
 						name: '娱乐放松',
-						data: []
+						data: this.historyData.rest
 					}]
 				}
 				//时间
 				studyColumn.categories = this.$getRecentDateArray(7)
 				//数据
-				studyColumn.series[0].data = this.historyData.study
-				studyColumn.series[1].data = this.historyData.rest
+				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)
 			}

+ 1 - 0
pages/homework/homework.vue

@@ -229,6 +229,7 @@
 				//时间
 				temp.categories = this.$getRecentDateArray(5)
 				//数据
+				//解除对象指向同一块内存(拷贝)
 				temp.series[0].data = this.historyData.test
 				let testDataTemp = JSON.parse(JSON.stringify(temp))
 				this.updateTestColumn(testDataTemp)