From dc0e2809ec0fd70b6957c197f579f0e84fa87fc9 Mon Sep 17 00:00:00 2001 From: cuixiaorui Date: Thu, 25 Jan 2024 21:02:59 +0800 Subject: [PATCH] refactor: extract core code --- apps/client/api/courses.ts | 8 +- .../{Footer/index.vue => Footer.vue} | 0 .../{Navbar/index.vue => Navbar.vue} | 84 ++++++++++--------- .../index.vue => courses/CourseCard.vue} | 14 ++-- apps/client/components/main/Answer.vue | 25 ++---- .../client/components/main/CourseProgress.vue | 14 +--- apps/client/components/main/Game.vue | 6 +- apps/client/components/main/Question.vue | 7 +- apps/client/components/main/Summary.vue | 69 +++++++++------ apps/client/components/main/Tips.vue | 7 +- apps/client/components/main/Tool.vue | 26 ++++-- .../englishSound.ts} | 5 +- .../{components => composables}/main/game.ts | 2 +- .../main/summary.ts | 0 apps/client/layouts/default.vue | 6 +- apps/client/pages/Courses.vue | 33 ++------ apps/client/pages/Main/[id].vue | 3 - apps/client/store/course.ts | 14 +++- apps/client/store/todo.ts | 12 --- 19 files changed, 157 insertions(+), 178 deletions(-) rename apps/client/components/{Footer/index.vue => Footer.vue} (100%) rename apps/client/components/{Navbar/index.vue => Navbar.vue} (75%) rename apps/client/components/{CourseItemCard/index.vue => courses/CourseCard.vue} (95%) rename apps/client/composables/{useEnglishSound.ts => main/englishSound.ts} (86%) rename apps/client/{components => composables}/main/game.ts (88%) rename apps/client/{components => composables}/main/summary.ts (100%) delete mode 100644 apps/client/store/todo.ts diff --git a/apps/client/api/courses.ts b/apps/client/api/courses.ts index 01f79fe74..3013534fd 100644 --- a/apps/client/api/courses.ts +++ b/apps/client/api/courses.ts @@ -1,5 +1,4 @@ -import { type Course } from "~/store/course-new"; -import { useFetchPlus } from "~/composables/useFetch"; +import { type Course } from "~/store/course"; import { http } from "./http"; export async function fetchCourse(courseId: number) { @@ -8,9 +7,4 @@ export async function fetchCourse(courseId: number) { export async function fetchNextCourse(courseId: number) { return await http.get(`/courses/${courseId}/next`); - // const { data: courses } = await useFetchPlus( - // `/courses/${courseId}/next` - // ); - - // return courses.value; } diff --git a/apps/client/components/Footer/index.vue b/apps/client/components/Footer.vue similarity index 100% rename from apps/client/components/Footer/index.vue rename to apps/client/components/Footer.vue diff --git a/apps/client/components/Navbar/index.vue b/apps/client/components/Navbar.vue similarity index 75% rename from apps/client/components/Navbar/index.vue rename to apps/client/components/Navbar.vue index 5d6b973ea..87b66f96b 100644 --- a/apps/client/components/Navbar/index.vue +++ b/apps/client/components/Navbar.vue @@ -1,3 +1,45 @@ + + - - \ No newline at end of file + \ No newline at end of file diff --git a/apps/client/components/CourseItemCard/index.vue b/apps/client/components/courses/CourseCard.vue similarity index 95% rename from apps/client/components/CourseItemCard/index.vue rename to apps/client/components/courses/CourseCard.vue index a31c88df3..887f0c8bf 100644 --- a/apps/client/components/CourseItemCard/index.vue +++ b/apps/client/components/courses/CourseCard.vue @@ -1,13 +1,13 @@ - - \ No newline at end of file + + + \ No newline at end of file diff --git a/apps/client/components/main/Answer.vue b/apps/client/components/main/Answer.vue index 711d97cfc..53af8ce71 100644 --- a/apps/client/components/main/Answer.vue +++ b/apps/client/components/main/Answer.vue @@ -2,17 +2,11 @@
{{ courseStore.currentStatement?.english }} - + + fill="#666666">
@@ -20,8 +14,7 @@
@@ -30,8 +23,9 @@ -~/store/course-new + \ No newline at end of file diff --git a/apps/client/components/main/CourseProgress.vue b/apps/client/components/main/CourseProgress.vue index 3fe006938..1090e1723 100644 --- a/apps/client/components/main/CourseProgress.vue +++ b/apps/client/components/main/CourseProgress.vue @@ -1,23 +1,15 @@ - - -~/store/course~/store/course-new \ No newline at end of file diff --git a/apps/client/components/main/Game.vue b/apps/client/components/main/Game.vue index f73d98481..1240f7394 100644 --- a/apps/client/components/main/Game.vue +++ b/apps/client/components/main/Game.vue @@ -22,9 +22,9 @@ import Answer from "./Answer.vue"; import CourseProgress from "./CourseProgress.vue"; import Summary from "./Summary.vue"; import Tips from "./Tips.vue"; -import { useMode } from "./game"; +import { useGameMode } from "~/composables/main/game"; -const { mode } = useMode(); +const { mode } = useGameMode(); - + \ No newline at end of file diff --git a/apps/client/components/main/Question.vue b/apps/client/components/main/Question.vue index 9ad3f6787..fb62c7bdd 100644 --- a/apps/client/components/main/Question.vue +++ b/apps/client/components/main/Question.vue @@ -36,7 +36,7 @@ - -~/store/course~/store/course-new \ No newline at end of file + \ No newline at end of file diff --git a/apps/client/components/main/Tips.vue b/apps/client/components/main/Tips.vue index b7e6e3c11..b1c16d96a 100644 --- a/apps/client/components/main/Tips.vue +++ b/apps/client/components/main/Tips.vue @@ -12,8 +12,9 @@ + \ No newline at end of file diff --git a/apps/client/components/main/Tool.vue b/apps/client/components/main/Tool.vue index 9427ef6fd..f58418868 100644 --- a/apps/client/components/main/Tool.vue +++ b/apps/client/components/main/Tool.vue @@ -3,7 +3,7 @@
更多课程
-
{{ coursesStore.currentCourse.title }}
+
{{ coursesStore.currentCourse?.title }}
@@ -12,16 +12,24 @@ - -~/store/course~/store/course-new \ No newline at end of file + + diff --git a/apps/client/composables/useEnglishSound.ts b/apps/client/composables/main/englishSound.ts similarity index 86% rename from apps/client/composables/useEnglishSound.ts rename to apps/client/composables/main/englishSound.ts index bd38e80bd..7f6d928cc 100644 --- a/apps/client/composables/useEnglishSound.ts +++ b/apps/client/composables/main/englishSound.ts @@ -18,8 +18,7 @@ export function useCurrentStatementEnglishSound() { const coursesStore = useCourseStore(); watchEffect(() => { - word.value = coursesStore.currentStatement?.english; - console.log(word) + word.value = coursesStore.currentStatement?.english || ""; }); const sound = useEnglishSound(word); @@ -28,5 +27,3 @@ export function useCurrentStatementEnglishSound() { sound, }; } - - diff --git a/apps/client/components/main/game.ts b/apps/client/composables/main/game.ts similarity index 88% rename from apps/client/components/main/game.ts rename to apps/client/composables/main/game.ts index a0039945c..2424ce914 100644 --- a/apps/client/components/main/game.ts +++ b/apps/client/composables/main/game.ts @@ -1,6 +1,6 @@ const mode = ref<"question" | "answer">("question"); -export function useMode() { +export function useGameMode() { function showAnswer() { mode.value = "answer"; } diff --git a/apps/client/components/main/summary.ts b/apps/client/composables/main/summary.ts similarity index 100% rename from apps/client/components/main/summary.ts rename to apps/client/composables/main/summary.ts diff --git a/apps/client/layouts/default.vue b/apps/client/layouts/default.vue index b973e3876..cae0eb1e9 100644 --- a/apps/client/layouts/default.vue +++ b/apps/client/layouts/default.vue @@ -1,7 +1,3 @@ - - \ No newline at end of file + diff --git a/apps/client/pages/Courses.vue b/apps/client/pages/Courses.vue index ca2824059..2372dd4f6 100644 --- a/apps/client/pages/Courses.vue +++ b/apps/client/pages/Courses.vue @@ -2,38 +2,23 @@
- - - + + +

English Course

-
    +