Commit 27e5f99f authored by 杨思琦's avatar 杨思琦

fix: 开启网关免登录修复

parent a2c745dc
Pipeline #72414 waiting for manual action with stages
...@@ -990,7 +990,7 @@ class Login { ...@@ -990,7 +990,7 @@ class Login {
reg = new RegExp(rules); reg = new RegExp(rules);
} }
let check = false; let check = false;
if (rules !== '') check = !reg.test(pwd); if (rules !== '' && pwd) check = !reg.test(pwd);
localStorage.setItem('access_token', response.access_token ? response.access_token : ''); localStorage.setItem('access_token', response.access_token ? response.access_token : '');
if (check) { if (check) {
localStorage.setItem('password_token', response.access_token ? response.access_token : ''); localStorage.setItem('password_token', response.access_token ? response.access_token : '');
......
/* eslint-disable no-prototype-builtins */
/* eslint-disable no-empty */ /* eslint-disable no-empty */
/* eslint-disable react-hooks/exhaustive-deps */ /* eslint-disable react-hooks/exhaustive-deps */
/* eslint-disable no-undef */ /* eslint-disable no-undef */
...@@ -7,6 +8,7 @@ import React, { forwardRef, useEffect, useRef, useState } from 'react'; ...@@ -7,6 +8,7 @@ import React, { forwardRef, useEffect, useRef, useState } from 'react';
import { connect } from 'react-redux'; import { connect } from 'react-redux';
import { useHistory } from '@wisdom-utils/runtime'; import { useHistory } from '@wisdom-utils/runtime';
import { actionCreators } from '@/containers/App/store'; import { actionCreators } from '@/containers/App/store';
import { appService } from '@/api';
import LoginAction from './login'; import LoginAction from './login';
import { defaultApp } from '../../../micro'; import { defaultApp } from '../../../micro';
const Login = forwardRef((props, _ref) => { const Login = forwardRef((props, _ref) => {
...@@ -16,15 +18,56 @@ const Login = forwardRef((props, _ref) => { ...@@ -16,15 +18,56 @@ const Login = forwardRef((props, _ref) => {
const param = params.getParams('redirect')?.replaceAll(';', '&'); const param = params.getParams('redirect')?.replaceAll(';', '&');
return param ? decodeURIComponent(escape(param)) : null; return param ? decodeURIComponent(escape(param)) : null;
}); });
const [token] = useState(() => {
const param = params.getParams('token')?.replaceAll(';', '&');
return param ? decodeURIComponent(escape(param)) : null;
});
// 需要在 GetGateWay 和 GetConfig 之后再执行登录。避免信息错落乱 // 需要在 GetGateWay 和 GetConfig 之后再执行登录。避免信息错落乱
const hasLogin = useRef(); const hasLogin = useRef();
useEffect(() => { useEffect(() => {
action.globalConfig = props.global; action.globalConfig = props.global;
// eslint-disable-next-line no-prototype-builtins // eslint-disable-next-line no-prototype-builtins
if (props.global && props.global.hasOwnProperty('products') && hasLogin.current !== true) { if (
props.global &&
props.global.hasOwnProperty('products') &&
hasLogin.current !== true &&
window.hasLogin !== true
) {
hasLogin.current = true; hasLogin.current = true;
action.init(); window.hasLogin = true;
if (window.globalConfig && window.globalConfig.hasGateWay) {
appService
.authorizationToken({
loginName: token,
type: 'token',
generateType: params.getParams('generateType') || '',
})
.then(res => {
if (res.code === 0) {
const { data } = res;
props.updateConfig &&
props.updateConfig(
Object.assign({}, window.globalConfig, {
access_token: data.access_token,
token: data.user_token,
}),
);
return data;
}
message.error({
duration: 3,
content: `授权失败:${res.msg}`,
});
action && action.events.emit('loginError', res.msg);
return Promise.reject(res);
})
.then(res => {
action.transformLoginHander(res, false);
});
} else {
action.init();
}
} }
}, [action, action.globalConfig, props.global]); }, [action, action.globalConfig, props.global]);
......
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