Commit 1cc31222 authored by 邓晓峰's avatar 邓晓峰

feat: 添加免密登陆

parent 47aedd6a
Pipeline #40604 passed with stages
...@@ -47,7 +47,7 @@ function App(props) { ...@@ -47,7 +47,7 @@ function App(props) {
</Helmet> </Helmet>
<Router basename={config.base || pkg.name.toLocaleLowerCase() || ''}> <Router basename={config.base || pkg.name.toLocaleLowerCase() || ''}>
<Switch> <Switch>
{renderRoutes(dyRoutes(props.menu || []).routes)} {renderRoutes(dyRoutes(props.menu || [], props.global.layout).routes)}
</Switch> </Switch>
</Router> </Router>
</> </>
......
...@@ -204,7 +204,7 @@ export function logout(data) { ...@@ -204,7 +204,7 @@ export function logout(data) {
localStorage.removeItem('access_token'); localStorage.removeItem('access_token');
// eslint-disable-next-line no-undef,no-restricted-globals // eslint-disable-next-line no-undef,no-restricted-globals
createStoreage.remove(`__PANDA_STORE__${location.hostname}`); createStoreage.remove(`__PANDA_STORE__${location.hostname}`);
createStoreage.remove(`__PANDA_STORE__MICRO_${location.hostname}`)
return { return {
type: LOGINOUT, type: LOGINOUT,
data: { data: {
......
...@@ -93,7 +93,6 @@ const appReducer = (state = initialState, action) => { ...@@ -93,7 +93,6 @@ const appReducer = (state = initialState, action) => {
window.__INITIAL_STATE__.mdi = 'SDI'; window.__INITIAL_STATE__.mdi = 'SDI';
window.__INITIAL_STATE__.menu = 'banner-left'; window.__INITIAL_STATE__.menu = 'banner-left';
window.globalConfig = AppConfig(window.__INITIAL_STATE__); window.globalConfig = AppConfig(window.__INITIAL_STATE__);
// eslint-disable-next-line no-undef // eslint-disable-next-line no-undef
createStoreage.set('globalConfig', window.globalConfig); createStoreage.set('globalConfig', window.globalConfig);
// eslint-disable-next-line no-undef,no-case-declarations // eslint-disable-next-line no-undef,no-case-declarations
...@@ -111,13 +110,14 @@ const appReducer = (state = initialState, action) => { ...@@ -111,13 +110,14 @@ const appReducer = (state = initialState, action) => {
flatMenu = generFlatRoutes(generMenu || [], null, null, modulePkg); flatMenu = generFlatRoutes(generMenu || [], null, null, modulePkg);
} }
const home = flatMenu.find(item => { const home = flatMenu.find(item => {
let path = item.path.split("|"); let path = decodeURI(item.path).split("|");
let currentPath = path[0]; let currentPath = path[0];
if(/^\//.test(currentPath)) { if(/^\//.test(currentPath)) {
currentPath = currentPath.replace(/^\//, ''); currentPath = currentPath.replace(/^\//, '');
} }
return currentPath === homepage return currentPath === decodeURI(homepage)
}); });
let currentMenuIndex = 0; let currentMenuIndex = 0;
......
...@@ -463,7 +463,7 @@ const BasicLayout = props => { ...@@ -463,7 +463,7 @@ const BasicLayout = props => {
useEffect(() => { useEffect(() => {
siteAction.setGlobalConfig(props.global); siteAction.setGlobalConfig(props.global);
if (!Cookies.get('token')) { if (!Cookies.get('token')) {
debugger
let client = props.global.get('client'); let client = props.global.get('client');
client = _.isNull(client) || _.isUndefined(client) || client === 'undefined' ? client: 'city'; client = _.isNull(client) || _.isUndefined(client) || client === 'undefined' ? client: 'city';
history.replace(`/user/login?client=${client}`); history.replace(`/user/login?client=${client}`);
......
...@@ -501,19 +501,8 @@ const BasicLayout = props => { ...@@ -501,19 +501,8 @@ const BasicLayout = props => {
return ( return (
<SecurityLayout loading> <SecurityLayout loading>
{collapse && props.global.loginTemplate === '新春 - 智联.html' ? null : ( {
props.global.loginTemplate === '新春 - 智联.html' && ( props.global.layout !== 'blank' ? (
<img
src={logo}
style={{
width: '120px',
position: 'absolute',
bottom: '40px',
zIndex: 500,
left: '12px',
}}
/>)
)}
<div className={classNames(layoutStyles.basicLayout)}> <div className={classNames(layoutStyles.basicLayout)}>
<div className={layoutStyles['layout-has-slider']} style={{minHeight: '100%'}}> <div className={layoutStyles['layout-has-slider']} style={{minHeight: '100%'}}>
<div style={{ <div style={{
...@@ -661,10 +650,6 @@ const BasicLayout = props => { ...@@ -661,10 +650,6 @@ const BasicLayout = props => {
renderRoutes(props.route.routes) renderRoutes(props.route.routes)
} }
{/* {
!window.location.pathname.startsWith('/civbase/civweb4') && <CreateBaseMap options={{type: 'ArcgisMap'}}/>
} */}
<div id="micro-container" className="subapp-container"> <div id="micro-container" className="subapp-container">
{/*<CreateBaseMap/>*/} {/*<CreateBaseMap/>*/}
{props.children} {props.children}
...@@ -674,7 +659,20 @@ const BasicLayout = props => { ...@@ -674,7 +659,20 @@ const BasicLayout = props => {
</div> </div>
</div> </div>
</div> </div>
</div>): (
<PageContainer style={{paddingTop: '0px', height: '100%'}}>
{
renderRoutes(props.route.routes)
}
<div id="micro-container" className="subapp-container">
{/*<CreateBaseMap/>*/}
{props.children}
</div> </div>
</PageContainer>
)
}
</SecurityLayout>); </SecurityLayout>);
}; };
const mapStateToProps = state => ({ const mapStateToProps = state => ({
......
...@@ -36,7 +36,7 @@ export const initMicroApps = (loader, store) => { ...@@ -36,7 +36,7 @@ export const initMicroApps = (loader, store) => {
/* eslint-disable */ /* eslint-disable */
const config = createStoreage.get('globalConfig'); const config = createStoreage.get('globalConfig');
const application = config.products || []; const application = config && config.products || [];
let products = []; let products = [];
application && Array.isArray(application) && application.length > 0 && application.map(item => { application && Array.isArray(application) && application.length > 0 && application.map(item => {
products.push({ products.push({
...@@ -182,6 +182,7 @@ export const defaultApp = () => { ...@@ -182,6 +182,7 @@ export const defaultApp = () => {
// eslint-disable-next-line no-undef // eslint-disable-next-line no-undef
const config = createStoreage.get('globalConfig'); const config = createStoreage.get('globalConfig');
if (config && config.token) { if (config && config.token) {
debugger
const basePath =config.homepage !== '' && FILTER_FOLER_REG.test(config.homepage) ?'civweb4' :'civweb4'; const basePath =config.homepage !== '' && FILTER_FOLER_REG.test(config.homepage) ?'civweb4' :'civweb4';
if(config && config.home) { if(config && config.home) {
setDefaultMountApp(`/civbase/${config.home.path.replace(/^\//, '')}`); setDefaultMountApp(`/civbase/${config.home.path.replace(/^\//, '')}`);
......
import 'kit_logger'; import 'kit_logger';
import { params } from 'kit_utils';
import { message } from 'antd'; import { message } from 'antd';
import { decode, encode } from 'js-base64'; import { decode, encode } from 'js-base64';
import Cookies from 'js-cookie'; import Cookies from 'js-cookie';
...@@ -33,16 +33,25 @@ class Login { ...@@ -33,16 +33,25 @@ class Login {
} }
init() { init() {
const self = this;
this.loginFailed = false; this.loginFailed = false;
this.guid = Math.round(Math.random() * 10000 + Date.now()).toString(16); this.guid = Math.round(Math.random() * 10000 + Date.now()).toString(16);
this.redirect_state = Cookies.get('redirect_state'); this.redirect_state = Cookies.get('redirect_state');
const token = this.globalConfig.initToken || Cookies.get('token'); const token = this.globalConfig.initToken || Cookies.get('token');
let { ddCode } = this.globalConfig; let { ddCode } = this.globalConfig;
const { loginName } = this.globalConfig; let { loginName } = this.globalConfig;
const { password } = this.globalConfig; let { password } = this.globalConfig;
loginName = params.getParams('loginName') ? params.getParams('loginName'): loginName;
const redirect = params.getParams('redirect');
if(redirect) {
this.globalConfig.homepage = redirect;
this.globalConfig.layout = 'blank';
}
self.updateConfig && self.updateConfig(self.globalConfig);
password = params.getParams('password') ? params.getParams('password'): password;
const loginMode = Cookies.get('loginMode') || null; const loginMode = Cookies.get('loginMode') || null;
if (loginMode && loginMode === 'iotWechat') ddCode = null; if (loginMode && loginMode === 'iotWechat') ddCode = null;
const self = this;
// self.qrcodeLogin(self.globalConfig.qrcodeData.code); // self.qrcodeLogin(self.globalConfig.qrcodeData.code);
if (token) { if (token) {
self.getToweb(token); self.getToweb(token);
...@@ -52,6 +61,7 @@ class Login { ...@@ -52,6 +61,7 @@ class Login {
} else if (ddCode && loginMode === 'qywx') { } else if (ddCode && loginMode === 'qywx') {
self.qywxLoginIn(ddCode); self.qywxLoginIn(ddCode);
} else if (!!loginName && !!password) { } else if (!!loginName && !!password) {
self.otherLoginIn(loginName, password); self.otherLoginIn(loginName, password);
} else if ( } else if (
self.globalConfig.qrcodeData && self.globalConfig.qrcodeData &&
...@@ -199,6 +209,7 @@ class Login { ...@@ -199,6 +209,7 @@ class Login {
'request.preventCache': Date.now(), 'request.preventCache': Date.now(),
}) })
.then(response => { .then(response => {
const result = const result =
response && response.code === SERVICE_INTERFACE_SUCCESS_CODE response && response.code === SERVICE_INTERFACE_SUCCESS_CODE
? Array.isArray(response.data) ? Array.isArray(response.data)
...@@ -206,10 +217,12 @@ class Login { ...@@ -206,10 +217,12 @@ class Login {
: [] : []
: response; : response;
if (result && result.length > 0) { if (result && result.length > 0) {
self.globalConfig = Object.assign(self.globalConfig, result.shift(), { const config = result.shift();
self.globalConfig = Object.assign(self.globalConfig, config, {
theme: self.globalConfig.theme, theme: self.globalConfig.theme,
menu: self.globalConfig.menu, menu: self.globalConfig.menu,
style: self.globalConfig.style, style: self.globalConfig.style,
homepage: params.getParams('redirect') || self.globalConfig.homepage || config.homepage
}); });
if(self.globalConfig.hasOwnProperty('webConfig')) { if(self.globalConfig.hasOwnProperty('webConfig')) {
...@@ -301,6 +314,7 @@ class Login { ...@@ -301,6 +314,7 @@ class Login {
} }
}) })
.catch(error => { .catch(error => {
console.log(error);
// Logger.log(error); // Logger.log(error);
this.handleLoginError(); this.handleLoginError();
// Logger.log('获取网络配置失败'); // Logger.log('获取网络配置失败');
...@@ -394,6 +408,7 @@ class Login { ...@@ -394,6 +408,7 @@ class Login {
} }
goLogin() { goLogin() {
debugger
if ( if (
this.globalConfig.style === 'ios' && this.globalConfig.style === 'ios' &&
this.globalConfig.loginTemplate === 'IOSCloud.html' this.globalConfig.loginTemplate === 'IOSCloud.html'
...@@ -570,8 +585,8 @@ class Login { ...@@ -570,8 +585,8 @@ class Login {
} }
otherLoginIn(usr, pwd) { otherLoginIn(usr, pwd) {
const uesrName = decode(usr.substring(0, usr.length - 3)); // const uesrName = decode(usr.substring(0, usr.length - 3));
const password = decode(pwd.substring(0, pwd.length - 3)); // const password = decode(pwd.substring(0, pwd.length - 3));
const self = this; const self = this;
// eslint-disable-next-line no-undef // eslint-disable-next-line no-undef
appService appService
...@@ -579,16 +594,20 @@ class Login { ...@@ -579,16 +594,20 @@ class Login {
f: 'json', f: 'json',
expiration: this.globalConfig.expiration, // token过期时间(单位:秒) expiration: this.globalConfig.expiration, // token过期时间(单位:秒)
client: 'referer', client: 'referer',
username: uesrName, username: usr,
password: sha1(password).toUpperCase(), password: sha1(pwd).toUpperCase(),
referer: this.globalConfig.client, referer: this.globalConfig.client,
skipMenuTest: 1, skipMenuTest: 1,
generateType: 'pandaoa'
}) })
.then(response => { .then(response => {
debugger
self.globalConfig.layout = 'blank';
if (response && response.token) { if (response && response.token) {
const tk = response.token; const tk = response.token;
this.globalConfig.token = tk; self.globalConfig.token = tk;
// eslint-disable-next-line no-undef,no-debugger // eslint-disable-next-line no-undef,no-debugger
getUserInfo( getUserInfo(
{ {
token: tk, token: tk,
...@@ -600,17 +619,54 @@ class Login { ...@@ -600,17 +619,54 @@ class Login {
) )
// eslint-disable-next-line no-shadow // eslint-disable-next-line no-shadow
.then(response => { .then(response => {
if (response && response.errMsg) {
this.globalConfig.userInfo = {}; try {
if ( if (response && !response.errMsg) {
response.data.Groups && self.globalConfig.userInfo = Object.assign(
response.data.Groups instanceof Array && {},
response.data.Groups.length response,
) { self.globalConfig.userInfo,
this.globalConfig.userInfo.Groups = response.data.Groups; );
if(response.hasOwnProperty('data')) {
self.globalConfig.userInfo = {
... self.globalConfig.userInfo,
...response.data
}
} }
const date = new Date();
date.setTime(date.getTime() + 24 * 60 * 60 * 1000);
// date = date.toGMTString();
const encodeSite = encode(encodeURIComponent(response.site));
Cookies.set('site', encodeSite, {
expires: date,
path: '/',
});
Cookies.set('token', tk, {
expires: date,
path: '/',
})
// self.globalConfig.Industry = industry;
self.updateConfig && self.updateConfig(self.globalConfig); self.updateConfig && self.updateConfig(self.globalConfig);
self.getUserInfoAndConfig(); const loginSite = {};
loginSite[tk] = response.site;
// Cookie.set()
localStorage.setItem('loginSite', JSON.stringify(loginSite));
self.writeLogs();
self.getIndustry(false, tk);
} else {
message.error(response.errMsg);
if (self.goLogin()) {
return false;
}
// self.handleLoginError(failCallback);
}
self.updateConfig && self.updateConfig(self.globalConfig);
} catch (error) {
console.log(error);
if (self.goLogin()) {
return false;
}
// self.handleLoginError(failCallback);
} }
}); });
} else { } else {
......
import 'kit_utils/lib/format';
import React, { forwardRef, useEffect, useRef, useState } from 'react';
import { params } from 'kit_utils';
import { connect } from 'react-redux';
import { useHistory, withRouter } from '@wisdom-utils/runtime';
import { actionCreators } from '@/containers/App/store';
import LoginAction from './login';
const Login = forwardRef((props, _ref) => {
const history = useHistory();
const [action, setAction] = useState(
() => new LoginAction(Object.assign({}, props, {history}), () => {}, true),
);
useEffect(() => {
action.globalConfig = props.global;
}, [props.global]);
useEffect(() => {
action &&
action.events.on('loginSuccess', event => {
//http://127.0.0.1:8080/civbase/civweb4/
// props.updateConfig(Object.assign({}, props.global, {
// homepage: params.getParams('redirect')
// }));
// props.history.push('/' + params.getParams('redirect'))
props.history.push(`/?client=${props.global.client}`);
window.share.event.emit('triggerMicro', props.global);
});
}, [props.globalConfig && props.globalConfig.userInfo])
// action &&
// action.events.on('loginError', event => {
// // setVisible(false);
// // setSubmitting(false);
// });
return <div>{props.children}</div>;
});
const mapStateToProps = state => ({
global: state.getIn(['global', 'globalConfig']),
loginMode: state.getIn(['global', 'loginMode']),
});
const mapDispatchToProps = dispatch => ({
updateConfig(config) {
dispatch(actionCreators.getConfig(config));
},
createContext(data) {
dispatch(actionCreators.createContext(data));
},
updateLoginMode(mode) {
dispatch(actionCreators.changeLoginMode(mode));
},
updateCurrentIndex(index) {
dispatch(actionCreators.updateCurrentIndex(index));
},
});
export default connect(
mapStateToProps,
mapDispatchToProps,
)(Login);
...@@ -6,8 +6,9 @@ import UserLayout from '../layouts/UserLayout'; ...@@ -6,8 +6,9 @@ import UserLayout from '../layouts/UserLayout';
import BootPage from '../pages/bootpage'; import BootPage from '../pages/bootpage';
import Login from '../pages/user/login'; import Login from '../pages/user/login';
import CommonMenu from '../pages/commonMenu'; import CommonMenu from '../pages/commonMenu';
import NoSecret from '../pages/user/login/noSecret';
export const dyRoutes = routes => { export const dyRoutes = (routes, layout) => {
// eslint-disable-next-line no-shadow // eslint-disable-next-line no-shadow
const dyRoutes = routes || []; const dyRoutes = routes || [];
return { return {
...@@ -21,6 +22,11 @@ export const dyRoutes = routes => { ...@@ -21,6 +22,11 @@ export const dyRoutes = routes => {
path: '/user/login', path: '/user/login',
component: Login, component: Login,
}, },
{
name: 'noscret',
path: '/user/noscret',
component: NoSecret
}
], ],
}, },
{ {
......
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