style:路由、权限优化

main
黄伟杰 3 weeks ago
parent 059f9fa3c7
commit 4e924c62eb

@ -43,7 +43,7 @@ const loginOut = async () => {
}) })
await userStore.loginOut() await userStore.loginOut()
tagsViewStore.delAllViews() tagsViewStore.delAllViews()
replace('/login?redirect=/index') replace('/login?redirect=/')
} catch {} } catch {}
} }
const toProfile = async () => { const toProfile = async () => {

@ -46,6 +46,32 @@ const parseURL = (
return { basePath, paramsObject } return { basePath, paramsObject }
} }
const resolveChildPath = (parentPath: string, childPath: string) => {
if (!childPath) return parentPath
if (childPath.startsWith('/')) return childPath
const p = parentPath.endsWith('/') ? parentPath.slice(0, -1) : parentPath
return `${p}/${childPath}`.replace(/\/+/g, '/')
}
const resolveFirstMenuPath = (routes: any[], parentPath = ''): string | undefined => {
for (const r of routes ?? []) {
if (!r) continue
if (typeof r?.path === 'string' && r.path.includes(':path(.*)*')) continue
if (r?.meta?.hidden === true) continue
if (typeof r.redirect === 'string' && r.redirect.trim()) {
const redirect = r.redirect.trim()
if (redirect !== '/') return redirect
}
const currentPath = parentPath ? resolveChildPath(parentPath, String(r.path ?? '')) : String(r.path ?? '')
const childPath = resolveFirstMenuPath(r.children, currentPath)
if (childPath) return childPath
if (currentPath && currentPath !== '/') return currentPath
}
return undefined
}
// 路由不重定向白名单 // 路由不重定向白名单
const whiteList = [ const whiteList = [
'/login', '/login',
@ -81,12 +107,21 @@ router.beforeEach(async (to, from, next) => {
router.addRoute(route as unknown as RouteRecordRaw) // 动态添加可访问路由表 router.addRoute(route as unknown as RouteRecordRaw) // 动态添加可访问路由表
}) })
const redirectPath = from.query.redirect || to.path const redirectPath = from.query.redirect || to.path
// 修复跳转时不带参数的问题
const redirect = decodeURIComponent(redirectPath as string) const redirect = decodeURIComponent(redirectPath as string)
const { basePath, paramsObject: query } = parseURL(redirect) const { basePath, paramsObject: query } = parseURL(redirect)
const nextData = to.path === redirect ? { ...to, replace: true } : { path: redirect, query } let targetPath = redirect
let targetQuery = query
if (basePath === '/' || basePath === '') {
targetPath = resolveFirstMenuPath(permissionStore.addRouters) ?? '/empty'
targetQuery = {}
}
const nextData = to.path === targetPath ? { ...to, replace: true } : { path: targetPath, query: targetQuery }
next(nextData) next(nextData)
} else { } else {
if (to.path === '/') {
next({ path: resolveFirstMenuPath(permissionStore.addRouters) ?? '/empty', replace: true })
return
}
next() next()
} }
} }

@ -12,7 +12,7 @@ const router = createRouter({
}) })
export const resetRouter = (): void => { export const resetRouter = (): void => {
const resetWhiteNameList = ['Redirect', 'Login', 'NoFind', 'Root'] const resetWhiteNameList = ['Redirect', 'Login', 'NoFind', 'Root', 'EmptyRoot', 'EmptyPage']
router.getRoutes().forEach((route) => { router.getRoutes().forEach((route) => {
const { name } = route const { name } = route
if (name && !resetWhiteNameList.includes(name as string)) { if (name && !resetWhiteNameList.includes(name as string)) {

@ -50,26 +50,26 @@ const remainingRouter: AppRouteRecordRaw[] = [
noTagsView: true noTagsView: true
} }
}, },
{ // {
path: '/', // path: '/',
component: Layout, // component: Layout,
redirect: '/index', // redirect: '/index',
name: 'Home', // name: 'Home',
meta: {}, // meta: {},
children: [ // children: [
{ // {
path: 'index', // path: 'index',
component: () => import('@/views/Home/Index.vue'), // component: () => import('@/views/Home/Index.vue'),
name: 'Index', // name: 'Index',
meta: { // meta: {
title: t('router.home'), // title: t('router.home'),
icon: 'ep:home-filled', // icon: 'ep:home-filled',
noCache: false, // noCache: false,
affix: true // affix: true
} // }
} // }
] // ]
}, // },
{ {
path: '/user', path: '/user',
component: Layout, component: Layout,
@ -234,6 +234,26 @@ const remainingRouter: AppRouteRecordRaw[] = [
noTagsView: true noTagsView: true
} }
}, },
{
path: '/empty',
component: Layout,
name: 'EmptyRoot',
meta: {
hidden: true,
noTagsView: true
},
children: [
{
path: '',
component: () => import('@/views/Empty/Index.vue'),
name: 'EmptyPage',
meta: {
hidden: true,
noTagsView: true
}
}
]
},
{ {
path: '/bpm', path: '/bpm',
component: Layout, component: Layout,

@ -0,0 +1,12 @@
<template>
<div class="empty-page"></div>
</template>
<script setup lang="ts"></script>
<style scoped>
.empty-page {
width: 100%;
height: 100%;
}
</style>

@ -96,11 +96,11 @@
<dict-tag :type="DICT_TYPE.IOT_PROTOCOL" :value="scope.row.protocol" /> <dict-tag :type="DICT_TYPE.IOT_PROTOCOL" :value="scope.row.protocol" />
</template> </template>
</el-table-column> </el-table-column>
<el-table-column :label="t('DataCollection.Device.status')" align="center" prop="status" width="120px"> <!-- <el-table-column :label="t('DataCollection.Device.status')" align="center" prop="status" width="120px">
<template #default="scope"> <template #default="scope">
<dict-tag :type="DICT_TYPE.IOT_GATEWAY_STATUS" :value="scope.row.status" /> <dict-tag :type="DICT_TYPE.IOT_GATEWAY_STATUS" :value="scope.row.status" />
</template> </template>
</el-table-column> </el-table-column> -->
<!-- <el-table-column label="读主题" align="center" prop="readTopic" /> <!-- <el-table-column label="读主题" align="center" prop="readTopic" />
<el-table-column label="写主题" align="center" prop="writeTopic" /> <el-table-column label="写主题" align="center" prop="writeTopic" />
<el-table-column label="网关id" align="center" prop="gatewayId" /> --> <el-table-column label="网关id" align="center" prop="gatewayId" /> -->

Loading…
Cancel
Save