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) {
export function logout(data) {
// eslint-disable-next-line no-undef
createStoreage.remove('PANDA_STORE');
const integrationClient = localStorage.getItem('integrationClient');
if (window.globalConfig) {
Cookies.set(window.globalConfig.client, '', {
Cookies.set(integrationClient || window.globalConfig.client, '', {
path: '/',
});
window.globalConfig.token = null;
......@@ -198,6 +199,9 @@ export function logout(data) {
window.globalConfig.baseURI = window.location.origin;
window.globalConfig.hasGateWay = false;
window.globalConfig.userInfo = null;
if (integrationClient) {
window.globalConfig.client = integrationClient;
}
window.qiankunIsCache = null;
window.qiankunStarted = false;
// window.globalConfig.hasGateWay = ;
......@@ -220,6 +224,11 @@ export function logout(data) {
Cookies.set('singleToken', '', {
path: '/',
});
// 如果有集成登录client,则 client 切换成集成登录
if (integrationClient) {
sessionStorage.setItem('client', integrationClient);
}
localStorage.removeItem('integrationClient');
localStorage.removeItem('access_token');
localStorage.removeItem('password_token');
localStorage.removeItem('password_pwdRegex');
......
......@@ -326,6 +326,8 @@ const Layout = props => {
!_.isNull(generateType) && !_.isUndefined(generateType) && generateType !== 'undefined'
? `&generateType=${generateType}`
: '';
const integrationClient = localStorage.getItem('integrationClient');
if(integrationClient) client = integrationClient
if (!isLogin) {
history.push(`/user/login?client=${client}${generateType}`, { reload: true });
clear();
......@@ -385,11 +387,14 @@ const Layout = props => {
const GetIntegrationConfig = () => {
if (first) {
const integrationClient = localStorage.getItem('integrationClient');
appService
.GetIntegrationConfig({
type: '集成登录',
userId: window.globalConfig.userInfo?.OID ?? null,
isEnable: true,
client: integrationClient || '' // 只有指定client才能获取集成登录信息
})
.then(res => {
setFirst(false);
......
......@@ -4,6 +4,7 @@ import { log, params, encipher } from '@wisdom-utils/utils/lib/helpers';
import { message } from 'antd';
import { decode, encode } from 'js-base64';
import Cookies from 'js-cookie';
import { SlideVerify } from '@wisdom-utils/components';
import { appService, noticeService } from '@/api';
import { getUserInfo, getWebSiteConfig } from '@/api/service/base';
import { SERVICE_APP_LOGIN_MODE, SERVICE_INTERFACE_SUCCESS_CODE, WX_REDIRECT_URI } from '@/constants';
......@@ -14,6 +15,7 @@ import {
DEFAULT_TCP_PORT,
DEFAULT_PARSE_LEVEL,
} from '@wisdom-utils/components/lib/AppLayout/notifier/constants';
import { guidePage } from '@/pages/bootpage/template/constants';
// eslint-disable-next-line no-undef
const Logger = logger('login');
......@@ -29,12 +31,308 @@ class Login {
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.history = props.history;
this.callback = callback;
this.integratedNum = 0;
this.hasTry = false;
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() {
......@@ -82,23 +380,23 @@ class Login {
}
});
}
// eslint-disable-next-line prettier/prettier
if (
!flag &&
this.isSignIn &&
this.globalConfig.userInfo.Industries.length &&
this.globalConfig.userInfo.Industries.length > 1
) {
this.createContext(this);
this.updateConfig && this.updateConfig(this.globalConfig);
this.history.push('/industry');
return false;
}
// 跳转到集成登录引导页_xule_2023-08-28
if (!flag && this.isSignIn && this.globalConfig.isIntegration >= 1 && this.integratedNum >= 2) {
this.history.push('/industry');
return false;
if (!flag && this.isSignIn && !window.qiankunStarted) {
const item = guidePage.find(g => g.value === this.globalConfig.displayMode);
// 到引导页
if (this.globalConfig.displayMode !== 'default' && item) {
this.createContext(this);
this.updateConfig && this.updateConfig(this.globalConfig);
this.events && this.events.emit('loginIndustry');
return false;
}
// this.globalConfig.isIntegration 为系统配置表里 是否集成登录
// integratedNum 为当前站点配置的集成登录数量,
if (this.globalConfig.isIntegration >= 1 && this.integratedNum >= 2) {
this.events && this.events.emit('loginIndustry');
return false;
}
}
this.initGateWay(token, getIndustry);
}
......@@ -120,12 +418,11 @@ class Login {
}, time);
}
initGateWay(token, getIndustry, failCallback) {
initGateWay(token, getIndustry) {
const self = this;
const gateWayParam = {
_site: this?.globalConfig?.userInfo?.site ?? '',
};
appService
.getWateWayConfig(gateWayParam)
.then(res => {
......@@ -167,7 +464,7 @@ class Login {
})
.then(() => {
// eslint-disable-next-line no-use-before-define
this.getWebConfig(token, getIndustry, failCallback);
this.getWebConfig(token, getIndustry);
})
.catch(err => {
self.updateConfig(self.globalConfig);
......@@ -180,11 +477,12 @@ class Login {
}
})
.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;
// eslint-disable-next-line no-undef
// 获取网站配置的同时,预先获取到mqtt配置,注册进子应用
......@@ -346,7 +644,9 @@ class Login {
self.globalConfig.uiwidgets = [self.globalConfig.shareWidget];
self.globalConfig.widgets = [];
}
// this.events.removeAllListeners('loginSuccess')
// this.events.removeAllListeners('toggleIndustry')
// window.share.event = this.events;
if (
self.globalConfig.userInfo &&
self.globalConfig.userInfo.site &&
......@@ -407,10 +707,13 @@ class Login {
headerPrimaryColor: mainConf.headerPrimaryColor,
};
}
// if (mainConf.productType)
// self.globalConfig.productType = mainConf.productType;
}
this.isOpenYanshi(self, getIndustry);
});
} else {
// loginSuccess
this.isOpenYanshi(self, getIndustry);
}
});
......@@ -419,13 +722,13 @@ class Login {
return false;
}
this.handleLoginError();
this.events.emit('loginError', '获取网络配置失败');
// Logger.log('获取网络配置失败');
}
})
.catch(error => {
// Logger.log(error);
this.handleLoginError();
this.events.emit('loginError', '获取网络配置失败');
// Logger.log('获取网络配置失败');
});
}
......@@ -444,7 +747,6 @@ class Login {
self.getYanshiAuthority(self, getIndustry);
})
.catch(error => {
this.events.emit('loginError', '服务请求异常');
this.handleLoginError();
});
} else {
......@@ -457,23 +759,23 @@ class Login {
}
finish(self, getIndustry) {
self.events.emit('onendLoading');
setTimeout(() => {
window.finishRender = true;
getIndustry ? self.events.emit('toggleIndustry') : self.events.emit('loginSuccess');
window.share.event = self.events;
self.callback && self.callback();
}, 100);
window.finishRender = true;
getIndustry ? self.events.emit('toggleIndustry') : self.events.emit('loginSuccess');
window.share.event = self.events;
self.callback && self.callback();
}
getYanshiAuthority(self, getIndustry) {
// self.updateConfig && self.updateConfig(self.globalConfig);
if (self.globalConfig.widgets.length === 0) {
message.error({
duration: 3,
content: '当前账号未配置菜单',
});
self.events.emit('loginError', '当前账号未配置菜单');
self.handleLoginError();
return;
}
if (self.globalConfig.isOpenTransitionPage) {
appService
.getTransitionPage()
......@@ -503,6 +805,7 @@ class Login {
if (transitionPage.content.length > 0) {
self.globalConfig.transitionPage = transitionPage;
self.updateConfig && self.updateConfig(self.globalConfig);
window.finishRender = true;
self.events.emit('loginHomePage');
window.share.event = self.events;
return self.callback && self.callback();
......@@ -591,6 +894,10 @@ class Login {
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);
}
......@@ -639,8 +946,254 @@ class Login {
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) {
this.updateConfig(window.globalConfig);
const { token: tk } = this.globalConfig;
const token = tk || Cookies.get('token');
const site = Cookies.get('site');
......@@ -696,6 +1249,9 @@ class Login {
site: _industrySite || this.getLocalSiteBytoken(token),
ignoreSite: true,
'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),
// industrySite ? _industrySite : this.getLocalSiteBytoken(token),
};
......@@ -732,14 +1288,12 @@ class Login {
return false;
}
self.handleLoginError(failCallback);
this.events.emit('loginError', '获取账号信息异常');
}
self.updateConfig && self.updateConfig(self.globalConfig);
} catch (error) {
if (self.goLogin()) {
return false;
}
self.events.emit('loginError', '获取账号信息异常');
self.handleLoginError(failCallback);
}
})
......@@ -747,7 +1301,6 @@ class Login {
if (self.goLogin()) {
return false;
}
self.events.emit('loginError', '获取账号信息异常');
self.handleLoginError(failCallback);
});
} else {
......@@ -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;
......@@ -33,28 +33,28 @@
"english": "Monitoring Center",
"label": "",
"url": "",
"client": ""
"client": "scada"
},
{
"name": "控漏管控",
"english": "Leakage control",
"label": "",
"url": "",
"client": ""
"client": "DMA"
},
{
"name": "业务中心",
"english": "Business center",
"label": "",
"url": "",
"client": ""
"client": "business"
},
{
"name": "工单中心",
"english": "Ticket center",
"label": "",
"url": "",
"client": ""
"client": "work"
}
],
"标题": "弥勒自来水公司信息化平台",
......
......@@ -36,15 +36,13 @@ const boxHeight = 930;
const IntegrationMile = props => {
const [ref, isFullscreen, handleFullScreen, handleExitFullScreen] = useFullScreen(false);
const history = useHistory();
const globalClient = window?.globalConfig?.client || 'city';
let integrationClient = window?.globalConfig?.client || 'city'; // 集成登录client
const timer2 = useRef(null);
const timer3 = useRef(null);
const timer4 = useRef(null);
const progressRef2 = useRef(0);
const [loginAction, setAction] = useState(() => new LoginAction(props));
const [dataList, setDataList] = useState([]); // 集成登录详情
const [currentType, setCurrentType] = useState('');
const [mClient, setMClient] = useState('');
const { clear } = useAliveController();
......@@ -60,6 +58,8 @@ const IntegrationMile = props => {
scale: 1,
boxHeight: 930,
});
const [integrationData, setIntegrationData] = useState({});
const [linkUrl, setLinkUrl] = useState('');
const [jumpLoading, setJumpLoading] = useState(false);
const [progressValue2, setProgressValue2] = useState(0);
......@@ -103,6 +103,35 @@ const IntegrationMile = props => {
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 = () => {
if (ref?.current) {
......@@ -193,6 +222,10 @@ const IntegrationMile = props => {
}, time * 1000);
};
const onLink = (item, loginA) => {
if (!integrationData[item.name]) {
message.warning('当前账号没有权限,请联系管理人员配置');
return;
}
const { url, client } = item;
if (!url && !client) return message.warning('未配置功能路径');
if (url) {
......@@ -222,7 +255,6 @@ const IntegrationMile = props => {
sessionStorage.setItem(currentProductNew, 0);
setMClient(client);
const config = props.global;
window.qiankunStarted = false;
if (client) {
config.client = client;
......@@ -231,7 +263,7 @@ const IntegrationMile = props => {
const token = props.global?.token || Cookies.get('token');
if (!token) {
history.push(`/user/login?client=${globalClient}`, { reload: true });
history.push(`/user/login?client=${integrationClient}`, { reload: true });
clear();
props.logout();
} else {
......@@ -280,6 +312,7 @@ const IntegrationMile = props => {
}
}
};
useEffect(() => {
getData();
window.addEventListener('resize', debounce(onResize, 300));
......@@ -299,7 +332,7 @@ const IntegrationMile = props => {
timer4.current = null;
}
timer4.current = setTimeout(() => {
if ($('.CarouselRipples')) {
if ($('.CarouselRipples')?.ripples) {
$('.CarouselRipples').ripples({
resolution: 800,
dropRadius: 20, // px
......@@ -400,17 +433,17 @@ const IntegrationMile = props => {
: null}
</div>
</div>
{linkUrl && showBackBtn ? (
{showBackBtn ? (
<div
className={classNames(styles.iframeExit, 'animate__animated', 'animate__fadeIn')}
onClick={() => setLinkUrl('')}
onClick={() => props.logout()}
>
<div className={styles.iframeBackLeft}>
<img src={arrowLeftImg} alt="返回" />
</div>
<div className={styles.iframeExitIcon}>
<img src={backImg} alt="返回" />
返回
退出
</div>
</div>
) : null}
......@@ -432,6 +465,9 @@ const mapDispatchToProps = dispatch => ({
updateCurrentIndex(index) {
dispatch(actionCreators.updateCurrentIndex(index));
},
logout() {
dispatch(actionCreators.logout());
},
});
export default connect(
mapStateToProps,
......
......@@ -8,12 +8,12 @@
.iframeExitIcon {
position: absolute;
top: 0;
left: -45px;
right: -45px;
display: flex;
height: 44px;
width: 44px;
background: rgba(28, 94, 180, 0.95);
border-radius: 0 7px 7px 0;
border-radius: 7px 0px 0px 7px;
flex-direction: column;
justify-content: space-around;
align-items: center;
......@@ -30,11 +30,11 @@
.iframeExit:hover {
.iframeExitIcon {
left: 0;
right: 0;
}
.iframeBackLeft {
left: -15px;
right: -15px;
}
}
......@@ -42,11 +42,11 @@
.iframeBackLeft {
position: absolute;
top: 0;
left: 0;
right: 0;
width: 14px;
height: 44px;
background: rgba(28, 94, 180, 0.95);
border-radius: 0 7px 7px 0;
border-radius: 7px 0 0 7px;
display: flex;
align-items: center;
justify-content: center;
......@@ -62,8 +62,8 @@
width: 44px;
height: 44px;
position: absolute;
top: 4px;
left: 0;
top: 50px;
right: 0;
color: #FFF;
cursor: pointer;
user-select: none;
......
......@@ -141,7 +141,7 @@ const IntegratedLogin = props => {
<EditTwoTone onClick={() => edit(record)} style={{ fontSize: '16px' }} />
</Tooltip>
{!record.isEnable ? (
<Tooltip title="用">
<Tooltip title="点击启用">
<Popconfirm
placement="left"
title={
......@@ -158,7 +158,7 @@ const IntegratedLogin = props => {
</Popconfirm>
</Tooltip>
) : (
<Tooltip title="用">
<Tooltip title="点击停用">
<Popconfirm
placement="left"
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