上传文件至 src/router
This commit is contained in:
103
src/router/index.ts
Normal file
103
src/router/index.ts
Normal file
@ -0,0 +1,103 @@
|
|||||||
|
import { createRouter, createWebHistory, RouteRecordRaw } from "vue-router";
|
||||||
|
import axios from "axios";
|
||||||
|
import UserLogin from "../views/UserLogin.vue";
|
||||||
|
import RequestList from "../views/RequestList.vue";
|
||||||
|
import RequestDetail from "../views/RequestDetail.vue";
|
||||||
|
import RequestRegist from "../views/RequestRegist.vue";
|
||||||
|
import ApprovalList from "../views/ApprovalList.vue";
|
||||||
|
import OrderAct from "../views/OrderAct.vue";
|
||||||
|
import DeleverAct from "../views/DeleverAct.vue";
|
||||||
|
import InStore from "../views/InStore.vue";
|
||||||
|
import OutStore from "../views/OutStore.vue";
|
||||||
|
import SystemAdmin from "../views/SystemAdmin.vue";
|
||||||
|
|
||||||
|
const routes: Array<RouteRecordRaw> = [
|
||||||
|
{
|
||||||
|
path: "/",
|
||||||
|
redirect: "/login",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
path: "/login",
|
||||||
|
name: "Login",
|
||||||
|
component: UserLogin,
|
||||||
|
meta: { title: "ユーザーログイン" },
|
||||||
|
},
|
||||||
|
{
|
||||||
|
path: "/request",
|
||||||
|
name: "RequestList",
|
||||||
|
component: RequestList,
|
||||||
|
meta: { title: "購入依頼一覧", requiresAuth: true },
|
||||||
|
},
|
||||||
|
{
|
||||||
|
path: "/requestDetail",
|
||||||
|
name: "RequestDetail",
|
||||||
|
component: RequestDetail,
|
||||||
|
meta: { title: "購入依頼詳細", requiresAuth: true },
|
||||||
|
},
|
||||||
|
{
|
||||||
|
path: "/requestRegist",
|
||||||
|
name: "RequestRegist",
|
||||||
|
component: RequestRegist,
|
||||||
|
meta: { title: "購入依頼登録", requiresAuth: true },
|
||||||
|
},
|
||||||
|
{
|
||||||
|
path: "/approval",
|
||||||
|
name: "ApprovalList",
|
||||||
|
component: ApprovalList,
|
||||||
|
meta: { title: "購入依頼一覧", requiresAuth: true },
|
||||||
|
},
|
||||||
|
{
|
||||||
|
path: "/order",
|
||||||
|
name: "OrderAct",
|
||||||
|
component: OrderAct,
|
||||||
|
meta: { title: "発注画面", requiresAuth: true },
|
||||||
|
},
|
||||||
|
{
|
||||||
|
path: "/delever",
|
||||||
|
name: "DeleverAct",
|
||||||
|
component: DeleverAct,
|
||||||
|
meta: { title: "納品画面", requiresAuth: true },
|
||||||
|
},
|
||||||
|
{
|
||||||
|
path: "/inStore",
|
||||||
|
name: "InStore",
|
||||||
|
component: InStore,
|
||||||
|
meta: { title: "入庫画面", requiresAuth: true },
|
||||||
|
},
|
||||||
|
{
|
||||||
|
path: "/outStore",
|
||||||
|
name: "OutStore",
|
||||||
|
component: OutStore,
|
||||||
|
meta: { title: "出庫画面", requiresAuth: true },
|
||||||
|
},
|
||||||
|
{
|
||||||
|
path: "/systemAdmin",
|
||||||
|
name: "SystemAdmin",
|
||||||
|
component: SystemAdmin,
|
||||||
|
meta: { title: "Administrator", requiresAuth: true },
|
||||||
|
},
|
||||||
|
];
|
||||||
|
|
||||||
|
const router = createRouter({
|
||||||
|
history: createWebHistory(process.env.BASE_URL),
|
||||||
|
routes,
|
||||||
|
});
|
||||||
|
|
||||||
|
router.beforeEach(async (to, from, next) => {
|
||||||
|
if (to.meta.title) {
|
||||||
|
document.title = to.meta.title as string;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!to.meta.requiresAuth) {
|
||||||
|
return next();
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
await axios.get("/api/me", { withCredentials: true }); // cookie
|
||||||
|
next(); // 登录状态 OK,继续跳转
|
||||||
|
} catch (error) {
|
||||||
|
// 没登录 -> 跳转到登录页
|
||||||
|
next("/login");
|
||||||
|
}
|
||||||
|
});
|
||||||
|
export default router;
|
Reference in New Issue
Block a user