refactor(router): 移除笔记路由并重构URL生成方法
- 移除了笔记路由,暂时禁用相关的noteRoute()函数。 - 重构了getCardUrl()和getNoteUrl()方法,使用URL构造器以增强可读性和可维护性。 - 在cardRoute()和noteRoute()中,将user_name从路由参数中移除,现在通过查询参数处理。
This commit is contained in:
parent
3325d5aacc
commit
f3ccb0361a
@ -29,7 +29,7 @@ let { card, idx } = defineProps<{
|
|||||||
|
|
||||||
function getRealHref(href: string, user_name: string = "$") {
|
function getRealHref(href: string, user_name: string = "$") {
|
||||||
if (href.startsWith('$')) {
|
if (href.startsWith('$')) {
|
||||||
href = `/card/${user_name}${href.substring(1)}`;
|
href = `/card${href.substring(1)}?user_name=${user_name}`;
|
||||||
}
|
}
|
||||||
return href;
|
return href;
|
||||||
}
|
}
|
||||||
|
@ -1,30 +1,31 @@
|
|||||||
import { type RouteRecordRaw } from "vue-router";
|
import { type RouteRecordRaw } from "vue-router";
|
||||||
import { file_api } from "./config.json";
|
import { file_api } from "./config.json";
|
||||||
|
|
||||||
export function getCardUrl(path: string = file_api.cards.home): string {
|
export function getCardUrl(path: string = file_api.cards.home, query: Record<string, string> = {}): string {
|
||||||
return `${file_api.root_url}/` +
|
const url = new URL(window.location.origin);
|
||||||
`${file_api.cards.url}/` +
|
url.pathname = `${file_api.root_url}/${file_api.cards.url}/${path}`;
|
||||||
`${path}?` +
|
|
||||||
`type=${file_api.cards.type}`
|
url.searchParams.set('type', file_api.cards.type);
|
||||||
|
Object.entries(query).forEach(([key, value]) => {
|
||||||
|
url.searchParams.set(key, value);
|
||||||
|
})
|
||||||
|
return url.toString();
|
||||||
};
|
};
|
||||||
|
|
||||||
export default function cardRoute(): RouteRecordRaw {
|
export default function cardRoute(): RouteRecordRaw {
|
||||||
return {
|
return {
|
||||||
name: "cardShower",
|
name: "cardShower",
|
||||||
path: "/card/:user_name/:pages_path*",
|
path: "/card/:pages_path*",
|
||||||
component: () => import("@/pages/CardsShower.vue"),
|
component: () => import("@/pages/CardsShower.vue"),
|
||||||
props(to) {
|
props(to) {
|
||||||
let path: string;
|
const path = Array.isArray(to.params.pages_path)
|
||||||
if (Array.isArray(to.params.pages_path)) {
|
? to.params.pages_path.join("/")
|
||||||
path = to.params.pages_path.join("/");
|
: to.params.pages_path;
|
||||||
} else {
|
|
||||||
path = to.params.pages_path;
|
|
||||||
}
|
|
||||||
|
|
||||||
return {
|
return {
|
||||||
...to.params,
|
...to.params,
|
||||||
path,
|
path,
|
||||||
url: getCardUrl(path),
|
url: getCardUrl(path, to.query as Record<string, string>),
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
@ -26,7 +26,7 @@ const router = createRouter({
|
|||||||
component: () => import("@/pages/Users.vue"),
|
component: () => import("@/pages/Users.vue"),
|
||||||
},
|
},
|
||||||
cardRoute(),
|
cardRoute(),
|
||||||
noteRoute(),
|
// noteRoute(),
|
||||||
// {
|
// {
|
||||||
// name: "noteShower",
|
// name: "noteShower",
|
||||||
// path: "/note/:note_name/:token?",
|
// path: "/note/:note_name/:token?",
|
||||||
|
@ -1,11 +1,15 @@
|
|||||||
import { type RouteRecordRaw } from "vue-router";
|
import { type RouteRecordRaw } from "vue-router";
|
||||||
import { file_api } from "./config.json";
|
import { file_api } from "./config.json";
|
||||||
|
|
||||||
export function getNoteUrl(path: string = file_api.cards.home): string {
|
export function getNoteUrl(path: string = file_api.cards.home, query: Record<string, string> = {}): string {
|
||||||
return `${file_api.root_url}/` +
|
const url = new URL(window.location.origin);
|
||||||
`${file_api.notes.url}/` +
|
url.pathname = `${file_api.root_url}/${file_api.notes.url}/${path}`;
|
||||||
`${path}?` +
|
|
||||||
`type=${file_api.notes.type}`
|
url.searchParams.set('type', file_api.notes.type);
|
||||||
|
Object.entries(query).forEach(([key, value]) => {
|
||||||
|
url.searchParams.set(key, value);
|
||||||
|
})
|
||||||
|
return url.toString();
|
||||||
};
|
};
|
||||||
|
|
||||||
export default function noteRoute(): RouteRecordRaw {
|
export default function noteRoute(): RouteRecordRaw {
|
||||||
@ -14,18 +18,15 @@ export default function noteRoute(): RouteRecordRaw {
|
|||||||
path: "/note/:pages_path*",
|
path: "/note/:pages_path*",
|
||||||
component: () => import("@/pages/NoteShower.vue"),
|
component: () => import("@/pages/NoteShower.vue"),
|
||||||
props(to) {
|
props(to) {
|
||||||
let path: string;
|
const path = Array.isArray(to.params.pages_path)
|
||||||
if (Array.isArray(to.params.pages_path)) {
|
? to.params.pages_path.join("/")
|
||||||
path = to.params.pages_path.join("/");
|
: to.params.pages_path;
|
||||||
} else {
|
|
||||||
path = to.params.pages_path;
|
|
||||||
}
|
|
||||||
|
|
||||||
return {
|
return {
|
||||||
...to.params,
|
...to.params,
|
||||||
path,
|
path,
|
||||||
url: getNoteUrl(path),
|
url: getNoteUrl(path, to.query as Record<string, string>),
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
x
Reference in New Issue
Block a user