动作参数取值范围+角色配置权限

This commit is contained in:
2026-04-30 15:16:48 +08:00
parent 0bc6dd7761
commit 05770f7e56
177 changed files with 13913 additions and 9863 deletions

View File

@@ -1,12 +1,30 @@
import { createRouter, createWebHistory } from 'vue-router'
import { createRouter, createWebHashHistory } from 'vue-router'
import { useAuthStore } from '@/stores/auth'
import { ElMessage } from 'element-plus'
const router = createRouter({
history: createWebHistory(import.meta.env.BASE_URL),
history: createWebHashHistory(import.meta.env.BASE_URL),
routes: [
{
path: '/login',
name: 'login',
component: () => import('../views/Login.vue'),
meta: { requiresAuth: false },
},
{
path: '/',
component: () => import('../views/Layout.vue'),
meta: { requiresAuth: true },
children: [
{
path: '',
redirect: '/home',
},
{
path: '/home',
name: 'home',
component: () => import('../views/Home.vue'),
},
{
path: '/user',
name: 'user',
@@ -22,6 +40,11 @@ const router = createRouter({
name: 'department',
component: () => import('../views/department/index.vue'),
},
{
path: '/permission',
name: 'permission',
component: () => import('../views/permission/index.vue'),
},
{
path: '/position',
name: 'position',
@@ -42,6 +65,11 @@ const router = createRouter({
name: 'island-info',
component: () => import('../views/islandInfo/index.vue'),
},
{
path: '/devparam',
name: 'devparam',
component: () => import('../views/devparam/index.vue'),
},
{
path: '/devinfo',
name: 'devinfo',
@@ -52,20 +80,69 @@ const router = createRouter({
name: 'plc-devinfo',
component: () => import('../views/devinfo/plc.vue'),
},
{
path: '/goods-info',
name: 'goods-info',
component: () => import('../views/goods/index.vue'),
},
{
path: '/flow-info',
name: 'flow-info',
component: () => import('../views/flowinfo/index.vue'),
},
{
path: '/step-info',
name: 'step-info',
component: () => import('../views/stepinfo/index.vue'),
},
{
path: '/plc-device-control',
name: 'plc-device-control',
component: () => import('../views/plcdevicecontrol/index.vue'),
},
{
path: '/sample-injection',
name: 'sample-injection',
component: () => import('../views/sampleinjection/index.vue'),
},
],
},
],
})
// 添加全局路由守卫
// router.beforeEach((to, from, next) => {
// const token = localStorage.getItem('token')
router.beforeEach((to, _from, next) => {
const authStore = useAuthStore()
const token = authStore.getToken()
// if (to.path !== '/login' && !token) {
// next('/login')
// } else {
// next()
// }
// })
// 如果访问登录页
if (to.path === '/login') {
// 已登录状态下访问登录页,自动跳转到首页
if (token) {
next('/home')
ElMessage.success('已登录,自动跳转')
} else {
// 未登录,正常进入登录页
next()
}
return
}
// 访问需要认证的页面但未登录无token
if (to.meta.requiresAuth && !token) {
ElMessage.warning('请先登录')
next('/login')
return
}
// 如果访问根路径,重定向到首页
if (to.path === '/') {
next('/home')
return
}
// 已登录且访问合法页面,正常放行
next()
})
export default router