From a7d8663f4d1d678d9ee82a953d513cbaafdf9fd8 Mon Sep 17 00:00:00 2001 From: yuetsh <517252939@qq.com> Date: Mon, 3 Mar 2025 22:11:01 +0800 Subject: [PATCH] =?UTF-8?q?=E5=90=8E=E5=8F=B0=E6=95=99=E7=A8=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- components.d.ts | 6 ++ src/App.vue | 10 +-- src/api.ts | 46 ++++++++++--- src/components/Editors.vue | 6 +- src/components/Login.vue | 4 +- src/pages/Dashboard.vue | 29 +++++++- src/pages/Markdown.vue | 135 +++++++++++++++++++++++++++++++++++++ src/router.ts | 9 ++- src/utils/type.ts | 12 ++++ 9 files changed, 235 insertions(+), 22 deletions(-) create mode 100644 src/pages/Markdown.vue diff --git a/components.d.ts b/components.d.ts index 670fe3f..461db47 100644 --- a/components.d.ts +++ b/components.d.ts @@ -13,11 +13,17 @@ declare module 'vue' { Login: typeof import('./src/components/Login.vue')['default'] NAlert: typeof import('naive-ui')['NAlert'] NButton: typeof import('naive-ui')['NButton'] + NCard: typeof import('naive-ui')['NCard'] NConfigProvider: typeof import('naive-ui')['NConfigProvider'] + NDialog: typeof import('naive-ui')['NDialog'] + NDialogProvider: typeof import('naive-ui')['NDialogProvider'] NDropdown: typeof import('naive-ui')['NDropdown'] NFlex: typeof import('naive-ui')['NFlex'] NForm: typeof import('naive-ui')['NForm'] NFormItem: typeof import('naive-ui')['NFormItem'] + NGi: typeof import('naive-ui')['NGi'] + NGrid: typeof import('naive-ui')['NGrid'] + NIcon: typeof import('naive-ui')['NIcon'] NInput: typeof import('naive-ui')['NInput'] NMessageProvider: typeof import('naive-ui')['NMessageProvider'] NModal: typeof import('naive-ui')['NModal'] diff --git a/src/App.vue b/src/App.vue index 5df9a0d..bf07912 100644 --- a/src/App.vue +++ b/src/App.vue @@ -2,11 +2,11 @@ import { dateZhCN, zhCN } from "naive-ui" import Login from "./components/Login.vue" import { onMounted, watch } from "vue" -import { getMyProfile } from "./api" +import { Account } from "./api" import { authed, user } from "./store/user" onMounted(async () => { - const data = await getMyProfile() + const data = await Account.getMyProfile() user.loaded = true user.username = data.username user.role = data.role @@ -25,8 +25,10 @@ watch(authed, (v) => { - - + + + + diff --git a/src/api.ts b/src/api.ts index d58a81b..8e80685 100644 --- a/src/api.ts +++ b/src/api.ts @@ -1,5 +1,6 @@ import axios from "axios" import { router } from "./router" +import type { TutorialIn } from "./utils/type" const http = axios.create({ baseURL: @@ -30,23 +31,46 @@ http.interceptors.response.use( console.error("出现错误:", err.response.status, err.response.data) } } else { - console.error("Network error:", err.message) + console.error("出现错误:", err.message) } return Promise.reject(err) }, ) -export async function login(username: string, password: string) { - const res = await http.post("/account/login", { username, password }) - return res.data +export class Account { + static async login(username: string, password: string) { + const res = await http.post("/account/login", { username, password }) + return res.data + } + + static async logout() { + const res = await http.post("/account/logout") + return res.data + } + + static async getMyProfile() { + const res = await http.get("/account/profile") + return res.data + } } -export async function logout() { - const res = await http.post("/account/logout") - return res.data -} +export class Tutorial { + static async list() { + const res = await http.get("/tutorial/") + return res.data + } -export async function getMyProfile() { - const res = await http.get("/account/profile") - return res.data + static async create(payload: TutorialIn) { + const res = await http.post("/tutorial/", payload) + return res.data + } + + static async remove(display: string) { + await http.delete(`/tutorial/${display}`) + } + + static async get(display: string) { + const res = await http.get(`/tutorial/${display}`) + return res.data + } } diff --git a/src/components/Editors.vue b/src/components/Editors.vue index c36e7e7..9946ccc 100644 --- a/src/components/Editors.vue +++ b/src/components/Editors.vue @@ -92,7 +92,7 @@ import Editor from "./Editor.vue" import { html, css, js, tab, size, reset } from "../store/editors" import { user, authed, roleNormal } from "../store/user" import { loginModal } from "../store/modal" -import { logout } from "../api" +import { Account } from "../api" import { Role } from "../utils/type" import { router } from "../router" import { computed, h } from "vue" @@ -123,7 +123,7 @@ const menu = computed(() => [ function clickMenu(name: string) { switch (name) { case "dashboard": - router.push({ name: "dashboard" }) + router.push({ name: "tutorial" }) break case "logout": handleLogout() @@ -144,7 +144,7 @@ function handleLogin() { } async function handleLogout() { - await logout() + await Account.logout() user.username = "" user.role = Role.Normal } diff --git a/src/components/Login.vue b/src/components/Login.vue index b2097b1..94079f6 100644 --- a/src/components/Login.vue +++ b/src/components/Login.vue @@ -30,7 +30,7 @@ + diff --git a/src/pages/Markdown.vue b/src/pages/Markdown.vue new file mode 100644 index 0000000..45e7b4a --- /dev/null +++ b/src/pages/Markdown.vue @@ -0,0 +1,135 @@ + + + diff --git a/src/router.ts b/src/router.ts index 3195bfc..0d9e92f 100644 --- a/src/router.ts +++ b/src/router.ts @@ -4,12 +4,19 @@ import { loginModal } from "./store/modal" import Home from "./pages/Home.vue" const routes = [ - { path: "/", component: Home }, + { path: "/", name: "home", component: Home }, { path: "/dashboard", name: "dashboard", component: () => import("./pages/Dashboard.vue"), meta: { auth: true }, + children: [ + { + path: "tutorial", + name: "tutorial", + component: () => import("./pages/Markdown.vue"), + }, + ], }, ] diff --git a/src/utils/type.ts b/src/utils/type.ts index 6e02bc7..6a33a02 100644 --- a/src/utils/type.ts +++ b/src/utils/type.ts @@ -3,3 +3,15 @@ export enum Role { Admin = "admin", Normal = "normal", } + +export interface TutorialSlim { + display: string + title: string + is_public: boolean +} + +export interface TutorialIn { + display: string + title: string + content: string +}