diff --git a/src/router/index.js b/src/router/index.js index 3f78636..f32962b 100644 --- a/src/router/index.js +++ b/src/router/index.js @@ -42,10 +42,24 @@ router.beforeEach(async (to, from, next) => { const token = localRead(LocalStorageKeyConst.USER_TOKEN); if (!token) { useUserStore().logout(); - if (to.path === PAGE_PATH_LOGIN) { - next(); + + // 设备检测函数 + const isMobileDevice = () => /Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent); + + // 如果是移动端路径或移动端设备,跳转到移动端登录页 + if (to.path.startsWith('/mobile') || isMobileDevice()) { + if (to.path === '/mobile/login') { + next(); + } else { + next({ path: '/mobile/login' }); + } } else { - next({ path: PAGE_PATH_LOGIN }); + // PC端设备,跳转到PC端登录页 + if (to.path === PAGE_PATH_LOGIN) { + next(); + } else { + next({ path: PAGE_PATH_LOGIN }); + } } return; } diff --git a/src/router/mobile.js b/src/router/mobile.js new file mode 100644 index 0000000..8d88368 --- /dev/null +++ b/src/router/mobile.js @@ -0,0 +1,90 @@ +import { createRouter, createWebHistory } from 'vue-router' + +// 设备检测函数 +function isMobileDevice() { + return /Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent) +} + +// 检查登录状态 +function isLoggedIn() { + const token = localStorage.getItem('token') + return !!token && token !== 'null' && token !== 'undefined' +} + +// 获取用户信息 +function getUserInfo() { + try { + return JSON.parse(localStorage.getItem('userInfo') || '{}') + } catch { + return {} + } +} + +const mobileRoutes = [ + { + path: '/mobile/login', + name: 'MobileLogin', + component: () => import('/@/views/mobile/login.vue') + }, + { + path: '/mobile/agreement', + name: 'MobileAgreement', + component: () => import('/@/views/mobile/agreement.vue'), + meta: { requiresAuth: true, mobileOnly: true } + }, + { + path: '/mobile/service', + name: 'MobileService', + component: () => import('/@/views/mobile/index.vue'), + meta: { requiresAuth: true, mobileOnly: true } + }, + { + path: '/mobile/service/create', + name: 'MobileServiceCreate', + component: () => import('/@/views/mobile/service/create.vue'), + meta: { requiresAuth: true, mobileOnly: true } + }, + { + path: '/mobile', + redirect: '/mobile/login' + } +] + +// 移动端路由守卫函数 +function mobileRouteGuard(to, from, next) { + if (to.path.startsWith('/mobile')) { + // 设备检测(开发环境暂时跳过) + if (process.env.NODE_ENV === 'development') { + // 开发环境跳过设备检测,方便测试 + } else if (!isMobileDevice()) { + next('/') + return + } + + // 登录检查 + if (to.meta.requiresAuth && !isLoggedIn()) { + next('/mobile/login') + return + } + + // 已登录用户的智能跳转 + if (isLoggedIn() && to.path === '/mobile/login') { + const userInfo = getUserInfo() + const isUserOrCto = ['user', 'cto'].includes((userInfo.roleCode || '').toLowerCase()) + const isSigned = userInfo.agreementSignFlag === true + + if (isUserOrCto && !isSigned) { + next('/mobile/agreement') + } else { + next('/mobile/service') + } + return + } + } + + next() +} + +// 导出移动端路由数组和守卫函数 +export const mobileRouters = mobileRoutes +export { mobileRouteGuard } \ No newline at end of file diff --git a/src/router/routers.js b/src/router/routers.js index 638d4d8..c0dad7d 100644 --- a/src/router/routers.js +++ b/src/router/routers.js @@ -12,11 +12,12 @@ import { loginRouters } from './system/login'; import { helpDocRouters } from './support/help-doc'; import NotFound from '/@/views/system/40X/404.vue'; import NoPrivilege from '/@/views/system/40X/403.vue'; - +import { mobileRouters } from './mobile'; // 导入移动端路由 export const routerArray = [ ...loginRouters, ...homeRouters, ...helpDocRouters, + ...mobileRouters, // 添加移动端路由 { path: '/:pathMatch(.*)*', name: '404', component: NotFound }, { path: '/403', name: '403', component: NoPrivilege } ]; diff --git a/src/views/mobile/agreement.vue b/src/views/mobile/agreement.vue new file mode 100644 index 0000000..4e95615 --- /dev/null +++ b/src/views/mobile/agreement.vue @@ -0,0 +1,131 @@ + + + + + \ No newline at end of file diff --git a/src/views/mobile/index.vue b/src/views/mobile/index.vue new file mode 100644 index 0000000..32f5862 --- /dev/null +++ b/src/views/mobile/index.vue @@ -0,0 +1,373 @@ + + + + + \ No newline at end of file diff --git a/src/views/mobile/login.vue b/src/views/mobile/login.vue new file mode 100644 index 0000000..f90b721 --- /dev/null +++ b/src/views/mobile/login.vue @@ -0,0 +1,324 @@ + + + + + \ No newline at end of file diff --git a/src/views/mobile/service/create.vue b/src/views/mobile/service/create.vue new file mode 100644 index 0000000..dea2c7f --- /dev/null +++ b/src/views/mobile/service/create.vue @@ -0,0 +1,231 @@ + \ No newline at end of file diff --git a/src/views/mobile/service/index.vue b/src/views/mobile/service/index.vue new file mode 100644 index 0000000..04f0cc1 --- /dev/null +++ b/src/views/mobile/service/index.vue @@ -0,0 +1,17 @@ + + + + + \ No newline at end of file diff --git a/vite.config.js b/vite.config.js index ff50222..b4a3246 100644 --- a/vite.config.js +++ b/vite.config.js @@ -35,14 +35,20 @@ export default { proxy: { // 代理API路径 '/api': { - target: 'http://8.148.67.92:8080/', // 目标服务器地址 - //target: 'http://127.0.0.1:8080/', + //target: 'http://8.148.67.92:8080/', // 目标服务器地址 + target: 'http://127.0.0.1:8080/', changeOrigin: true, // 是否修改请求头中的 Origin 字段 rewrite: (path) => path.replace(/^\/api/, ''), // 重写路径 }, '/login': { - target: 'http://8.148.67.92:8080/', // 目标服务器地址 - //target: 'http://127.0.0.1:8080/', + //target: 'http://8.148.67.92:8080/', // 目标服务器地址 + target: 'http://127.0.0.1:8080/', + changeOrigin: true, // 是否修改请求头中的 Origin 字段 + rewrite: (path) => path.replace(/^\/api/, ''), // 重写路径 + }, + '/mobile/login': { + //target: 'http://8.148.67.92:8080/', // 目标服务器地址 + target: 'http://127.0.0.1:8080/', changeOrigin: true, // 是否修改请求头中的 Origin 字段 rewrite: (path) => path.replace(/^\/api/, ''), // 重写路径 },