chore: initial baseline with P0-safety .gitignore
This commit is contained in:
@@ -0,0 +1,88 @@
|
||||
// =============================================================================
|
||||
// 企微IT智能服务台 — 坐席工作台路由配置
|
||||
// =============================================================================
|
||||
// 说明:定义页面路由映射
|
||||
// 包括:
|
||||
// 1. /login → 登录页(简单的用户名密码表单)
|
||||
// 2. /workspace → 坐席工作台(需要认证)
|
||||
// 3. / → 重定向到 /workspace
|
||||
// =============================================================================
|
||||
|
||||
import { createRouter, createWebHistory } from 'vue-router'
|
||||
|
||||
// --------------------------------------------------------------------------
|
||||
// 路由配置
|
||||
// --------------------------------------------------------------------------
|
||||
const routes = [
|
||||
{
|
||||
// 根路径重定向到工作台
|
||||
path: '/',
|
||||
redirect: '/workspace',
|
||||
},
|
||||
{
|
||||
// 登录页面
|
||||
path: '/login',
|
||||
name: 'Login',
|
||||
component: () => import('@/views/Login.vue'),
|
||||
meta: { title: '坐席登录', requiresAuth: false },
|
||||
},
|
||||
{
|
||||
// 坐席工作台主页面
|
||||
path: '/workspace',
|
||||
name: 'Workspace',
|
||||
component: () => import('@/views/Workspace.vue'),
|
||||
meta: { title: '坐席工作台', requiresAuth: true },
|
||||
},
|
||||
]
|
||||
|
||||
// --------------------------------------------------------------------------
|
||||
// 创建路由实例
|
||||
// --------------------------------------------------------------------------
|
||||
// createWebHistory: 使用 HTML5 History 模式,基础路径 /itagent/(与IT数据平台共享域名)
|
||||
const router = createRouter({
|
||||
history: createWebHistory('/itagent/'),
|
||||
routes,
|
||||
})
|
||||
|
||||
// --------------------------------------------------------------------------
|
||||
// 路由守卫 — 检查登录状态
|
||||
// --------------------------------------------------------------------------
|
||||
// 访问需要认证的页面前,检查 localStorage 中是否有 token
|
||||
// 没有 token 则跳转到登录页
|
||||
router.beforeEach((to, _from, next) => {
|
||||
// 设置页面标题
|
||||
if (to.meta.title) {
|
||||
document.title = `${to.meta.title} - IT智能服务台`
|
||||
}
|
||||
|
||||
// ========================================================================
|
||||
// Portal Token 传递:从 URL 参数 ?token=xxx 读取并保存到 localStorage
|
||||
// ========================================================================
|
||||
const urlParams = new URLSearchParams(window.location.search)
|
||||
const urlToken = urlParams.get('token')
|
||||
if (urlToken) {
|
||||
// 保存 token 到坐席端 localStorage key
|
||||
localStorage.setItem('agent_token', urlToken)
|
||||
// 同时保存到 portal_token key(方便跨端共享)
|
||||
localStorage.setItem('portal_token', urlToken)
|
||||
// 清除 URL 参数,避免刷新页面重复读取
|
||||
const cleanUrl = window.location.pathname
|
||||
window.history.replaceState({}, '', cleanUrl)
|
||||
}
|
||||
|
||||
// 检查是否需要认证
|
||||
const requiresAuth = to.meta.requiresAuth !== false // 默认需要认证
|
||||
const token = localStorage.getItem('agent_token')
|
||||
|
||||
if (requiresAuth && !token) {
|
||||
// 需要认证但没有 token,跳转到 Portal 统一入口
|
||||
window.location.href = '/itportal/'
|
||||
} else if (to.path === '/login' && token) {
|
||||
// 已登录用户访问登录页,跳转到工作台
|
||||
next({ path: '/workspace' })
|
||||
} else {
|
||||
next()
|
||||
}
|
||||
})
|
||||
|
||||
export default router
|
||||
Reference in New Issue
Block a user