From 3492fc6c5c9789ff0848d5cdd47b2a46722d8a53 Mon Sep 17 00:00:00 2001 From: HoshinoSuzumi Date: Fri, 20 Sep 2024 16:15:23 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E8=AF=BE=E7=A8=8B=E8=AF=A6=E6=83=85?= =?UTF-8?q?=E9=A1=B5=E9=9D=A2=E7=BA=BF=E6=80=A7=E8=BF=9B=E5=BA=A6=E5=B1=95?= =?UTF-8?q?=E7=A4=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- components.d.ts | 3 +++ src/pages/index/index.vue | 32 ++++++++++++------------- src/pages/lesson/index.vue | 22 +++++++++++------ src/utils/lesson.ts | 48 ++++++++++++++++++++++++++++++++++++++ 4 files changed, 81 insertions(+), 24 deletions(-) create mode 100644 src/utils/lesson.ts diff --git a/components.d.ts b/components.d.ts index 083c60d..56a1c04 100644 --- a/components.d.ts +++ b/components.d.ts @@ -19,6 +19,9 @@ declare module 'vue' { WdInput: typeof import('wot-design-uni/components/wd-input/wd-input.vue')['default'] WdProgress: typeof import('wot-design-uni/components/wd-progress/wd-progress.vue')['default'] WdStatusTip: typeof import('wot-design-uni/components/wd-status-tip/wd-status-tip.vue')['default'] + WdSte: typeof import('wot-design-uni/components/wd-ste/wd-ste.vue')['default'] + WdStep: typeof import('wot-design-uni/components/wd-step/wd-step.vue')['default'] + WdSteps: typeof import('wot-design-uni/components/wd-steps/wd-steps.vue')['default'] WdTabbar: typeof import('wot-design-uni/components/wd-tabbar/wd-tabbar.vue')['default'] WdTabbarItem: typeof import('wot-design-uni/components/wd-tabbar-item/wd-tabbar-item.vue')['default'] WdToast: typeof import('wot-design-uni/components/wd-toast/wd-toast.vue')['default'] diff --git a/src/pages/index/index.vue b/src/pages/index/index.vue index 31bcbd8..145842a 100644 --- a/src/pages/index/index.vue +++ b/src/pages/index/index.vue @@ -2,6 +2,7 @@ import BussApi from '@/api/BussApi'; import pageWrapper from '@/components/page-wrapper.vue'; import type { Lesson } from '@/types/api/lesson'; +import { calcLessonProgress } from '@/utils/lesson'; import { useRouter } from 'uni-mini-router'; import { onMounted, ref } from 'vue'; import { useToast } from 'wot-design-uni'; @@ -10,7 +11,7 @@ const toast = useToast() const router = useRouter() const expandedCourse = ref(['lesson']) -const groupLessons = ref<{ [key: string]: Lesson[] }>({}) +const groupedLessons = ref<{ [key: string]: Lesson[] }>({}) const openLessonDetail = (courseId: number) => { router.push({ @@ -21,13 +22,6 @@ const openLessonDetail = (courseId: number) => { }) } -const calcProgress = (course: Lesson) => { - const total = 4 - let finished = 0 - if (!!course?.script_file) finished++ - return Math.floor((finished / total) * 100) -} - onMounted(() => { toast.loading({ msg: '加载中...' @@ -41,7 +35,9 @@ onMounted(() => { acc[cur.m_lesson_name].push(cur) return acc }, {}) - groupLessons.value = groupData + groupedLessons.value = groupData + }).catch(err => { + toast.error({ msg: err.message }) }) }) @@ -50,19 +46,21 @@ onMounted(() => {
- - + +
- -
+
- - {{ course.course_name || '无标题视频' }} + + {{ lesson.course_name || '无标题视频' }}
- +
diff --git a/src/pages/lesson/index.vue b/src/pages/lesson/index.vue index d9964ce..147befb 100644 --- a/src/pages/lesson/index.vue +++ b/src/pages/lesson/index.vue @@ -1,14 +1,17 @@ - + diff --git a/src/utils/lesson.ts b/src/utils/lesson.ts new file mode 100644 index 0000000..1c42b4b --- /dev/null +++ b/src/utils/lesson.ts @@ -0,0 +1,48 @@ +import type { Lesson } from "@/types/api/lesson"; + +export const extractLessonStage = (lesson: Lesson) => { + const stages = { + script_upload: !!lesson?.script_upload_time, + script_confirm: !!lesson?.script_confirm_time, + video_capture: !!lesson?.video_capture_time, + post_production: !!lesson?.video_confirm_time, + step: 0, + }; + stages.step = Object.values(stages).filter((v) => v).length; + return stages; +}; + +export const calcLessonProgress = (lesson: Lesson, total: number = 4) => { + const progress = extractLessonStage(lesson); + return Math.floor((progress.step / total) * 100); +}; + +export const getLessonSteps = (lesson: Lesson) => { + const progress = extractLessonStage(lesson); + return [ + { + title: progress.script_upload ? "脚本文件上传" : undefined, + description: progress.script_upload + ? `已于 ${lesson.script_upload_time} 完成上传` + : "脚本文件上传", + }, + { + title: progress.script_confirm ? "脚本文件确认" : undefined, + description: progress.script_confirm + ? `已于 ${lesson.script_confirm_time} 确认` + : "脚本文件确认", + }, + { + title: progress.video_capture ? "视频拍摄和上传" : undefined, + description: progress.video_capture + ? `已于 ${lesson.video_capture_time} 完成上传` + : "视频拍摄上传", + }, + { + title: progress.post_production ? "视频后期制作" : undefined, + description: progress.post_production + ? `已于 ${lesson.video_confirm_time} 完成上传` + : "视频后期制作", + }, + ]; +};