diff --git a/src/permission.js b/src/permission.js index 493627f..c93bc92 100644 --- a/src/permission.js +++ b/src/permission.js @@ -26,76 +26,54 @@ router.beforeEach((to, from, next) => { NProgress.start() - //政务登录 - const url = window.location.href - - // 检查是否包含政务平台返回的关键参数 - const hasUserToken = url.includes('userToken=') - const hasSignature = url.includes('signature=') - const hasTimespan = url.includes('timespan=') - - if (hasUserToken && hasSignature && hasTimespan) { - const regUserToken = /[?&]userToken=([^&#]+)/ - const regSignature = /[?&]signature=([^&#]+)/ - const regTimespan = /[?&]timespan=([^&#]+)/ - - const userTokenMatch = url.match(regUserToken) - const signatureMatch = url.match(regSignature) - const timespanMatch = url.match(regTimespan) - - const userToken = userTokenMatch ? userTokenMatch[1] : null - const signature = signatureMatch ? signatureMatch[1] : null - const timespan = timespanMatch ? timespanMatch[1] : null - - if (userToken && signature && timespan) { - // 调用政务系统登录接口 - governmentGetInfo({ - userToken, - signature, - timespan - }).then(res => { - const token = res.token - if (token) { - setToken(token) - localStorage.setItem('otherToken', userToken) - - const cleanUrl = url - .replace(regUserToken, '') - .replace(regSignature, '') - .replace(regTimespan, '') - .replace(/^&/, '?') - - window.history.replaceState({}, '', cleanUrl) - - // 继续路由守卫流程 - if (store.getters.roles.length === 0) { - isRelogin.show = true - store.dispatch('GetInfo').then(() => { - isRelogin.show = false - store.dispatch('GenerateRoutes').then(accessRoutes => { - router.addRoutes(accessRoutes) - next({ ...to, replace: true }) - }) - }).catch(err => { - store.dispatch('LogOut').then(() => { - Message.error(err) - next({ path: '/' }) - }) - }) - } else { - next() - } - } - }).catch(err => { - console.error('政务系统登录失败:', err) - Message.error('政务系统登录失败,请重新登录') - }) - } else { - Message.error('缺少必要的登录参数') - next(`/login?redirect=${encodeURIComponent(to.fullPath)}`) +const { userToken, signature, timespan } = to.query +console.log(userToken, signature, timespan, '参数') + + +if (userToken && signature && timespan) { + // 政务登录 + governmentGetInfo({ + userToken, + signature, + timespan + }).then(res => { + const token = res.token + if (token) { + setToken(token) + localStorage.setItem('otherToken', userToken) + + const newQuery = { ...to.query } + delete newQuery.userToken + delete newQuery.signature + delete newQuery.timespan + const newPath = to.path + '?' + new URLSearchParams(newQuery).toString() + window.history.replaceState({}, '', newPath) + + if (store.getters.roles.length === 0) { + isRelogin.show = true + store.dispatch('GetInfo').then(() => { + isRelogin.show = false + store.dispatch('GenerateRoutes').then(accessRoutes => { + router.addRoutes(accessRoutes) + next({ ...to, replace: true }) + }) + }).catch(err => { + store.dispatch('LogOut').then(() => { + Message.error(err) + next({ path: '/' }) + }) + }) + } else { + next() + } } - return - } + }).catch(err => { + console.error('政务系统登录失败:', err) + Message.error('政务系统登录失败,请重新登录') + }) + + return +} diff --git a/src/router/index.js b/src/router/index.js index f6fabdd..1b1cbb6 100644 --- a/src/router/index.js +++ b/src/router/index.js @@ -43,7 +43,10 @@ export const constantRoutes = [ }, { path: "/login", - component: () => import("@/views/login"), + // 正式环境登录页 + // component: () => import("@/views/login"), + // 测试 + component: () => import("@/views/login_v1"), hidden: true, }, { @@ -77,7 +80,7 @@ export const constantRoutes = [ component: () => import("@/views/index"), name: "Index", meta: { title: "角色判断", icon: "icon-tjfx-1" }, -hidden:true + hidden: true, }, { path: "/user", diff --git a/src/views/login.vue b/src/views/login.vue index a43ba6e..53998bb 100644 --- a/src/views/login.vue +++ b/src/views/login.vue @@ -203,7 +203,7 @@ export default { window.location.href = 'https://qyt.sipac.gov.cn/sipsg-enterprise-mobile-manage/#/login' }, handleEnterpriseLogin() { - window.location.href = 'https://gysl.sipac.gov.cn'; + // window.location.href = 'https://gysl.sipac.gov.cn'; } } } diff --git a/src/views/login_v1.vue b/src/views/login_v1.vue index 9d91cb0..65811dd 100644 --- a/src/views/login_v1.vue +++ b/src/views/login_v1.vue @@ -1,335 +1,356 @@ - - - - \ No newline at end of file +} + +.el-login-footer { + height: 40px; + line-height: 40px; + position: fixed; + bottom: 0; + width: 100%; + text-align: center; + color: #333; + font-family: Arial; + font-size: 12px; + letter-spacing: 1px; +} + +.login-code-img { + height: 38px; +} + +.el-tabs__item.is-active { + color: #216CDC; + position: relative; + padding-bottom: 0.5rem; +} + \ No newline at end of file