From 2af1109ceddfd706973d2b78e868c841c56c4aa9 Mon Sep 17 00:00:00 2001 From: yuetsh <517252939@qq.com> Date: Tue, 4 Mar 2025 08:52:28 +0800 Subject: [PATCH] update --- src/App.vue | 5 +++-- src/api.ts | 4 ++-- src/components/Login.vue | 2 +- src/components/Tutorial.vue | 3 ++- src/pages/Markdown.vue | 3 ++- src/router.ts | 3 ++- src/store/editors.ts | 11 ++++++----- src/utils/const.ts | 11 +++++++++++ 8 files changed, 29 insertions(+), 13 deletions(-) diff --git a/src/App.vue b/src/App.vue index bf07912..c1d0b06 100644 --- a/src/App.vue +++ b/src/App.vue @@ -4,6 +4,7 @@ import Login from "./components/Login.vue" import { onMounted, watch } from "vue" import { Account } from "./api" import { authed, user } from "./store/user" +import { STORAGE_KEY } from "./utils/const" onMounted(async () => { const data = await Account.getMyProfile() @@ -14,9 +15,9 @@ onMounted(async () => { watch(authed, (v) => { if (v) { - localStorage.setItem("web-isloggedin", "true") + localStorage.setItem(STORAGE_KEY.LOGIN, "true") } else { - localStorage.removeItem("web-isloggedin") + localStorage.removeItem(STORAGE_KEY.LOGIN) } }) diff --git a/src/api.ts b/src/api.ts index b7f8a15..1c42dcd 100644 --- a/src/api.ts +++ b/src/api.ts @@ -1,6 +1,7 @@ import axios from "axios" import { router } from "./router" import type { TutorialIn } from "./utils/type" +import { STORAGE_KEY } from "./utils/const" const http = axios.create({ baseURL: @@ -20,8 +21,7 @@ http.interceptors.response.use( if (err.response) { switch (err.response.status) { case 401: // 未授权 - localStorage.removeItem("web-isloggedin") - alert("未登录") + localStorage.removeItem(STORAGE_KEY.LOGIN) router.push("/") break case 403: // 禁止访问 diff --git a/src/components/Login.vue b/src/components/Login.vue index 94079f6..217e369 100644 --- a/src/components/Login.vue +++ b/src/components/Login.vue @@ -20,7 +20,7 @@ type="error" v-if="showMeesage" class="message" - title="登录失败" + title="登录失败,请检查用户名和密码" > 登录 diff --git a/src/components/Tutorial.vue b/src/components/Tutorial.vue index 84388c9..44b1be9 100644 --- a/src/components/Tutorial.vue +++ b/src/components/Tutorial.vue @@ -22,8 +22,9 @@ import { computed, onMounted, ref, useTemplateRef, watch } from "vue" import { marked } from "marked" import { useStorage } from "@vueuse/core" import { Tutorial } from "../api" +import { STORAGE_KEY } from "../utils/const" -const step = useStorage("web-turtorial-step", 1) +const step = useStorage(STORAGE_KEY.STEP, 1) const displays = ref([]) const content = ref("") const $content = useTemplateRef("$content") diff --git a/src/pages/Markdown.vue b/src/pages/Markdown.vue index 2fa41ea..a4d1476 100644 --- a/src/pages/Markdown.vue +++ b/src/pages/Markdown.vue @@ -73,13 +73,14 @@ import { useStorage } from "@vueuse/core" import { Tutorial } from "../api" import type { TutorialSlim } from "../utils/type" import { useDialog, useMessage } from "naive-ui" +import { STORAGE_KEY } from "../utils/const" const message = useMessage() const confirm = useDialog() const list = ref([]) const content = ref("") -const tutorial = useStorage("web-tutorial", { +const tutorial = useStorage(STORAGE_KEY.TUTORIAL, { display: 0, title: "", content: "", diff --git a/src/router.ts b/src/router.ts index 0d9e92f..d383e2b 100644 --- a/src/router.ts +++ b/src/router.ts @@ -2,6 +2,7 @@ import { createWebHistory, createRouter } from "vue-router" import { loginModal } from "./store/modal" import Home from "./pages/Home.vue" +import { STORAGE_KEY } from "./utils/const" const routes = [ { path: "/", name: "home", component: Home }, @@ -26,7 +27,7 @@ export const router = createRouter({ }) router.beforeEach((to, from, next) => { - const isLoggedIn = localStorage.getItem("web-isloggedin") === "true" + const isLoggedIn = localStorage.getItem(STORAGE_KEY.LOGIN) === "true" if (to.meta.auth && !isLoggedIn) { loginModal.value = true next(false) diff --git a/src/store/editors.ts b/src/store/editors.ts index dc66fd0..b376ffb 100644 --- a/src/store/editors.ts +++ b/src/store/editors.ts @@ -1,4 +1,5 @@ import { useStorage } from "@vueuse/core" +import { STORAGE_KEY } from "../utils/const" const defaultHTML = `
黄岩一职
` const defaultCSS = `.welcome { @@ -6,12 +7,12 @@ const defaultCSS = `.welcome { font-size: 24px; }` -export const html = useStorage("web-html", defaultHTML) -export const css = useStorage("web-css", defaultCSS) -export const js = useStorage("web-js", "") +export const html = useStorage(STORAGE_KEY.HTML, defaultHTML) +export const css = useStorage(STORAGE_KEY.CSS, defaultCSS) +export const js = useStorage(STORAGE_KEY.JS, "") -export const tab = useStorage("web-tab", "html") -export const size = useStorage("web-fontsize", 24) +export const tab = useStorage(STORAGE_KEY.TAB, "html") +export const size = useStorage(STORAGE_KEY.FONTSIZE, 24) export function reset(lang: "html" | "css" | "js") { if (lang === "html") { diff --git a/src/utils/const.ts b/src/utils/const.ts index fb27634..c58af77 100644 --- a/src/utils/const.ts +++ b/src/utils/const.ts @@ -25,3 +25,14 @@ export const alertVariants = [ title: "小心", }, ] + +export const STORAGE_KEY = { + LOGIN: "web-isloggedin", + STEP: "web-turtorial-step", + TUTORIAL: "web-tutorial", + HTML: "web-html", + CSS: "web-css", + JS: "web-js", + TAB: "web-tab", + FONTSIZE: "web-fontsize", +} \ No newline at end of file