release(custom): i

This commit is contained in:
2023-10-10 15:01:00 +08:00
parent a9707c6d94
commit 5b33290de6
78 changed files with 13003 additions and 5230 deletions

View File

@@ -2,7 +2,7 @@ import { createRouter, createWebHistory, createWebHashHistory } from 'vue-router
import { setupRouterGuard } from './guard'
import { basicRoutes, EMPTY_ROUTE, NOT_FOUND_ROUTE } from './routes'
import { getToken, isNullOrWhitespace } from '@/utils'
import { useUserStore, usePermissionStore } from '@/store'
import { usePermissionStore } from '@/store'
const isHash = true
export const router = createRouter({
@@ -17,16 +17,6 @@ export async function setupRouter(app) {
app.use(router)
}
export async function resetRouter() {
const basicRouteNames = getRouteNames(basicRoutes)
router.getRoutes().forEach((route) => {
const name = route.name
if (!basicRouteNames.includes(name)) {
router.removeRoute(name)
}
})
}
export async function addDynamicRoutes() {
const token = getToken()
@@ -38,10 +28,8 @@ export async function addDynamicRoutes() {
// 有token的情况
try {
const userStore = useUserStore()
const permissionStore = usePermissionStore()
!userStore.userId && (await userStore.getUserInfo())
const accessRoutes = permissionStore.generateRoutes(userStore.role)
const accessRoutes = permissionStore.generateRoutes()
accessRoutes.forEach((route) => {
!router.hasRoute(route.name) && router.addRoute(route)
})
@@ -49,6 +37,7 @@ export async function addDynamicRoutes() {
router.addRoute(NOT_FOUND_ROUTE)
} catch (error) {
console.error(error)
throw error
}
}
@@ -58,8 +47,8 @@ export function getRouteNames(routes) {
function getRouteName(route) {
const names = [route.name]
if (route.children && route.children.length) {
names.push(...route.children.map((item) => getRouteName(item)).flat(1))
if (route.subMenu && route.subMenu.length) {
names.push(...route.subMenu.map((item) => getRouteName(item)).flat(1))
}
return names
}

View File

@@ -1,5 +1,3 @@
// const Layout = () => import('@/layout/index.vue')
export const basicRoutes = [
{
name: '404',
@@ -17,43 +15,6 @@ export const basicRoutes = [
title: '登录页',
},
},
// {
// name: 'ExternalLink',
// path: '/external-link',
// component: Layout,
// meta: {
// title: '外部链接',
// icon: 'mdi:link-variant',
// order: 4,
// },
// children: [
// {
// name: 'LinkGithubSrc',
// path: 'https://github.com/zclzone/vue-naive-admin',
// meta: {
// title: '源码 - github',
// icon: 'mdi:github',
// },
// },
// {
// name: 'LinkGiteeSrc',
// path: 'https://gitee.com/zclzone/vue-naive-admin',
// meta: {
// title: '源码 - gitee',
// icon: 'simple-icons:gitee',
// },
// },
// {
// name: 'LinkDocs',
// path: 'https://zclzone.github.io/vue-naive-admin-docs',
// meta: {
// title: '文档 - vuepress',
// icon: 'mdi:vuejs',
// },
// },
// ],
// },
]
export const NOT_FOUND_ROUTE = {
@@ -68,11 +29,3 @@ export const EMPTY_ROUTE = {
path: '/:pathMatch(.*)*',
component: null,
}
const modules = import.meta.glob('@/views/**/route.js', { eager: true })
const asyncRoutes = []
Object.keys(modules).forEach((key) => {
asyncRoutes.push(modules[key].default)
})
export { asyncRoutes }