This commit is contained in:
Sun
2023-11-08 21:53:07 +08:00
commit 211c3071dc
245 changed files with 39293 additions and 0 deletions
+66
View File
@@ -0,0 +1,66 @@
import type { App } from 'vue'
import type { RouteRecordRaw } from 'vue-router'
import { createRouter, createWebHashHistory } from 'vue-router'
import { setupPageGuard } from './permission'
const routes: RouteRecordRaw[] = [
{
path: '/',
name: 'Home',
// component: () => import('@/views/home/Layout.vue'),
component: () => import('@/views/home/index.vue'),
// children: [
// {
// path: '/edit/:noteId?',
// name: 'EditNote',
// component: () => import('@/views/home/index.vue'),
// },
// ],
},
{
path: '/login',
name: 'login',
component: () => import('@/views/login/index.vue'),
},
{
path: '/404',
name: '404',
component: () => import('@/views/exception/404/index.vue'),
},
{
path: '/500',
name: '500',
component: () => import('@/views/exception/500/index.vue'),
},
{
path: '/:pathMatch(.*)*',
name: 'notFound',
redirect: '/404',
},
{
path: '/test',
name: 'test',
component: () => import('@/views/exception/test/index.vue'),
},
// adminRouter,
]
export const router = createRouter({
history: createWebHashHistory(),
routes,
scrollBehavior: () => ({ left: 0, top: 0 }),
})
setupPageGuard(router)
export async function setupRouter(app: App) {
app.use(router)
await router.isReady()
}
+36
View File
@@ -0,0 +1,36 @@
import type { Router } from 'vue-router'
import { useUserStore } from '@/store/modules/user'
export function setupPageGuard(router: Router) {
router.beforeEach(async (to, from, next) => {
// const authStore = useAuthStoreWithout()
const userStore = useUserStore()
// 非管理员路由拦截
if (userStore.userInfo.role !== 1 && to.path.includes('admin'))
next({ name: '404' })
else
next()
// if (!authStore.session) {
// try {
// const data = await authStore.getSession()
// if (String(data.auth) === 'false' && authStore.token)
// authStore.removeToken()
// if (to.path === '/500')
// next({ name: 'Root' })
// else
// next()
// }
// catch (error) {
// if (to.path !== '/500')
// next({ name: '500' })
// else
// next()
// }
// }
// else {
// next()
// }
})
}