From 53287e4cbd57e8ccfd1afcc95a1ef3c59a5b83b6 Mon Sep 17 00:00:00 2001 From: HoshinoSuzumi Date: Thu, 19 Sep 2024 15:13:42 +0800 Subject: [PATCH] feat: Add "lesson" page and related components This commit adds a new "lesson" page along with the necessary components and types. The "lesson" page displays the details of a specific lesson and includes a dynamic route parameter for the lesson name. Additionally, the commit includes updates to the `pages.json` file to configure the navigation bar title for the "lesson" page. --- components.d.ts | 3 ++ src/api/BussApi.ts | 16 ++++++ src/http/HttpClient.ts | 7 ++- src/pages.json | 7 +++ src/pages/index/index.vue | 101 +++++++++++++++++++++++-------------- src/pages/lesson/index.vue | 16 ++++++ src/pages/login/index.vue | 3 ++ src/pages/my/index.vue | 6 +++ src/types/api/common.ts | 26 ++++++++++ src/types/api/lesson.ts | 17 +++++++ 10 files changed, 163 insertions(+), 39 deletions(-) create mode 100644 src/pages/lesson/index.vue create mode 100644 src/types/api/common.ts create mode 100644 src/types/api/lesson.ts diff --git a/components.d.ts b/components.d.ts index 9a60117..6e917f9 100644 --- a/components.d.ts +++ b/components.d.ts @@ -12,8 +12,11 @@ declare module 'vue' { WdButton: typeof import('wot-design-uni/components/wd-button/wd-button.vue')['default'] WdCell: typeof import('wot-design-uni/components/wd-cell/wd-cell.vue')['default'] WdCellGroup: typeof import('wot-design-uni/components/wd-cell-group/wd-cell-group.vue')['default'] + WdCollapse: typeof import('wot-design-uni/components/wd-collapse/wd-collapse.vue')['default'] + WdCollapseItem: typeof import('wot-design-uni/components/wd-collapse-item/wd-collapse-item.vue')['default'] WdForm: typeof import('wot-design-uni/components/wd-form/wd-form.vue')['default'] 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'] 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/api/BussApi.ts b/src/api/BussApi.ts index a581b64..fbc9d1c 100644 --- a/src/api/BussApi.ts +++ b/src/api/BussApi.ts @@ -1,4 +1,7 @@ import http from "@/http/HttpClient"; +import { useUser } from "@/stores/useUser"; +import type { PagedData } from "@/types/api/common"; +import type { Lesson } from "@/types/api/lesson"; import type { User } from "@/types/api/user"; export interface LoginRequest extends Record { @@ -25,4 +28,17 @@ export default class BussApi { }) .then((res) => res.data); } + + static lessons(page: number = 1, limit: number = 20): Promise> { + const user = useUser(); + return http + .server() + .get("/lesson/task", { + headers: { + Authorization: `Bearer ${user.token}`, + }, + params: { page, limit }, + }) + .then((res) => res.data); + } } diff --git a/src/http/HttpClient.ts b/src/http/HttpClient.ts index 2aaeb02..6cf71a8 100644 --- a/src/http/HttpClient.ts +++ b/src/http/HttpClient.ts @@ -38,9 +38,12 @@ export default class ApiClient { if (response.data.code === 10001) { const pages = getCurrentPages() as any[]; const user = useUser(); - user.logout(); setTimeout(() => { - uni.showToast({ title: "登录已过期,请重新登录", icon: "none" }); + uni.showToast({ + title: !!user.token ? "登录已过期,请重新登录" : "请先登录", + icon: "none", + }); + user.logout(); }, 300); if ( !pages[pages.length - 1].$page || diff --git a/src/pages.json b/src/pages.json index d9241a7..b483a98 100644 --- a/src/pages.json +++ b/src/pages.json @@ -20,6 +20,13 @@ "style": { "navigationBarTitleText": "登录" } + }, + { + "name": "lesson", + "path": "pages/lesson/index", + "style": { + "navigationBarTitleText": "课程进度" + } } ], "tabBar": { diff --git a/src/pages/index/index.vue b/src/pages/index/index.vue index 3542545..facab9f 100644 --- a/src/pages/index/index.vue +++ b/src/pages/index/index.vue @@ -1,43 +1,70 @@ + + - - - + diff --git a/src/pages/lesson/index.vue b/src/pages/lesson/index.vue new file mode 100644 index 0000000..01d7836 --- /dev/null +++ b/src/pages/lesson/index.vue @@ -0,0 +1,16 @@ + + + + + diff --git a/src/pages/login/index.vue b/src/pages/login/index.vue index 76e2df1..2f4e132 100644 --- a/src/pages/login/index.vue +++ b/src/pages/login/index.vue @@ -1,6 +1,7 @@