From 3325d5aacca17e1a410cbfd41402fee2c8563334 Mon Sep 17 00:00:00 2001 From: ZZY <2450266535@qq.com> Date: Sun, 1 Sep 2024 23:48:22 +0800 Subject: [PATCH] =?UTF-8?q?refactor(NoteShower):=20=E4=BD=BF=E7=94=A8?= =?UTF-8?q?=E8=B7=AF=E5=BE=84=E5=92=8CURL=E5=B1=9E=E6=80=A7=E6=9B=BF?= =?UTF-8?q?=E6=8D=A2note=5Fname=E5=92=8Ctoken?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 在NoteShower组件中,props从['note_name', 'token']被修改为['path', 'url']以更好地与路由配置对齐。这一改变是为了适应新的路由结构,其中note_name和token已被弃用,并被包含在props路由参数中。 refactor(router): 添加noteRoute命名空间并移除NoteShower路由配置 从主路由配置中移除独立的NoteShower路由,并将其移至新的noteRoute命名空间下。此更改实现了路由配置的模块化,使notes相关路由能够在一个独立的命名空间内进行管理和维护。 --- src/pages/NoteShower.vue | 4 ++-- src/router/index.ts | 24 +++++++++++++----------- src/router/note.ts | 31 +++++++++++++++++++++++++++++++ 3 files changed, 46 insertions(+), 13 deletions(-) create mode 100644 src/router/note.ts diff --git a/src/pages/NoteShower.vue b/src/pages/NoteShower.vue index 0624c9c..0e60d12 100644 --- a/src/pages/NoteShower.vue +++ b/src/pages/NoteShower.vue @@ -7,10 +7,10 @@ import FetchWrapper from "@/components/utils/FetchWapper"; import { file_api } from '@/router/config.json'; -const props = defineProps(['note_name', 'token']) +const props = defineProps(['path', 'url']) onMounted(() => { - FetchWrapper.fetch(`${file_api.root_url}/${file_api.notes.url}/${props.note_name}?type=${file_api.notes.type}`, + FetchWrapper.fetch(props.url, { timeout: 3000, headers: { diff --git a/src/router/index.ts b/src/router/index.ts index 912df44..4b65e2b 100644 --- a/src/router/index.ts +++ b/src/router/index.ts @@ -1,5 +1,6 @@ import { createRouter, createWebHistory } from "vue-router"; import cardRoute from "./card"; +import noteRoute from "./note"; const router = createRouter({ history: createWebHistory(), @@ -25,17 +26,18 @@ const router = createRouter({ component: () => import("@/pages/Users.vue"), }, cardRoute(), - { - name: "noteShower", - path: "/note/:note_name/:token?", - component: () => import("@/pages/NoteShower.vue"), - props: true, - // props(route) { - // return { - // ...route.params - // } - // }, - }, + noteRoute(), + // { + // name: "noteShower", + // path: "/note/:note_name/:token?", + // component: () => import("@/pages/NoteShower.vue"), + // props: true, + // // props(route) { + // // return { + // // ...route.params + // // } + // // }, + // }, { name: 'notFound', path: "/:any*", // 使用正则表达式匹配所有路径 diff --git a/src/router/note.ts b/src/router/note.ts new file mode 100644 index 0000000..8bfc6e6 --- /dev/null +++ b/src/router/note.ts @@ -0,0 +1,31 @@ +import { type RouteRecordRaw } from "vue-router"; +import { file_api } from "./config.json"; + +export function getNoteUrl(path: string = file_api.cards.home): string { + return `${file_api.root_url}/` + + `${file_api.notes.url}/` + + `${path}?` + + `type=${file_api.notes.type}` +}; + +export default function noteRoute(): RouteRecordRaw { + return { + name: "cardShower", + path: "/note/:pages_path*", + component: () => import("@/pages/NoteShower.vue"), + props(to) { + let path: string; + if (Array.isArray(to.params.pages_path)) { + path = to.params.pages_path.join("/"); + } else { + path = to.params.pages_path; + } + + return { + ...to.params, + path, + url: getNoteUrl(path), + } + }, + } +}