This commit is contained in:
fengchuanhn@gmail.com
2026-05-15 19:08:03 +08:00
parent 28b2b4d686
commit 9d2c592127
9 changed files with 946 additions and 31 deletions

View File

@@ -1,12 +1,68 @@
import { createRouter, createWebHistory } from "vue-router";
import { useAuthStore } from "../stores/auth";
const placeholder = () => import("../views/PlaceholderView.vue");
const routes = [
{
path: "/",
name: "home",
component: () => import("../views/HomeView.vue"),
component: () => import("../layouts/MainLayout.vue"),
meta: { requiresAuth: true },
children: [
{
path: "",
name: "home",
component: () => import("../views/HomeView.vue"),
},
{
path: "avatar",
name: "avatar",
component: placeholder,
meta: { title: "形象" },
},
{
path: "material",
name: "material",
component: placeholder,
meta: { title: "素材" },
},
{
path: "voice",
name: "voice",
component: placeholder,
meta: { title: "声音" },
},
{
path: "compose",
name: "compose",
component: placeholder,
meta: { title: "合成" },
},
{
path: "extract",
name: "extract",
component: placeholder,
meta: { title: "提取" },
},
{
path: "design",
name: "design",
component: placeholder,
meta: { title: "设计" },
},
{
path: "model",
name: "model",
component: placeholder,
meta: { title: "模型" },
},
{
path: "help",
name: "help",
component: placeholder,
meta: { title: "帮助" },
},
],
},
{
path: "/login",
@@ -31,8 +87,9 @@ const router = createRouter({
router.beforeEach((to) => {
const auth = useAuthStore();
const requiresAuth = to.matched.some((record) => record.meta.requiresAuth);
if (to.meta.requiresAuth && !auth.isAuthenticated) {
if (requiresAuth && !auth.isAuthenticated) {
return { name: "login" };
}