Commit 7d920eea authored by 周宏民's avatar 周宏民

feat:弥勒集成登录 支持client

parent c5efa399
Pipeline #92457 waiting for manual action with stages
...@@ -188,8 +188,9 @@ export function updatePdCesiumView(data) { ...@@ -188,8 +188,9 @@ export function updatePdCesiumView(data) {
export function logout(data) { export function logout(data) {
// eslint-disable-next-line no-undef // eslint-disable-next-line no-undef
createStoreage.remove('PANDA_STORE'); createStoreage.remove('PANDA_STORE');
const integrationClient = localStorage.getItem('integrationClient');
if (window.globalConfig) { if (window.globalConfig) {
Cookies.set(window.globalConfig.client, '', { Cookies.set(integrationClient || window.globalConfig.client, '', {
path: '/', path: '/',
}); });
window.globalConfig.token = null; window.globalConfig.token = null;
...@@ -198,6 +199,9 @@ export function logout(data) { ...@@ -198,6 +199,9 @@ export function logout(data) {
window.globalConfig.baseURI = window.location.origin; window.globalConfig.baseURI = window.location.origin;
window.globalConfig.hasGateWay = false; window.globalConfig.hasGateWay = false;
window.globalConfig.userInfo = null; window.globalConfig.userInfo = null;
if (integrationClient) {
window.globalConfig.client = integrationClient;
}
window.qiankunIsCache = null; window.qiankunIsCache = null;
window.qiankunStarted = false; window.qiankunStarted = false;
// window.globalConfig.hasGateWay = ; // window.globalConfig.hasGateWay = ;
...@@ -220,6 +224,11 @@ export function logout(data) { ...@@ -220,6 +224,11 @@ export function logout(data) {
Cookies.set('singleToken', '', { Cookies.set('singleToken', '', {
path: '/', path: '/',
}); });
// 如果有集成登录client,则 client 切换成集成登录
if (integrationClient) {
sessionStorage.setItem('client', integrationClient);
}
localStorage.removeItem('integrationClient');
localStorage.removeItem('access_token'); localStorage.removeItem('access_token');
localStorage.removeItem('password_token'); localStorage.removeItem('password_token');
localStorage.removeItem('password_pwdRegex'); localStorage.removeItem('password_pwdRegex');
......
...@@ -326,6 +326,8 @@ const Layout = props => { ...@@ -326,6 +326,8 @@ const Layout = props => {
!_.isNull(generateType) && !_.isUndefined(generateType) && generateType !== 'undefined' !_.isNull(generateType) && !_.isUndefined(generateType) && generateType !== 'undefined'
? `&generateType=${generateType}` ? `&generateType=${generateType}`
: ''; : '';
const integrationClient = localStorage.getItem('integrationClient');
if(integrationClient) client = integrationClient
if (!isLogin) { if (!isLogin) {
history.push(`/user/login?client=${client}${generateType}`, { reload: true }); history.push(`/user/login?client=${client}${generateType}`, { reload: true });
clear(); clear();
...@@ -385,11 +387,14 @@ const Layout = props => { ...@@ -385,11 +387,14 @@ const Layout = props => {
const GetIntegrationConfig = () => { const GetIntegrationConfig = () => {
if (first) { if (first) {
const integrationClient = localStorage.getItem('integrationClient');
appService appService
.GetIntegrationConfig({ .GetIntegrationConfig({
type: '集成登录', type: '集成登录',
userId: window.globalConfig.userInfo?.OID ?? null, userId: window.globalConfig.userInfo?.OID ?? null,
isEnable: true, isEnable: true,
client: integrationClient || '' // 只有指定client才能获取集成登录信息
}) })
.then(res => { .then(res => {
setFirst(false); setFirst(false);
......
...@@ -4,6 +4,7 @@ import { log, params, encipher } from '@wisdom-utils/utils/lib/helpers'; ...@@ -4,6 +4,7 @@ import { log, params, encipher } from '@wisdom-utils/utils/lib/helpers';
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';
import { SlideVerify } from '@wisdom-utils/components';
import { appService, noticeService } from '@/api'; import { appService, noticeService } from '@/api';
import { getUserInfo, getWebSiteConfig } from '@/api/service/base'; import { getUserInfo, getWebSiteConfig } from '@/api/service/base';
import { SERVICE_APP_LOGIN_MODE, SERVICE_INTERFACE_SUCCESS_CODE, WX_REDIRECT_URI } from '@/constants'; import { SERVICE_APP_LOGIN_MODE, SERVICE_INTERFACE_SUCCESS_CODE, WX_REDIRECT_URI } from '@/constants';
...@@ -14,6 +15,7 @@ import { ...@@ -14,6 +15,7 @@ import {
DEFAULT_TCP_PORT, DEFAULT_TCP_PORT,
DEFAULT_PARSE_LEVEL, DEFAULT_PARSE_LEVEL,
} from '@wisdom-utils/components/lib/AppLayout/notifier/constants'; } from '@wisdom-utils/components/lib/AppLayout/notifier/constants';
import { guidePage } from '@/pages/bootpage/template/constants';
// eslint-disable-next-line no-undef // eslint-disable-next-line no-undef
const Logger = logger('login'); const Logger = logger('login');
...@@ -29,12 +31,308 @@ class Login { ...@@ -29,12 +31,308 @@ class Login {
this.globalConfig = getGlobalConfig(); this.globalConfig = getGlobalConfig();
}; };
// 单点登录_xule_20231214
const queryString = window.location.search.substring(1);
const params = queryString.split('&');
const paramsFind =
params &&
params.find(function(a) {
return a.split('=')[0] == 'uniwater_utoken';
});
this.uniwater_utoken = paramsFind?.split('=')[1] ?? '';
// 单页面免登重定向地址
const redirect =
params &&
params.find(function(a) {
return a.split('=')[0] === 'redirect';
});
if (this.uniwater_utoken && !redirect) {
this.getTokenForThird();
}
this.createContext = props.createContext; this.createContext = props.createContext;
this.history = props.history; this.history = props.history;
this.callback = callback; this.callback = callback;
this.integratedNum = 0; this.integratedNum = 0;
this.hasTry = false; this.hasTry = false;
this.logout = props.logout; this.logout = props.logout;
if (isInit) {
this.init();
}
}
// 第三方单页面免登
getTokenThirdLogin(tk) {
const self = this;
self.globalConfig.token = tk;
self.updateConfig && self.updateConfig(self.globalConfig);
}
// 单点登录接口_xule_20231214
getTokenForThird() {
const self = this;
appService
.HDAuthLogin({
token: self.uniwater_utoken,
ignoreSite: true,
})
.then(res => {
if (res.success === 'OK') {
const tk = res.token;
self.globalConfig.token = tk;
const param = {
subOID: 'subOID',
site: this.getLocalSiteBytoken(tk),
ignoreSite: true,
};
if (window.location?.host === 'panda-water.cn') {
param.token = tk;
} else {
param.identity = tk;
}
getUserInfo(param)
.then(response => {
try {
if (response && response.code === 0) {
self.globalConfig.userInfo = window?.globalConfig?.transformUserInfo?.(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.isSignIn = true;
self.updateConfig && self.updateConfig(self.globalConfig);
const loginSite = {};
loginSite[tk] = response.site;
localStorage.setItem('loginSite', JSON.stringify(loginSite));
self.writeLogs();
self.getIndustry(false, tk);
} else {
message.error(response.errMsg);
if (self.goLogin()) {
return false;
}
}
self.updateConfig && self.updateConfig(self.globalConfig);
} catch (error) {
message.error('登录失败');
if (self.goLogin()) {
return false;
}
}
})
.catch(error => {
this.handleLoginError();
Logger.log('获取用户配置失败');
});
}
});
}
gzlogin(userPhone) {
this.login(userPhone, '', userPhone, false, SERVICE_APP_LOGIN_MODE.phone);
}
gztransformLoginHander(response, isRememberPWD, pwd) {
const self = this;
// eslint-disable-next-line prettier/prettier
const token =
response &&
(response.token
? response.token
: response.access_token !== null && response.user_token !== null
? response.user_token
: '');
if (token) {
const exp = 86400000;
self.globalConfig.token = token;
if (response.access_token !== '') {
self.globalConfig.access_token = response.access_token;
self.updateConfig && self.updateConfig(self.globalConfig);
let rules = localStorage.getItem('password_pwdRegex') ? localStorage.getItem('password_pwdRegex') : '';
let reg;
try {
reg = new RegExp(rules);
} catch (error) {
rules = '';
reg = new RegExp(rules);
}
let check = false;
if (rules !== '') check = !reg.test(pwd);
localStorage.setItem('access_token', response.access_token ? response.access_token : '');
if (check) {
localStorage.setItem('password_token', response.access_token ? response.access_token : '');
}
Cookies.set('client', self.globalConfig.client, {
expires: exp / (24 * 60 * 60 * 1000),
path: '/',
});
}
if (isRememberPWD) {
Cookies.set('client', self.globalConfig.client, {
expires: exp / (24 * 60 * 60 * 1000),
path: '/',
});
Cookies.set('token', token, {
expires: exp / (24 * 60 * 60 * 1000),
path: '/',
});
}
sessionStorage.setItem('client', self.globalConfig.client);
self.isSignIn = true;
self.updateConfig && self.updateConfig(self.globalConfig);
self.getUserInfoAndConfig();
} else {
self.hasTry = true;
self.events.emit('loginError', response);
message.error(response.error.message);
self.callback && self.callback(false);
}
}
// 获取手机号
getIpone() {
const self = this;
const accessToken = params.getParams('access_token');
return appService.getUserMobile({
// isTest: true,
access_token: accessToken,
});
}
init(site) {
const self = this;
this.loginFailed = false;
this.guid = Math.round(Math.random() * 10000 + Date.now()).toString(16);
this.redirect_state = Cookies.get('redirect_state');
const token =
this.globalConfig.initToken ||
Cookies.get('token') ||
params.getParams('token') ||
this.globalConfig.token ||
null;
const noTokenSite = site ?? null;
let { ddCode } = this.globalConfig;
let { loginName } = this.globalConfig;
let { password } = this.globalConfig;
loginName = params.getParams('loginName') ? params.getParams('loginName') : loginName;
const homepage = params.getParams('homepage');
const generateType = params.getParams('generateType');
const authCode = params.getParams('authCode');
if (homepage) {
this.globalConfig.homepage = homepage;
// this.globalConfig.layout = 'blank';
}
if (generateType) {
this.globalConfig.generateType = generateType;
}
self.updateConfig && self.updateConfig(self.globalConfig);
password = params.getParams('password') ? params.getParams('password') : password;
const loginMode = Cookies.get('loginMode') || null;
if (loginMode && loginMode === 'iotWechat') ddCode = null;
// self.qrcodeLogin(self.globalConfig.qrcodeData.code);
if (token) {
if (loginMode === 'qywx') {
// 微信登录刷新退出登录
Cookies.set('token', '', {
path: '/',
});
const client = this?.global?.client || sessionStorage.getItem('client') || null;
window.location.href = `${WX_REDIRECT_URI}?client=${client}`;
return;
}
self.getToweb(token, noTokenSite);
// eslint-disable-next-line no-empty
} else if (ddCode && loginMode === 'dingding') {
self.ddLoginIn(ddCode);
} else if (ddCode && loginMode === 'qywx') {
// 云平台和信息化都有企业微信,得区分(接口定义里面做了判断)
self.qywxLoginIn(ddCode);
} else if ((!!loginName && !!password) || !!authCode) {
self.otherLoginIn(loginName, password, authCode);
} else if (
self.globalConfig.qrcodeData &&
(self.globalConfig.qrcodeData.state && self.globalConfig.qrcodeData.state === this.redirect_state) &&
self.globalConfig.qrcodeData.code !== ''
) {
self.qrcodeLogin(self.globalConfig.qrcodeData.code);
} else if (!!self.globalConfig.isSingleLogin && !!self.globalConfig.singleLoginCode) {
//
} else if (
window.globalConfig.subtitle === '广州节约用水管理系统'
// && this.props.location.pathname.indexOf('noscret') > -1
) {
self.getIpone().then(v => {
if (v.code === 0) {
this.gzlogin(v.data.userMobile || v.data.loginName);
} else {
this.goLogin();
}
});
} else if (self.goLogin()) {
return false;
}
}
getToweb(token, noTokenSite) {
this.globalConfig.token = token;
const self = this;
// eslint-disable-next-line no-undef
const param = {
subOID: 'subOID',
site: noTokenSite ?? this.getLocalSiteBytoken(token),
'request.preventCache': Date.now(),
ignoreSite: true,
};
if (window.location?.host === 'panda-water.cn') {
param.token = this.globalConfig.token;
} else {
param.identity = this.globalConfig.token;
}
getUserInfo(param)
.then(response => {
if (response && response.code === 0) {
self.isSignIn = true;
self.globalConfig.userInfo = window?.globalConfig?.transformUserInfo?.(response.data) ?? {};
self.updateConfig && self.updateConfig(self.globalConfig);
let flag = true;
const loginMode = Cookies.get('loginMode');
if (loginMode === 'qywx') {
flag = false;
}
// flag 为true 时,不会进引导页或集成登录
self.getUserInfoAndConfig(null, flag);
} else {
self.logout && self.logout();
if (params.getParams('token')) {
// token免登录失败,回到登录页,防止reload造成死循环
window.location.href = `${window.location.origin}`;
return false;
}
if (self.globalConfig.style === 'ios' && self.globalConfig.loginTemplate === 'IOSCloud.html') {
window.location.href = `${window.location.origin}`;
return false;
}
window.location.reload();
}
})
.catch(error => {
this.handleLoginError();
Logger.log('获取用户配置失败');
});
} }
writeLogs() { writeLogs() {
...@@ -82,23 +380,23 @@ class Login { ...@@ -82,23 +380,23 @@ class Login {
} }
}); });
} }
// eslint-disable-next-line prettier/prettier if (!flag && this.isSignIn && !window.qiankunStarted) {
if ( const item = guidePage.find(g => g.value === this.globalConfig.displayMode);
!flag && // 到引导页
this.isSignIn && if (this.globalConfig.displayMode !== 'default' && item) {
this.globalConfig.userInfo.Industries.length && this.createContext(this);
this.globalConfig.userInfo.Industries.length > 1 this.updateConfig && this.updateConfig(this.globalConfig);
) { this.events && this.events.emit('loginIndustry');
this.createContext(this); return false;
this.updateConfig && this.updateConfig(this.globalConfig); }
this.history.push('/industry'); // this.globalConfig.isIntegration 为系统配置表里 是否集成登录
return false; // integratedNum 为当前站点配置的集成登录数量,
} if (this.globalConfig.isIntegration >= 1 && this.integratedNum >= 2) {
// 跳转到集成登录引导页_xule_2023-08-28 this.events && this.events.emit('loginIndustry');
if (!flag && this.isSignIn && this.globalConfig.isIntegration >= 1 && this.integratedNum >= 2) { return false;
this.history.push('/industry'); }
return false;
} }
this.initGateWay(token, getIndustry); this.initGateWay(token, getIndustry);
} }
...@@ -120,12 +418,11 @@ class Login { ...@@ -120,12 +418,11 @@ class Login {
}, time); }, time);
} }
initGateWay(token, getIndustry, failCallback) { initGateWay(token, getIndustry) {
const self = this; const self = this;
const gateWayParam = { const gateWayParam = {
_site: this?.globalConfig?.userInfo?.site ?? '', _site: this?.globalConfig?.userInfo?.site ?? '',
}; };
appService appService
.getWateWayConfig(gateWayParam) .getWateWayConfig(gateWayParam)
.then(res => { .then(res => {
...@@ -167,7 +464,7 @@ class Login { ...@@ -167,7 +464,7 @@ class Login {
}) })
.then(() => { .then(() => {
// eslint-disable-next-line no-use-before-define // eslint-disable-next-line no-use-before-define
this.getWebConfig(token, getIndustry, failCallback); this.getWebConfig(token, getIndustry);
}) })
.catch(err => { .catch(err => {
self.updateConfig(self.globalConfig); self.updateConfig(self.globalConfig);
...@@ -180,11 +477,12 @@ class Login { ...@@ -180,11 +477,12 @@ class Login {
} }
}) })
.catch(err => { .catch(err => {
this.events.emit('loginError', '该站点无法访问,请联系管理人员'); // eslint-disable-next-line no-use-before-define
this.getWebConfig(token, getIndustry);
}); });
} }
getWebConfig(token, getIndustry, failCallback) { getWebConfig(token, getIndustry) {
const self = this; const self = this;
// eslint-disable-next-line no-undef // eslint-disable-next-line no-undef
// 获取网站配置的同时,预先获取到mqtt配置,注册进子应用 // 获取网站配置的同时,预先获取到mqtt配置,注册进子应用
...@@ -346,7 +644,9 @@ class Login { ...@@ -346,7 +644,9 @@ class Login {
self.globalConfig.uiwidgets = [self.globalConfig.shareWidget]; self.globalConfig.uiwidgets = [self.globalConfig.shareWidget];
self.globalConfig.widgets = []; self.globalConfig.widgets = [];
} }
// this.events.removeAllListeners('loginSuccess')
// this.events.removeAllListeners('toggleIndustry')
// window.share.event = this.events;
if ( if (
self.globalConfig.userInfo && self.globalConfig.userInfo &&
self.globalConfig.userInfo.site && self.globalConfig.userInfo.site &&
...@@ -407,10 +707,13 @@ class Login { ...@@ -407,10 +707,13 @@ class Login {
headerPrimaryColor: mainConf.headerPrimaryColor, headerPrimaryColor: mainConf.headerPrimaryColor,
}; };
} }
// if (mainConf.productType)
// self.globalConfig.productType = mainConf.productType;
} }
this.isOpenYanshi(self, getIndustry); this.isOpenYanshi(self, getIndustry);
}); });
} else { } else {
// loginSuccess
this.isOpenYanshi(self, getIndustry); this.isOpenYanshi(self, getIndustry);
} }
}); });
...@@ -419,13 +722,13 @@ class Login { ...@@ -419,13 +722,13 @@ class Login {
return false; return false;
} }
this.handleLoginError(); this.handleLoginError();
this.events.emit('loginError', '获取网络配置失败'); // Logger.log('获取网络配置失败');
} }
}) })
.catch(error => { .catch(error => {
// Logger.log(error); // Logger.log(error);
this.handleLoginError(); this.handleLoginError();
this.events.emit('loginError', '获取网络配置失败'); // Logger.log('获取网络配置失败');
}); });
} }
...@@ -444,7 +747,6 @@ class Login { ...@@ -444,7 +747,6 @@ class Login {
self.getYanshiAuthority(self, getIndustry); self.getYanshiAuthority(self, getIndustry);
}) })
.catch(error => { .catch(error => {
this.events.emit('loginError', '服务请求异常');
this.handleLoginError(); this.handleLoginError();
}); });
} else { } else {
...@@ -457,23 +759,23 @@ class Login { ...@@ -457,23 +759,23 @@ class Login {
} }
finish(self, getIndustry) { finish(self, getIndustry) {
self.events.emit('onendLoading'); window.finishRender = true;
setTimeout(() => { getIndustry ? self.events.emit('toggleIndustry') : self.events.emit('loginSuccess');
window.finishRender = true; window.share.event = self.events;
getIndustry ? self.events.emit('toggleIndustry') : self.events.emit('loginSuccess'); self.callback && self.callback();
window.share.event = self.events;
self.callback && self.callback();
}, 100);
} }
getYanshiAuthority(self, getIndustry) { getYanshiAuthority(self, getIndustry) {
// self.updateConfig && self.updateConfig(self.globalConfig); // self.updateConfig && self.updateConfig(self.globalConfig);
if (self.globalConfig.widgets.length === 0) { if (self.globalConfig.widgets.length === 0) {
message.error({
duration: 3,
content: '当前账号未配置菜单',
});
self.events.emit('loginError', '当前账号未配置菜单'); self.events.emit('loginError', '当前账号未配置菜单');
self.handleLoginError(); self.handleLoginError();
return; return;
} }
if (self.globalConfig.isOpenTransitionPage) { if (self.globalConfig.isOpenTransitionPage) {
appService appService
.getTransitionPage() .getTransitionPage()
...@@ -503,6 +805,7 @@ class Login { ...@@ -503,6 +805,7 @@ class Login {
if (transitionPage.content.length > 0) { if (transitionPage.content.length > 0) {
self.globalConfig.transitionPage = transitionPage; self.globalConfig.transitionPage = transitionPage;
self.updateConfig && self.updateConfig(self.globalConfig); self.updateConfig && self.updateConfig(self.globalConfig);
window.finishRender = true;
self.events.emit('loginHomePage'); self.events.emit('loginHomePage');
window.share.event = self.events; window.share.event = self.events;
return self.callback && self.callback(); return self.callback && self.callback();
...@@ -591,6 +894,10 @@ class Login { ...@@ -591,6 +894,10 @@ class Login {
this.globalConfig.mapsettings.basemaps = layer.basemaps; this.globalConfig.mapsettings.basemaps = layer.basemaps;
} }
// this.updateConfig && this.updateConfig(Object.assign({}, this.globalConfig, {
// mapsettings: this.globalConfig.mapsettings
// }));
// console.log("mapsettings", this.globalConfig.mapsettings)
return Promise.resolve(this.globalConfig.mapsettings); return Promise.resolve(this.globalConfig.mapsettings);
} }
...@@ -639,8 +946,254 @@ class Login { ...@@ -639,8 +946,254 @@ class Login {
return s; return s;
} }
// 企业微信登录
loginByWx() {
window.WwLogin({
id: 'wxlogin_container',
appid: 'wxec56ca668e7f9155',
agentid: '1000083',
redirect_uri: encodeURIComponent(window.location.href),
href: 'https://mis.panda-water.cn/web4/styles/wx.css',
});
}
qywxLoginIn(code) {
// eslint-disable-next-line no-undef
const self = this;
appService
.getInfo({
code,
cacheBust: true,
})
.then(response => {
if (response && response.getMe && response.getMe.length) {
const tk = response.getMe[0].Token;
self.globalConfig.token = tk;
Cookies.set('token', tk);
let url = window.location.href; // 获取当前页面的url
if (url.indexOf('&code') !== -1) {
// 判断是否存在参数
// eslint-disable-next-line no-useless-escape
url = url.replace(/(\&code|#)[^'"]*/, '&code=success'); // 去除参数
window.history.pushState({}, 0, url);
}
self.isSignIn = true;
self.getUserInfoAndConfig();
} else {
self.handleLoginError();
message.error('登录失败,用户信息错误');
self.hasTry = true; // 已经输错过密码
}
});
}
loginByDD() {
const gotoUrl = `https://oapi.dingtalk.com/connect/oauth2/sns_authorize?appid=dingoakne99srqra6hldv2&response_type=code&scope=snsapi_login&state=STATE&redirect_uri=${encodeURIComponent(
window.location.href,
)}`;
// eslint-disable-next-line no-undef
const obj = DDLogin({
id: 'login_container',
goto: encodeURIComponent(gotoUrl),
style: 'border:none;background-color:#FFFFFF;',
width: '365',
height: '400',
});
const handleMessage = function(event) {
const { origin } = event;
// Logger.log('origin', event.origin);
if (origin === 'https://login.dingtalk.com') {
// 判断是否来自ddLogin扫码事件。
const loginTmpCode = event.data;
const redirectUrl = `https://oapi.dingtalk.com/connect/oauth2/sns_authorize?appid=dingoakne99srqra6hldv2&response_type=code&scope=snsapi_login&state=STATE&redirect_uri=${encodeURIComponent(
window.location.href,
)}&loginTmpCode=${loginTmpCode}`;
// 获取到loginTmpCode后就可以在这里构造跳转链接进行跳转了
window.location.href = redirectUrl;
}
};
if (typeof window.addEventListener !== 'undefined') {
window.addEventListener('message', handleMessage, false);
} else if (typeof window.attachEvent !== 'undefined') {
window.attachEvent('onmessage', handleMessage);
}
}
ddLoginIn(code) {
// eslint-disable-next-line no-undef
const self = this;
appService
.getOA({
TmpAuthCode: code,
cacheBust: true,
})
.then(response => {
if (response && response.getMe && response.getMe.length) {
const tk = response.getMe[0].token;
self.globalConfig.token = tk;
Cookies.set('token', tk);
let url = window.location.href; // 获取当前页面的url
if (url.indexOf('&code') !== -1) {
// 判断是否存在参数
// eslint-disable-next-line no-useless-escape
url = url.replace(/(\&code|#)[^'"]*/, ''); // 去除参数
window.history.pushState({}, 0, url);
}
self.isSignIn = true;
self.getUserInfoAndConfig();
} else {
self.handleLoginError();
// msgUtils.fault("登录失败,请检查用户名或密码");
// msgUtils.fault("登录失败," + error.message);
self.hasTry = true; // 已经输错过密码
}
});
}
qrcodeLogin(code) {
const self = this;
// eslint-disable-next-line no-undef
appService
.generatetokenByqrcode({
f: 'json',
expiration: self.globalConfig.expiration || 43200000,
referer: self.globalConfig.client,
skipMenuTest: 1,
qrcode: code,
cacheBust: true,
})
.then(response => {
if (response.token) {
self.globalConfig.token = response.token;
Cookies.set('token', response.token);
self.updateConfig && self.updateConfig(this.globalConfig);
self.isSignIn = true;
self.getUserInfoAndConfig();
// Logger.log('===getUserInfoAndConfig===');
} else {
message.error(`登录失败,${response.message}`);
self.events.emit('loginError', response);
setTimeout(() => {
self.handleLoginError(() => {
window.location.href = WX_REDIRECT_URI;
});
}, 600);
}
})
.catch(error => {
// eslint-disable-next-line no-undef
message.error(`登录失败,${error.message}`);
// eslint-disable-next-line no-undef
self.events.emit('loginError', error);
setTimeout(() => {
self.handleLoginError(() => {
window.location.href = WX_REDIRECT_URI;
});
}, 600);
});
}
otherLoginIn(usr, pwd, code) {
// const uesrName = decode(usr.substring(0, usr.length - 3));
// const password = decode(pwd.substring(0, pwd.length - 3));
const self = this;
// eslint-disable-next-line no-undef
appService
.generateToken({
f: 'json',
expiration: this.globalConfig.expiration, // token过期时间(单位:秒)
client: 'referer',
username: usr,
// password: params.getParams('generateType') ? pwd : sha1(pwd).toUpperCase(),
password: params.getParams('generateType') ? pwd : encipher(pwd, this.globalConfig.encrypt).toUpperCase(),
referer: this.globalConfig.client,
skipMenuTest: 1,
generateType: params.getParams('generateType') || '',
authCode: code,
})
.then(response => {
// self.globalConfig.layout = 'blank';
if (response && response.token) {
const tk = response.token;
self.globalConfig.token = tk;
// eslint-disable-next-line no-undef,no-debugger
const param = {
subOID: 'subOID',
site: this.getLocalSiteBytoken(tk),
ignoreSite: true,
};
if (window.location?.host === 'panda-water.cn') {
param.token = tk;
} else {
param.identity = tk;
}
getUserInfo(
param,
// eslint-disable-next-line no-shadow
)
// eslint-disable-next-line no-shadow
.then(response => {
try {
if (response && response.code === 0) {
self.globalConfig.userInfo = window?.globalConfig?.transformUserInfo?.(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.isSignIn = true;
self.updateConfig && self.updateConfig(self.globalConfig);
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) {
message.error('登录失败');
if (self.goLogin()) {
return false;
}
// self.handleLoginError(failCallback);
}
})
.catch(error => {
this.handleLoginError();
Logger.log('获取用户配置失败');
});
} else {
self.handleLoginError();
message.error('登录失败');
this.hasTry = true;
}
})
.catch(error => {
self.handleLoginError();
message.error('登录失败');
this.hasTry = true;
});
}
getUserInfoAndConfig(failCallback, flag, industry, toSite) { getUserInfoAndConfig(failCallback, flag, industry, toSite) {
this.updateConfig(window.globalConfig);
const { token: tk } = this.globalConfig; const { token: tk } = this.globalConfig;
const token = tk || Cookies.get('token'); const token = tk || Cookies.get('token');
const site = Cookies.get('site'); const site = Cookies.get('site');
...@@ -696,6 +1249,9 @@ class Login { ...@@ -696,6 +1249,9 @@ class Login {
site: _industrySite || this.getLocalSiteBytoken(token), site: _industrySite || this.getLocalSiteBytoken(token),
ignoreSite: true, ignoreSite: true,
'request.preventCache': Date.now(), 'request.preventCache': Date.now(),
// 获取用户信息添加 client参数,集成登录数量integrated与client相关
client: self?.global?.client || sessionStorage.getItem('client'),
// self.globalConfig.userInfo.site ? self.globalConfig.userInfo.site: this.getLocalSiteBytoken(token), // self.globalConfig.userInfo.site ? self.globalConfig.userInfo.site: this.getLocalSiteBytoken(token),
// industrySite ? _industrySite : this.getLocalSiteBytoken(token), // industrySite ? _industrySite : this.getLocalSiteBytoken(token),
}; };
...@@ -732,14 +1288,12 @@ class Login { ...@@ -732,14 +1288,12 @@ class Login {
return false; return false;
} }
self.handleLoginError(failCallback); self.handleLoginError(failCallback);
this.events.emit('loginError', '获取账号信息异常');
} }
self.updateConfig && self.updateConfig(self.globalConfig); self.updateConfig && self.updateConfig(self.globalConfig);
} catch (error) { } catch (error) {
if (self.goLogin()) { if (self.goLogin()) {
return false; return false;
} }
self.events.emit('loginError', '获取账号信息异常');
self.handleLoginError(failCallback); self.handleLoginError(failCallback);
} }
}) })
...@@ -747,7 +1301,6 @@ class Login { ...@@ -747,7 +1301,6 @@ class Login {
if (self.goLogin()) { if (self.goLogin()) {
return false; return false;
} }
self.events.emit('loginError', '获取账号信息异常');
self.handleLoginError(failCallback); self.handleLoginError(failCallback);
}); });
} else { } else {
...@@ -762,6 +1315,245 @@ class Login { ...@@ -762,6 +1315,245 @@ class Login {
} }
} }
} }
transformLoginHander(response, isRememberPWD, pwd) {
const self = this;
const token =
response &&
(response.token
? response.token
: response.access_token !== null && response.user_token !== null
? response.user_token
: '');
if (token) {
const exp = 86400000;
self.globalConfig.token = token;
if (response.access_token !== '') {
self.globalConfig.access_token = response.access_token;
self.updateConfig && self.updateConfig(self.globalConfig);
let rules = localStorage.getItem('password_pwdRegex') ? localStorage.getItem('password_pwdRegex') : '';
let reg;
try {
reg = new RegExp(rules);
} catch (error) {
rules = '';
reg = new RegExp(rules);
}
let check = false;
if (rules !== '' && pwd) check = !reg.test(pwd);
localStorage.setItem('access_token', response.access_token ? response.access_token : '');
if (check) {
localStorage.setItem('password_token', response.access_token ? response.access_token : '');
}
Cookies.set('client', self.globalConfig.client, {
expires: exp / (24 * 60 * 60 * 1000),
path: '/',
});
}
if (isRememberPWD) {
Cookies.set('client', self.globalConfig.client, {
expires: exp / (24 * 60 * 60 * 1000),
path: '/',
});
Cookies.set('token', token, {
expires: exp / (24 * 60 * 60 * 1000),
path: '/',
});
}
debugger
sessionStorage.setItem('client', self.globalConfig.client);
self.isSignIn = true;
self.updateConfig && self.updateConfig(self.globalConfig);
self.getUserInfoAndConfig();
} else {
self.hasTry = true;
self.events.emit('loginError', response);
message.error(response.error.message);
self.callback && self.callback(false);
}
}
login(usr, pwd, userPhone, isRememberPWD, mode = SERVICE_APP_LOGIN_MODE.password) {
this.globalConfig = getGlobalConfig();
const self = this;
if (window.globalConfig && window.globalConfig.hasGateWay) {
usr = userPhone ? userPhone : usr;
appService
.authorizationToken({
loginName: usr,
// password: pwd ? (params.getParams('generateType') ? pwd : sha1(pwd).toUpperCase()) : '',
password: pwd
? params.getParams('generateType')
? pwd
: encipher(pwd, this.globalConfig.encrypt).toUpperCase()
: '',
type: mode,
generateType: params.getParams('generateType') || '',
})
.then(res => {
if (res.code === 0) {
const data = res.data;
self.updateConfig &&
self.updateConfig(
Object.assign({}, self.globalConfig, {
access_token: data.access_token,
token: data.user_token,
}),
);
if (res.msg === '密码过期') {
localStorage.setItem('password_needChange', true);
} else {
localStorage.removeItem('password_needChange');
}
return data;
} else {
message.error({
duration: 3,
content: `授权失败:${res.msg}`,
});
self.hasTry = true;
self.handleLoginError();
self.events.emit('loginError', res.msg);
return Promise.reject(res);
}
})
.then(res => {
self.transformLoginHander(res, isRememberPWD, pwd);
});
} else {
appService
.generateToken({
f: 'json',
expiration: this.globalConfig.expiration, // token过期时间(单位:秒)
client: 'referer',
username: usr,
// password: pwd ? (params.getParams('generateType') ? pwd : sha1(pwd).toUpperCase()) : '',
password: pwd
? params.getParams('generateType')
? pwd
: encipher(pwd, this.globalConfig.encrypt).toUpperCase()
: '',
referer: this.globalConfig.client,
skipMenuTest: 1,
userPhone,
'request.preventCache': Date.now(),
ignoreSite: true,
loginName: usr,
generateType: params.getParams('generateType') || '',
})
.then(response => {
if (response?.msg === '密码过期') {
localStorage.setItem('password_needChange', true);
} else {
localStorage.removeItem('password_needChange');
}
self.transformLoginHander(response, isRememberPWD, pwd);
})
.catch(error => {
self.hasTry = true;
self.handleLoginError();
self.events.emit('loginError', error.message);
message.error('登录服务异常');
});
}
}
loginHandler(user, pwd, userPhone, isRememberPWD, ref) {
const self = this;
if (user && pwd) {
if (self.loginFailed && self.captchaObj) {
self.captchaObj.verify();
} else if (self.hasTry) {
self.slideVerify(ref, () => {
self.login(user, pwd, userPhone, isRememberPWD);
});
} else {
self.login(user, pwd, userPhone, isRememberPWD);
}
}
}
loginHandlerJiangXi(user, pwd, userPhone, isRememberPWD, ref) {
const self = this;
if (user && pwd) {
if (self.loginFailed && self.captchaObj) {
self.captchaObj.verify();
} else if (self.hasTry) {
self.slideVerify(ref, () => {
self.loginJiang(user, pwd, userPhone, isRememberPWD);
});
} else {
self.loginJiang(user, pwd, userPhone, isRememberPWD);
}
}
}
loginJiang(usr, pwd, userPhone, isRememberPWD, mode = SERVICE_APP_LOGIN_MODE.password) {
this.globalConfig = getGlobalConfig();
const self = this;
appService
.getJiangXiManage({
username: usr,
password: btoa(pwd),
IsGateWay: window.globalConfig.hasGateWay,
'request.preventCache': Date.now(),
})
.then(response => {
if (response.code === 0) {
if (window.globalConfig?.hasGateWay) {
const data = response.data;
self.updateConfig &&
self.updateConfig(
Object.assign({}, self.globalConfig, {
access_token: data.access_token,
token: data.user_token,
}),
);
self.transformLoginHander(response.data, isRememberPWD, pwd);
} else {
self.transformLoginHander({ token: response.data.user_token }, isRememberPWD, pwd);
}
} else {
self.hasTry = true;
self.handleLoginError();
self.events.emit('loginError', response.msg);
message.error(response.msg);
}
})
.catch(error => {
self.hasTry = true;
self.handleLoginError();
self.events.emit('loginError', error.message);
message.error('登录服务异常');
});
}
phoneLoginFormHandler(userPhone, captcha) {
this.login('', '', userPhone, '', SERVICE_APP_LOGIN_MODE.phone);
}
slideVerify(ref, onSuccess, onFail, onRefresh) {
this.events.emit('loginVisible', true);
if (this.renderVerify) {
this.renderVerify.destroy();
}
this.renderVerify = new SlideVerify();
this.renderVerify.render({
container: ref.current,
onSuccess: () => {
onSuccess && onSuccess();
},
});
}
getLocalSites() {
const localSite = localStorage.getItem('loginSite');
let value = {};
if (localSite) {
value = JSON.parse(localSite);
}
return value;
}
} }
export default Login; export default Login;
...@@ -33,28 +33,28 @@ ...@@ -33,28 +33,28 @@
"english": "Monitoring Center", "english": "Monitoring Center",
"label": "", "label": "",
"url": "", "url": "",
"client": "" "client": "scada"
}, },
{ {
"name": "控漏管控", "name": "控漏管控",
"english": "Leakage control", "english": "Leakage control",
"label": "", "label": "",
"url": "", "url": "",
"client": "" "client": "DMA"
}, },
{ {
"name": "业务中心", "name": "业务中心",
"english": "Business center", "english": "Business center",
"label": "", "label": "",
"url": "", "url": "",
"client": "" "client": "business"
}, },
{ {
"name": "工单中心", "name": "工单中心",
"english": "Ticket center", "english": "Ticket center",
"label": "", "label": "",
"url": "", "url": "",
"client": "" "client": "work"
} }
], ],
"标题": "弥勒自来水公司信息化平台", "标题": "弥勒自来水公司信息化平台",
......
...@@ -36,15 +36,13 @@ const boxHeight = 930; ...@@ -36,15 +36,13 @@ const boxHeight = 930;
const IntegrationMile = props => { const IntegrationMile = props => {
const [ref, isFullscreen, handleFullScreen, handleExitFullScreen] = useFullScreen(false); const [ref, isFullscreen, handleFullScreen, handleExitFullScreen] = useFullScreen(false);
const history = useHistory(); const history = useHistory();
const globalClient = window?.globalConfig?.client || 'city'; let integrationClient = window?.globalConfig?.client || 'city'; // 集成登录client
const timer2 = useRef(null); const timer2 = useRef(null);
const timer3 = useRef(null); const timer3 = useRef(null);
const timer4 = useRef(null); const timer4 = useRef(null);
const progressRef2 = useRef(0); const progressRef2 = useRef(0);
const [loginAction, setAction] = useState(() => new LoginAction(props)); const [loginAction, setAction] = useState(() => new LoginAction(props));
const [dataList, setDataList] = useState([]); // 集成登录详情
const [currentType, setCurrentType] = useState('');
const [mClient, setMClient] = useState(''); const [mClient, setMClient] = useState('');
const { clear } = useAliveController(); const { clear } = useAliveController();
...@@ -60,6 +58,8 @@ const IntegrationMile = props => { ...@@ -60,6 +58,8 @@ const IntegrationMile = props => {
scale: 1, scale: 1,
boxHeight: 930, boxHeight: 930,
}); });
const [integrationData, setIntegrationData] = useState({});
const [linkUrl, setLinkUrl] = useState(''); const [linkUrl, setLinkUrl] = useState('');
const [jumpLoading, setJumpLoading] = useState(false); const [jumpLoading, setJumpLoading] = useState(false);
const [progressValue2, setProgressValue2] = useState(0); const [progressValue2, setProgressValue2] = useState(0);
...@@ -103,6 +103,35 @@ const IntegrationMile = props => { ...@@ -103,6 +103,35 @@ const IntegrationMile = props => {
setConfigData(data); setConfigData(data);
} }
}); });
appService
.GetIntegratedloginSetting({
ignoreSite: true,
})
.then(res => {
const { code, data } = res;
if (data.client) {
integrationClient = data.client;
localStorage.setItem('integrationClient', data.client);
if (integrationClient) {
if (!data.client) return;
appService
.GetIntegrationConfig({
type: '集成登录',
userId: window.globalConfig.userInfo?.OID ?? null,
isEnable: true,
client: data.client || '',
})
.then(res1 => {
const list = res1.data || [];
const obj = {};
list.forEach(d => {
obj[d.name] = true;
});
setIntegrationData(obj);
});
}
}
});
}; };
const onResize = () => { const onResize = () => {
if (ref?.current) { if (ref?.current) {
...@@ -193,6 +222,10 @@ const IntegrationMile = props => { ...@@ -193,6 +222,10 @@ const IntegrationMile = props => {
}, time * 1000); }, time * 1000);
}; };
const onLink = (item, loginA) => { const onLink = (item, loginA) => {
if (!integrationData[item.name]) {
message.warning('当前账号没有权限,请联系管理人员配置');
return;
}
const { url, client } = item; const { url, client } = item;
if (!url && !client) return message.warning('未配置功能路径'); if (!url && !client) return message.warning('未配置功能路径');
if (url) { if (url) {
...@@ -222,7 +255,6 @@ const IntegrationMile = props => { ...@@ -222,7 +255,6 @@ const IntegrationMile = props => {
sessionStorage.setItem(currentProductNew, 0); sessionStorage.setItem(currentProductNew, 0);
setMClient(client); setMClient(client);
const config = props.global; const config = props.global;
window.qiankunStarted = false; window.qiankunStarted = false;
if (client) { if (client) {
config.client = client; config.client = client;
...@@ -231,7 +263,7 @@ const IntegrationMile = props => { ...@@ -231,7 +263,7 @@ const IntegrationMile = props => {
const token = props.global?.token || Cookies.get('token'); const token = props.global?.token || Cookies.get('token');
if (!token) { if (!token) {
history.push(`/user/login?client=${globalClient}`, { reload: true }); history.push(`/user/login?client=${integrationClient}`, { reload: true });
clear(); clear();
props.logout(); props.logout();
} else { } else {
...@@ -280,6 +312,7 @@ const IntegrationMile = props => { ...@@ -280,6 +312,7 @@ const IntegrationMile = props => {
} }
} }
}; };
useEffect(() => { useEffect(() => {
getData(); getData();
window.addEventListener('resize', debounce(onResize, 300)); window.addEventListener('resize', debounce(onResize, 300));
...@@ -299,7 +332,7 @@ const IntegrationMile = props => { ...@@ -299,7 +332,7 @@ const IntegrationMile = props => {
timer4.current = null; timer4.current = null;
} }
timer4.current = setTimeout(() => { timer4.current = setTimeout(() => {
if ($('.CarouselRipples')) { if ($('.CarouselRipples')?.ripples) {
$('.CarouselRipples').ripples({ $('.CarouselRipples').ripples({
resolution: 800, resolution: 800,
dropRadius: 20, // px dropRadius: 20, // px
...@@ -400,17 +433,17 @@ const IntegrationMile = props => { ...@@ -400,17 +433,17 @@ const IntegrationMile = props => {
: null} : null}
</div> </div>
</div> </div>
{linkUrl && showBackBtn ? ( {showBackBtn ? (
<div <div
className={classNames(styles.iframeExit, 'animate__animated', 'animate__fadeIn')} className={classNames(styles.iframeExit, 'animate__animated', 'animate__fadeIn')}
onClick={() => setLinkUrl('')} onClick={() => props.logout()}
> >
<div className={styles.iframeBackLeft}> <div className={styles.iframeBackLeft}>
<img src={arrowLeftImg} alt="返回" /> <img src={arrowLeftImg} alt="返回" />
</div> </div>
<div className={styles.iframeExitIcon}> <div className={styles.iframeExitIcon}>
<img src={backImg} alt="返回" /> <img src={backImg} alt="返回" />
返回 退出
</div> </div>
</div> </div>
) : null} ) : null}
...@@ -432,6 +465,9 @@ const mapDispatchToProps = dispatch => ({ ...@@ -432,6 +465,9 @@ const mapDispatchToProps = dispatch => ({
updateCurrentIndex(index) { updateCurrentIndex(index) {
dispatch(actionCreators.updateCurrentIndex(index)); dispatch(actionCreators.updateCurrentIndex(index));
}, },
logout() {
dispatch(actionCreators.logout());
},
}); });
export default connect( export default connect(
mapStateToProps, mapStateToProps,
......
...@@ -8,12 +8,12 @@ ...@@ -8,12 +8,12 @@
.iframeExitIcon { .iframeExitIcon {
position: absolute; position: absolute;
top: 0; top: 0;
left: -45px; right: -45px;
display: flex; display: flex;
height: 44px; height: 44px;
width: 44px; width: 44px;
background: rgba(28, 94, 180, 0.95); background: rgba(28, 94, 180, 0.95);
border-radius: 0 7px 7px 0; border-radius: 7px 0px 0px 7px;
flex-direction: column; flex-direction: column;
justify-content: space-around; justify-content: space-around;
align-items: center; align-items: center;
...@@ -30,11 +30,11 @@ ...@@ -30,11 +30,11 @@
.iframeExit:hover { .iframeExit:hover {
.iframeExitIcon { .iframeExitIcon {
left: 0; right: 0;
} }
.iframeBackLeft { .iframeBackLeft {
left: -15px; right: -15px;
} }
} }
...@@ -42,11 +42,11 @@ ...@@ -42,11 +42,11 @@
.iframeBackLeft { .iframeBackLeft {
position: absolute; position: absolute;
top: 0; top: 0;
left: 0; right: 0;
width: 14px; width: 14px;
height: 44px; height: 44px;
background: rgba(28, 94, 180, 0.95); background: rgba(28, 94, 180, 0.95);
border-radius: 0 7px 7px 0; border-radius: 7px 0 0 7px;
display: flex; display: flex;
align-items: center; align-items: center;
justify-content: center; justify-content: center;
...@@ -62,8 +62,8 @@ ...@@ -62,8 +62,8 @@
width: 44px; width: 44px;
height: 44px; height: 44px;
position: absolute; position: absolute;
top: 4px; top: 50px;
left: 0; right: 0;
color: #FFF; color: #FFF;
cursor: pointer; cursor: pointer;
user-select: none; user-select: none;
......
...@@ -141,7 +141,7 @@ const IntegratedLogin = props => { ...@@ -141,7 +141,7 @@ const IntegratedLogin = props => {
<EditTwoTone onClick={() => edit(record)} style={{ fontSize: '16px' }} /> <EditTwoTone onClick={() => edit(record)} style={{ fontSize: '16px' }} />
</Tooltip> </Tooltip>
{!record.isEnable ? ( {!record.isEnable ? (
<Tooltip title="用"> <Tooltip title="点击启用">
<Popconfirm <Popconfirm
placement="left" placement="left"
title={ title={
...@@ -158,7 +158,7 @@ const IntegratedLogin = props => { ...@@ -158,7 +158,7 @@ const IntegratedLogin = props => {
</Popconfirm> </Popconfirm>
</Tooltip> </Tooltip>
) : ( ) : (
<Tooltip title="用"> <Tooltip title="点击停用">
<Popconfirm <Popconfirm
placement="left" placement="left"
title={ title={
......
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