公共服务平台跳转问题

This commit is contained in:
zzyuan 2026-01-14 08:59:47 +08:00
parent de851f4147
commit f254838154
7 changed files with 69 additions and 11 deletions

View File

@ -108,7 +108,7 @@ export default {
type: 'warning'
}).then(() => {
this.$store.dispatch('LogOut').then(() => {
location.href = '/glweb/';
location.href = '/glweb/#/login';
})
}).catch(() => {});
}

View File

@ -162,7 +162,7 @@ export default {
},
close() {
this.$store.dispatch('LogOut').then(() => {
location.href = '/glweb/';
location.href = '/glweb/#/login';
})
},

View File

@ -5,7 +5,9 @@ import NProgress from 'nprogress'
import 'nprogress/nprogress.css'
import { getToken } from '@/utils/auth'
import { isRelogin } from '@/utils/request'
import {bnsCloudDecrypt} from "@/utils/aes_new";
import Cookies from "js-cookie";
import { encrypt, decrypt } from '@/utils/jsencrypt'
NProgress.configure({ showSpinner: false })
const whiteList = ['/login', '/register']
@ -16,7 +18,7 @@ router.beforeEach((to, from, next) => {
to.meta.title && store.dispatch('settings/setTitle', to.meta.title)
/* has token*/
if (to.path === '/login') {
next({ path: '/' })
next({ path: '/login' })
NProgress.done()
} else if (whiteList.indexOf(to.path) !== -1) {
next()
@ -34,7 +36,7 @@ router.beforeEach((to, from, next) => {
}).catch(err => {
store.dispatch('LogOut').then(() => {
Message.error(err)
next({ path: '/' })
next({ path: '/login' })
})
})
} else {
@ -47,12 +49,32 @@ router.beforeEach((to, from, next) => {
// 在免登录白名单,直接进入
next()
} else {
next(`/login?redirect=${encodeURIComponent(to.fullPath)}`) // 否则全部重定向到登录页
// console.log(to)
if(to.redirectedFrom=='/'){
next(`/login`)
}else{
if(!to.query.params){
next(`/login`)
}else{
let str = bnsCloudDecrypt(to.query.params)
let username = str.split("&")[0].split("=")[1]
let password = str.split("&")[1].split("=")[1]
Cookies.set("username", username, { expires: 30 });
Cookies.set("password", encrypt(password), { expires: 30 });
Cookies.set('rememberMe', true, { expires: 30 });
store.dispatch("Login", {'username':username,'password':password,'loginType':"USERNAME_PASSWORD"}).then(() => {
console.log(3)
next({ ...to, replace: true })
}).catch(() => {});
}
}
NProgress.done()
}
}
})
router.afterEach(() => {
NProgress.done()
})

36
src/utils/aes_new.js Normal file
View File

@ -0,0 +1,36 @@
// src/utils/aesUtil.js
import CryptoJS from 'crypto-js'
//公告服务平台加密参数跳转到本系统后参数解密
/**
* AES解密函数
* @param {string} word - 需要解密的字符串
* @returns {string} 解密后的明文
*/
export function bnsCloudDecrypt(word) {
const key = CryptoJS.enc.Utf8.parse("bonus@cloud@2025")
const decrypt = CryptoJS.AES.decrypt(word, key, {
mode: CryptoJS.mode.ECB,
padding: CryptoJS.pad.Pkcs7
})
return CryptoJS.enc.Utf8.stringify(decrypt).toString()
}
/**
* AES加密函数
* @param {string} word - 需要加密的明文
* @returns {string} 加密后的字符串
*/
export function bnsCloudEncrypt(word) {
const key = CryptoJS.enc.Utf8.parse("bonus@cloud@2025")
const srcs = CryptoJS.enc.Utf8.parse(word)
const encrypted = CryptoJS.AES.encrypt(srcs, key, {
mode: CryptoJS.mode.ECB,
padding: CryptoJS.pad.Pkcs7
})
return encrypted.toString()
}
export default {
bnsCloudDecrypt,
bnsCloudEncrypt
}

View File

@ -1,6 +1,6 @@
import Cookies from 'js-cookie'
const TokenKey = 'Admin-Token'
const TokenKey = 'Glweb-Token'
const ExpiresInKey = 'Admin-Expires-In'

View File

@ -110,7 +110,7 @@ service.interceptors.response.use(res => {
if (res.request.responseType === 'blob' || res.request.responseType === 'arraybuffer') {
return res.data
}
if (code === 401) {
if (code === 401) {
if (!isRelogin.show) {
isRelogin.show = true
MessageBox.confirm('登录状态已过期,您可以继续留在该页面,或者重新登录', '系统提示', {
@ -120,12 +120,12 @@ service.interceptors.response.use(res => {
}).then(() => {
isRelogin.show = false
store.dispatch('LogOut').then(() => {
location.href = '/glweb/'
location.href = '/glweb/#/canteen/index'
})
}).catch(() => {
isRelogin.show = false
})
}
}
return Promise.reject('无效的会话,或者会话已过期,请重新登录。')
} else if (code === 500) {
Message({ message: msg, type: 'error' })

View File

@ -36,7 +36,7 @@ module.exports = {
// detail: https://cli.vuejs.org/config/#devserver-proxy
[process.env.VUE_APP_BASE_API]: {
// target: `http://192.168.2.75:48380`,//旭
target: `http://192.168.20.234:48390`,//测试
target: `http://192.168.0.244:48380`,//测试
// target: `http://192.168.20.242:48380`,//测试
// target: `http://192.168.2.108:48380`,//测试
// target: `http://192.168.0.34:48380`,//测试