diff --git a/rc_autoplc_front/src/router/index.ts b/rc_autoplc_front/src/router/index.ts index 45c7ed0..15f6e13 100644 --- a/rc_autoplc_front/src/router/index.ts +++ b/rc_autoplc_front/src/router/index.ts @@ -16,6 +16,15 @@ const router = createRouter({ 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', @@ -90,7 +99,7 @@ router.beforeEach((to, from, next) => { if (to.path === '/login') { // 已登录状态下访问登录页,自动跳转到首页 if (token) { - next('/') + next('/home') ElMessage.success('已登录,自动跳转') } else { // 未登录,正常进入登录页 @@ -106,6 +115,12 @@ router.beforeEach((to, from, next) => { return } + // 如果访问根路径,重定向到首页 + if (to.path === '/') { + next('/home') + return + } + // 已登录且访问合法页面,正常放行 next() }) diff --git a/rc_autoplc_front/src/utils/request.ts b/rc_autoplc_front/src/utils/request.ts index 9a43f42..abfec19 100644 --- a/rc_autoplc_front/src/utils/request.ts +++ b/rc_autoplc_front/src/utils/request.ts @@ -43,6 +43,27 @@ const TokenManager = { // 应用启动时初始化token TokenManager.initToken() +// 登录过期提示防重复标志 +let isLoginExpiredShown = false + +// 处理登录过期(防重复提示) +const handleLoginExpired = () => { + if (!isLoginExpiredShown) { + isLoginExpiredShown = true + // 清除token + TokenManager.removeToken() + // 显示提示消息 + ElMessage.error('登录已过期,请重新登录') + // 跳转到登录页 + router.replace('/login').finally(() => { + // 延迟重置标志位,确保跳转完成后再允许下次提示 + setTimeout(() => { + isLoginExpiredShown = false + }, 1000) + }) + } +} + // 请求拦截器 request.interceptors.request.use( (config: InternalAxiosRequestConfig) => { @@ -72,10 +93,8 @@ request.interceptors.response.use( // 处理业务错误码 if (data.code === 302) { - // 清除token - TokenManager.removeToken() - // 跳转到登录页 - router.replace('/login') + // 处理登录过期(防重复提示) + handleLoginExpired() return Promise.reject(data) } @@ -90,11 +109,8 @@ request.interceptors.response.use( (error) => { // 处理401未授权错误 if (error.response?.status === 401) { - // 清除token - TokenManager.removeToken() - // 跳转到登录页 - ElMessage.error('登录已过期,请重新登录') - router.replace('/login') + // 处理登录过期(防重复提示) + handleLoginExpired() return Promise.reject(error) } diff --git a/rc_autoplc_front/src/views/Home.vue b/rc_autoplc_front/src/views/Home.vue new file mode 100644 index 0000000..2fd8b28 --- /dev/null +++ b/rc_autoplc_front/src/views/Home.vue @@ -0,0 +1,56 @@ + + + + + diff --git a/rc_autoplc_front/src/views/Layout.vue b/rc_autoplc_front/src/views/Layout.vue index 97ea15c..11efe7f 100644 --- a/rc_autoplc_front/src/views/Layout.vue +++ b/rc_autoplc_front/src/views/Layout.vue @@ -31,6 +31,10 @@ router :collapse="false" > + + + 首页 + - - - 功能岛管理 + + + PLC设备管理 设备管理 - - - PLC设备管理 + + + 功能岛管理 @@ -112,7 +116,7 @@ import { ref, computed } from 'vue' import { useRouter, useRoute } from 'vue-router' import { ElMessage, ElMessageBox } from 'element-plus' -import { User, Setting, Avatar, OfficeBuilding, Briefcase, Document, CaretBottom, UserFilled, Grid, Monitor, Connection, List, EditPen, Files, Tickets, Management, FolderOpened, Box, Filter } from '@element-plus/icons-vue' +import { User, Setting, Avatar, OfficeBuilding, Briefcase, Document, CaretBottom, UserFilled, Grid, Monitor, Connection, List, EditPen, Files, Tickets, Management, FolderOpened, Box, Filter, HomeFilled } from '@element-plus/icons-vue' import { useAuthStore } from '@/stores/auth' const router = useRouter() diff --git a/rc_autoplc_front/src/views/Login.vue b/rc_autoplc_front/src/views/Login.vue index 32cd015..73f909b 100644 --- a/rc_autoplc_front/src/views/Login.vue +++ b/rc_autoplc_front/src/views/Login.vue @@ -209,7 +209,7 @@ const handleLogin = async () => { ElMessage.success('登录成功') // 跳转到首页 - router.push('/') + router.push('/home') } } catch (error: any) { // 错误提示已在全局响应拦截中处理,这里不重复弹出 diff --git a/rc_autoplc_front/src/views/department/index.vue b/rc_autoplc_front/src/views/department/index.vue index 3ae58f1..2ff4ec5 100644 --- a/rc_autoplc_front/src/views/department/index.vue +++ b/rc_autoplc_front/src/views/department/index.vue @@ -1,6 +1,7 @@