2023-05-14 15:31:50 +00:00
|
|
|
import { createRouter, createWebHistory } from "vue-router";
|
2023-05-16 05:38:39 +00:00
|
|
|
import { Tooltip, Toast } from 'bootstrap';
|
|
|
|
|
2023-03-14 14:33:06 +00:00
|
|
|
|
|
|
|
const routes = [
|
|
|
|
{
|
|
|
|
path: "/",
|
|
|
|
name: "index",
|
|
|
|
component: () => import("../views/Index.vue"),
|
|
|
|
meta: {
|
|
|
|
title: "欢迎",
|
|
|
|
},
|
|
|
|
},
|
2023-03-15 13:44:06 +00:00
|
|
|
{
|
|
|
|
path: "/tunnels",
|
|
|
|
name: "tunnels",
|
|
|
|
component: () => import("../views/Tunnels/Index.vue"),
|
|
|
|
meta: {
|
|
|
|
title: "隧道",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
path: "/tunnels/create",
|
|
|
|
name: "tunnels.create",
|
|
|
|
component: () => import("../views/Tunnels/Create.vue"),
|
|
|
|
meta: {
|
|
|
|
title: "创建隧道",
|
|
|
|
},
|
|
|
|
},
|
2023-03-16 13:36:59 +00:00
|
|
|
{
|
|
|
|
path: "/tunnels/:id",
|
|
|
|
name: "tunnels.show",
|
|
|
|
component: () => import("../views/Tunnels/Show.vue"),
|
|
|
|
meta: {
|
|
|
|
title: "隧道",
|
|
|
|
},
|
|
|
|
},
|
2023-03-15 13:44:06 +00:00
|
|
|
{
|
2023-05-14 09:36:47 +00:00
|
|
|
path: "/downloads",
|
|
|
|
name: "downloads",
|
|
|
|
component: () => import("../views/Downloads.vue"),
|
2023-03-15 13:44:06 +00:00
|
|
|
meta: {
|
2023-05-14 09:36:47 +00:00
|
|
|
title: "客户端下载",
|
2023-03-15 13:44:06 +00:00
|
|
|
},
|
|
|
|
},
|
2023-05-14 15:31:50 +00:00
|
|
|
{
|
|
|
|
path: "/sign",
|
|
|
|
name: "sign",
|
|
|
|
component: () => import("../views/Sign.vue"),
|
|
|
|
meta: {
|
|
|
|
title: "签到",
|
|
|
|
},
|
|
|
|
},
|
2023-05-16 12:41:33 +00:00
|
|
|
{
|
|
|
|
path: "/charge",
|
|
|
|
name: "charge",
|
|
|
|
component: () => import("../views/Charge.vue"),
|
|
|
|
meta: {
|
|
|
|
title: "流量充值",
|
|
|
|
},
|
|
|
|
},
|
2023-03-14 14:33:06 +00:00
|
|
|
];
|
|
|
|
|
2023-03-15 13:44:06 +00:00
|
|
|
|
|
|
|
// 验证用户是否是管理员(从 window 中获取)
|
|
|
|
const isAdmin = () => {
|
|
|
|
return window.Base.User.is_admin;
|
|
|
|
};
|
|
|
|
|
2023-05-16 05:38:39 +00:00
|
|
|
|
|
|
|
const router = createRouter({
|
|
|
|
history: createWebHistory(),
|
|
|
|
routes,
|
|
|
|
});
|
|
|
|
|
|
|
|
|
2023-03-15 13:44:06 +00:00
|
|
|
// before each route
|
|
|
|
routes.forEach((route) => {
|
2023-05-16 05:38:39 +00:00
|
|
|
|
|
|
|
router.beforeEach((to, from) => {
|
|
|
|
new Tooltip(document.body, {
|
|
|
|
selector: "[data-bs-toggle='tooltip']",
|
|
|
|
});
|
|
|
|
|
|
|
|
Array.from(document.querySelectorAll('.toast')).forEach(
|
|
|
|
(toastNode) => new Toast(toastNode)
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
2023-03-15 13:44:06 +00:00
|
|
|
route.beforeEnter = (to, from, next) => {
|
|
|
|
// 如果是管理员页面,且用户不是管理员,则跳转到首页
|
|
|
|
if (route.meta.admin && !isAdmin()) {
|
2023-05-14 15:31:50 +00:00
|
|
|
next({ name: "index" });
|
2023-03-15 13:44:06 +00:00
|
|
|
} else {
|
|
|
|
next();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
});
|
|
|
|
|
|
|
|
|
2023-03-14 14:33:06 +00:00
|
|
|
export default router;
|