Explorar el Código

修复学习计划显示问题

shmily1213 hace 4 semanas
padre
commit
f51380c3a8

+ 34 - 19
src/pagesStudy/pages/study-plan/components/page-calendar.vue

@@ -1,7 +1,7 @@
 <template>
   <view class="mt-24 bg-white relative z-4">
-    <uni-calendar ref="calendarRef" :insert="true" :lunar="false" :readonly="false" :showMonth="false" :selected="selected"
-      :endDate="endDate" @change-month="changeMonth" @change="handleChangeDate" />
+    <uni-calendar ref="calendarRef" :insert="true" :lunar="false" :readonly="false" :showMonth="false"
+      :selected="selected" :endDate="endDate" @change-month="changeMonth" @change="handleChangeDate" />
     <view class="wrap mt-20 w-fit mx-auto px-98 py-16 flex items-center justify-center transition-all duration-300">
       <ie-image src="/pagesStudy/static/image/icon-calendar.png" custom-class="w-22 h-22" />
       <text class="ml-4 text-20 text-primary">{{ tip }}</text>
@@ -26,17 +26,17 @@ const studyPlanStats = inject(STUDY_PLAN_STATS) || ref({} as Study.StudyPlanStat
 const today = uni.$uv.timeFormat(new Date(), 'yyyy-mm-dd');
 let selectDate = ref(today);
 const stat = computed(() => {
-  let todayData = {} as Study.StudyStats;
+  let todayData = selectedDate.value;
   const questionCnt = studyPlan.value.questionCnt;
   const videoTime = studyPlan.value.videoTime;
-  if (studyPlanStats.value?.studyList?.length) {
-    const index = studyPlanStats?.value?.studyList.findIndex(item => item.date === selectDate.value);
-    if (index !== -1) {
-      todayData = studyPlanStats.value?.studyList[index].data;
-    } else {
-      todayData = {} as Study.StudyStats;
-    }
-  }
+  // if (studyPlanStats.value?.studyList?.length) {
+  //   const index = studyPlanStats?.value?.studyList.findIndex(item => item.date === selectDate.value);
+  //   if (index !== -1) {
+  //     todayData = studyPlanStats.value?.studyList[index].data;
+  //   } else {
+  //     todayData = {} as Study.StudyStats;
+  //   }
+  // }
 
   return [
     {
@@ -51,20 +51,30 @@ const stat = computed(() => {
       value: `${getValue(todayData?.videoTime)}/${getValue(videoTime)}`,
       icon: '/pagesStudy/static/image/icon-video.png'
     },
-    {
-      name: '学习时长',
-      unit: '分钟',
-      value: `${getValue(todayData?.videoTimes)}`,
-      icon: '/pagesStudy/static/image/icon-time.png'
-    },
     {
       name: '正确率',
       unit: '',
       value: `${getValue(todayData?.rightRate)}%`,
       icon: '/pagesStudy/static/image/icon-chart.png'
+    },
+    {
+      name: '学习时长',
+      unit: '分钟',
+      value: `${formatMinutes(todayData?.videoTimes)}`,
+      icon: '/pagesStudy/static/image/icon-time.png'
     }
   ]
 });
+const selectedDate = computed(() => {
+  if (studyPlanStats.value?.studyList?.length) {
+    const index = studyPlanStats?.value?.studyList.findIndex(item => item.date === selectDate.value);
+    if (index !== -1) {
+      return studyPlanStats.value?.studyList[index].data;
+    } else {
+      return {} as Study.StudyStats;
+    }
+  }
+});
 const isShowToday = computed(() => {
   return selectDate.value === today;
 });
@@ -85,7 +95,8 @@ const selected = computed(() => {
 
 const endDate = ref('')
 const todayPlanFinish = computed(() => {
-  const todayData = studyPlanStats?.value?.today;
+  // const todayData = studyPlanStats?.value?.today;
+  const todayData = selectedDate.value;
   const questionCnt = studyPlan.value.questionCnt;
   const videoTime = studyPlan.value.videoTime;
 
@@ -94,7 +105,7 @@ const todayPlanFinish = computed(() => {
     getValue(todayData?.videoTime) >= getValue(videoTime)) {
     return true;
   }
-  return false
+  return false;
 });
 const tip = computed(() => {
   if (isShowToday.value) {
@@ -122,6 +133,10 @@ const handleChangeDate = (e: any) => {
   selectDate.value = e.fulldate;
 }
 
+const formatMinutes = (val?: number) => {
+  return val ? val / 60 : 0;
+}
+
 init();
 </script>
 <style lang="scss" scoped>

+ 5 - 2
src/pagesStudy/pages/study-plan/components/page-header.vue

@@ -39,8 +39,8 @@ const stat = computed(() => {
       desc: '本月未完成'
     },
     {
-      data: getValue(studyPlanStats?.videoTimes),
-      unit: 'h',
+      data: formatMinutes(studyPlanStats?.videoTimes),
+      unit: '分钟',
       desc: '学习时长'
     },
     {
@@ -53,5 +53,8 @@ const stat = computed(() => {
 const getValue = (val?: number) => {
   return val || 0;
 }
+const formatMinutes = (val?: number) => {
+  return val ? val / 60 : 0;
+}
 </script>
 <style lang="scss" scoped></style>