Commit 79ca5926 authored by tianhongyang's avatar tianhongyang

第三方登录逻辑处理优化

parent cd65252f
......@@ -3,18 +3,27 @@ import store from './store';
import { Message } from 'element-ui';
import NProgress from 'nprogress';
import 'nprogress/nprogress.css';
import { getToken, getThirdPlatform } from '@/utils/auth';
import { getToken, getThirdPlatform, checkThirdPlatformChange, removeThirdPlatform, setThirdPlatform } from '@/utils/auth';
import { isRelogin } from '@/utils/request';
NProgress.configure({ showSpinner: false });
const whiteList = ['/login', "/404", "/401"];
router.beforeEach((to, from, next) => {
router.beforeEach(async (to, from, next) => {
// 存在platFormkey但是 已经更换 或本地session不存在 已经存在其它token 重写拉取所有信息
const onlyUrlKey = getThirdPlatform(true);
if (onlyUrlKey && checkThirdPlatformChange(onlyUrlKey)) {
// 前端退出登录
await store.dispatch("FedLogOut");
removeThirdPlatform();
setThirdPlatform(onlyUrlKey);
}
// 默认跳转路径 本系统跳转首页,第三方跳转宏观市场
const platFormKey = getThirdPlatform();
let defaultRedirectPath = platFormKey ? "/macro/nationalEconomies" : "/";
NProgress.start();
// 正常登录 不带第三方
if (getToken()) {
// tab页签title
const { tabTitle, url } = to.query;
......@@ -29,7 +38,10 @@ router.beforeEach((to, from, next) => {
if (!store.state?.user?.userId && !store.state?.user?.roles?.length) {
isRelogin.show = true;
// 判断当前用户是否已拉取完user_info信息
store.dispatch('GetInfo').then(() => {
store.dispatch('GetInfo').then(async (res) => {
if (res?.data?.isThirdPlatformLogin && !platFormKey) {
throw new Error("第三方登录重置,请重新使用platFormKey进入");
}
isRelogin.show = false;
store.dispatch('GenerateRoutes').then(accessRoutes => {
// 根据roles权限生成可访问的路由表
......
......@@ -115,7 +115,6 @@ const user = {
try {
if (!payload) throw new Error("缺少platFormKey");
const tokenInfo = await thirdPlatformLoginApi(payload);
console.log(tokenInfo);
if (tokenInfo.code == 200) {
setToken(tokenInfo.data.token);
commit('SET_TOKEN', tokenInfo.data.token);
......
......@@ -34,20 +34,32 @@ export function setBiAuth(token) {
/**
* 获取第三方app key
* @param {*} onlyUrl 是否仅从url获取
* @returns
*/
export function getThirdPlatform() {
const platForm = sessionStorage.getItem("PLAT_FORM");
if (platForm) return platForm;
export function getThirdPlatform(onlyUrl = false) {
if (!onlyUrl) {
const platForm = sessionStorage.getItem("PLAT_FORM");
if (platForm) return platForm;
}
// sessiongStorage 未获取到appkey 寻找url上的参数
const { platFormKey } = getUrlSearchQuery();
if (platFormKey) {
return setThirdPlatform(platFormKey) ? platFormKey : "";
return platFormKey;
} else {
return "";
};
}
/**
* 检测 appkey是否存在变动
* @param {*} appkey
*/
export function checkThirdPlatformChange(appkey) {
const platForm = sessionStorage.getItem("PLAT_FORM");
return platForm !== appkey;
}
/**
* 储存第三方app key
* @param {*} appkey
......
......@@ -35,12 +35,7 @@ module.exports = {
proxy: {
// detail: https://cli.vuejs.org/config/#devserver-proxy
[process.env.VUE_APP_BASE_API]: {
target: `http://120.46.64.239:9099/prod-api`,//测试
// target: `https://szhapi.jiansheku.com`,//线上
// target: `http://122.9.160.122:9011`, //线上
// target: `http://192.168.0.165:9098`,//施-无线
// target: `http://192.168.60.46:9098`,//施-有线
// target: `http://192.168.60.6:9098`,//谭
target: `http://123.60.218.188:9099/prod-api`,//测试
changeOrigin: true,
pathRewrite: {
['^' + process.env.VUE_APP_BASE_API]: ''
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment