mod vue2 to vue3

This commit is contained in:
chenhaodong
2026-06-18 01:44:25 +08:00
parent 109204734a
commit d30ff1a362
124 changed files with 951 additions and 2183 deletions
+43 -82
View File
@@ -1,21 +1,18 @@
import Vue from 'vue'
import Router from 'vue-router'
Vue.use(Router)
import { createRouter, createWebHashHistory } from 'vue-router'
// 主要框架
import Layout from '@/layout'
import Layout from '@/layout/index.vue'
// 登录框架
import LoginLayout from '@/views/login/components/LoginLayout'
import LoginLayout from '@/views/login/components/LoginLayout.vue'
export const constantRoutes = [{
path: '/redirect',
component: Layout,
hidden: true,
children: [{
path: '/redirect/:path*',
component: () => import('@/views/redirect/index')
path: '/redirect/:path(.*)',
component: () => import('@/views/redirect/index.vue')
}]
},
@@ -26,13 +23,13 @@ export const constantRoutes = [{
children: [{
path: '/login',
name: 'Login',
component: () => import('@/views/login/index'),
component: () => import('@/views/login/index.vue'),
hidden: true
},
{
path: '/register',
name: 'Register',
component: () => import('@/views/login/register'),
component: () => import('@/views/login/register.vue'),
hidden: true
}
]
@@ -40,12 +37,12 @@ export const constantRoutes = [{
{
path: '/404',
component: () => import('@/views/error-page/404'),
component: () => import('@/views/error-page/404.vue'),
hidden: true
},
{
path: '/401',
component: () => import('@/views/error-page/401'),
component: () => import('@/views/error-page/401.vue'),
hidden: true
},
{
@@ -54,7 +51,7 @@ export const constantRoutes = [{
redirect: '/dashboard',
children: [{
path: 'dashboard',
component: () => import('@/views/dashboard/index'),
component: () => import('@/views/dashboard/index.vue'),
name: 'Dashboard',
meta: {
title: '控制台',
@@ -71,7 +68,7 @@ export const constantRoutes = [{
hidden: true,
children: [{
path: 'index',
component: () => import('@/views/profile/index'),
component: () => import('@/views/profile/index.vue'),
name: 'Profile',
meta: {
title: '个人资料',
@@ -88,26 +85,6 @@ export const constantRoutes = [{
*/
export const asyncRoutes = [
/*{
path: '/apply',
component: Layout,
redirect: '/apply/input',
name: 'Apply',
meta: {
title: '报销申请',
icon: 'example',
roles: ['root']
},
children: [
{
path: 'input',
component: () => import('@/views/apply/input'),
name: 'input',
meta: { title: '报销申请', noCache: true, icon: 'repo' }
}
]
},*/
{
path: '/sys',
component: Layout,
@@ -120,7 +97,7 @@ export const asyncRoutes = [
},
children: [{
path: 'config',
component: () => import('@/views/sys/config'),
component: () => import('@/views/sys/config/index.vue'),
name: 'SysConfig',
meta: {
title: '系统配置',
@@ -129,26 +106,16 @@ export const asyncRoutes = [
},
{
path: 'dict',
component: () => import('@/views/sys/dict'),
component: () => import('@/views/sys/dict/index.vue'),
name: 'SysDict',
meta: {
title: '码值管理',
icon: 'theme'
}
},
/*{
path: 'depart',
component: () => import('@/views/sys/depart'),
name: 'SysDepart',
meta: {
title: '部门管理',
icon: 'tree'
}
},*/
{
path: 'role',
component: () => import('@/views/sys/role'),
component: () => import('@/views/sys/role/index.vue'),
name: 'SysRole',
meta: {
title: '角色管理',
@@ -158,7 +125,7 @@ export const asyncRoutes = [
{
path: 'user',
component: () => import('@/views/sys/user'),
component: () => import('@/views/sys/user/index.vue'),
name: 'SysUser',
meta: {
title: '用户管理',
@@ -168,7 +135,7 @@ export const asyncRoutes = [
{
path: 'bookgl',
component: () => import('@/views/sys/bookgl'),
component: () => import('@/views/sys/bookgl/index.vue'),
name: 'SysBookgl',
meta: {
title: '书籍信息管理',
@@ -177,7 +144,7 @@ export const asyncRoutes = [
},
{
path: 'jieshu',
component: () => import('@/views/sys/jieshu'),
component: () => import('@/views/sys/jieshu/index.vue'),
name: 'SysJieshu',
meta: {
title: '图书搜索',
@@ -187,7 +154,7 @@ export const asyncRoutes = [
{
path: 'huanshu',
component: () => import('@/views/sys/huanshu'),
component: () => import('@/views/sys/huanshu/index.vue'),
name: 'Syshuanshu',
meta: {
title: '我的借还',
@@ -196,7 +163,7 @@ export const asyncRoutes = [
},
{
path: 'jiehuanjilu',
component: () => import('@/views/sys/jiehuanjilu'),
component: () => import('@/views/sys/jiehuanjilu/index.vue'),
name: 'SysJiehuanjilu',
meta: {
title: '借还记录',
@@ -204,7 +171,7 @@ export const asyncRoutes = [
}
},{
path: 'gggl',
component: () => import('@/views/sys/gggl'),
component: () => import('@/views/sys/gggl/index.vue'),
name: 'SysGggl',
meta: {
title: '公告管理',
@@ -213,7 +180,7 @@ export const asyncRoutes = [
},
{
path: 'lygl',
component: () => import('@/views/sys/liuyangl'),
component: () => import('@/views/sys/liuyangl/index.vue'),
name: 'SysLygl',
meta: {
title: '留言管理',
@@ -222,9 +189,6 @@ export const asyncRoutes = [
},
]
},
{
path: '/sys',
@@ -235,20 +199,11 @@ export const asyncRoutes = [
title: '用户系统',
icon: 'configure',
roles: ['student']
},// 学生路由页面
},
children: [
/*{
path: 'grxxgl',
component: () => import('@/views/sys/grxxgl'),
name: 'SysGrxxgl',
meta: {
title: '个人信息管理',
icon: 'admin'
}
},*/
{
path: 'jieshu',
component: () => import('@/views/sys/jieshu'),
component: () => import('@/views/sys/jieshu/index.vue'),
name: 'SysJieshu',
meta: {
title: '图书搜索',
@@ -258,7 +213,7 @@ export const asyncRoutes = [
{
path: 'huanshu',
component: () => import('@/views/sys/huanshu'),
component: () => import('@/views/sys/huanshu/index.vue'),
name: 'Syshuanshu',
meta: {
title: '我的借还',
@@ -267,7 +222,7 @@ export const asyncRoutes = [
},
{
path: 'jiehuanjilu',
component: () => import('@/views/sys/jiehuanjilu'),
component: () => import('@/views/sys/jiehuanjilu/index.vue'),
name: 'SysJiehuanjilu',
meta: {
title: '借还记录',
@@ -277,7 +232,7 @@ export const asyncRoutes = [
,
{
path: 'liuyan',
component: () => import('@/views/sys/stuliuyan'),
component: () => import('@/views/sys/stuliuyan/index.vue'),
name: 'SysStuliuyan',
meta: {
title: '留言板块',
@@ -287,7 +242,7 @@ export const asyncRoutes = [
,
{
path: 'gonggao',
component: () => import('@/views/sys/stugggl'),
component: () => import('@/views/sys/stugggl/index.vue'),
name: 'SysStugggl',
meta: {
title: '公告板块',
@@ -300,25 +255,31 @@ export const asyncRoutes = [
// 404 page must be placed at the end !!!
{
path: '*',
path: '/:pathMatch(.*)*',
redirect: '/dashboard',
hidden: true
}
]
const createRouter = () => new Router({
// mode: 'history', // require service support
scrollBehavior: () => ({
y: 0
}),
const router = createRouter({
history: createWebHashHistory(),
scrollBehavior: () => ({ top: 0 }),
routes: constantRoutes
})
const router = createRouter()
export function resetRouter() {
const newRouter = createRouter()
router.matcher = newRouter.matcher // reset router
const newRouter = createRouter({
history: createWebHashHistory(),
scrollBehavior: () => ({ top: 0 }),
routes: constantRoutes
})
// 注意:Vue Router 4 没有 matcher,通过移除所有路由再重新添加来重置
const currentRoutes = router.getRoutes()
currentRoutes.forEach(route => {
if (route.name && !constantRoutes.find(cr => cr.name === route.name)) {
router.removeRoute(route.name)
}
})
}
export default router