Commit 8252d329 authored by 杨思琦's avatar 杨思琦

fix: 弱口令检测

parent 7b6f465f
Pipeline #60930 waiting for manual action with stages
...@@ -16,61 +16,65 @@ const formItemLayout = { ...@@ -16,61 +16,65 @@ const formItemLayout = {
* 云平台上判断是否是默认密码 * 云平台上判断是否是默认密码
* 如果是默认密码,强制要求修改密码 * 如果是默认密码,强制要求修改密码
*/ */
let info = '666';
let infoPre = 'panda';
const ValidContainer = props => { const ValidContainer = props => {
const [needChangePassword, setNeedChangePassword] = useState(false); const [needChangePassword, setNeedChangePassword] = useState(false);
const [form] = Form.useForm(); const [form] = Form.useForm();
// eslint-disable-next-line react/no-this-in-sfc
const password = localStorage.getItem('password_token');
let rules = localStorage.getItem('password_pwdRegex');
const rulesTip = localStorage.getItem('password_pwdRegexTip');
let reg;
try {
reg = new RegExp(rules);
} catch (error) {
rules = '';
reg = new RegExp(rules);
}
useEffect(() => { useEffect(() => {
if (window.location.origin.replace(/^(http|https):\/\//, '') !== 'panda-water.cn') return; // if (window.location.origin.replace(/^(http|https):\/\//, '') !== 'panda-water.cn') return;
const { global } = props; const { global } = props;
const tk = global.token; const tk = global.token;
// eslint-disable-next-line no-eval
if (tk) { if (tk) {
appService.validDefaultPWD({ if (rules !== '' && !reg.test(password)) {
ignoreSite: true, setNeedChangePassword(true);
token: tk
}).then(res => {
if(res.code === 0) {
const { data } = res;
setNeedChangePassword(data.valid);
info = data.info;
} }
}).catch(err => {
})
} }
}, []); }, []);
const handleOK = (e) => { const handleOK = e => {
e.stopPropagation(); e.stopPropagation();
form form
.validateFields() .validateFields()
.then((res) => { .then(res => {
const params = { const params = {
password: `${infoPre}${info}`, // 拼接默认密码 password, // 拼接默认密码
newpassword: res.newPwd, newpassword: res.newPwd,
token: window.globalConfig.token, token: window.globalConfig.token,
ignoreSite: true, ignoreSite: true,
} };
appService appService
.changePassword(params) .changePassword(params)
.then((res) => { // eslint-disable-next-line no-shadow
.then(res => {
if (res.success) { if (res.success) {
message.success(globalHeader['component.account.password.update.success']); message.success(globalHeader['component.account.password.update.success']);
setTimeout(() => { setTimeout(() => {
// setNeedChangePassword(false); setNeedChangePassword(false);
props.logout(); // props.logout();
}, 300); }, 300);
} else { } else {
message.error(globalHeader['component.account.oldpassword.errorMessage']); message.error(globalHeader['component.account.oldpassword.errorMessage']);
} }
}) })
.catch((error) => { .catch(error => {
message.error(globalHeader['component.account.password.update.fail']); message.error(globalHeader['component.account.password.update.fail']);
}); });
}).catch((error) => { })
console.log(error) .catch(error => {
console.log(error);
}); });
} };
return ( return (
<> <>
{props.children} {props.children}
...@@ -87,7 +91,7 @@ const ValidContainer = props => { ...@@ -87,7 +91,7 @@ const ValidContainer = props => {
// zIndex={2000} // zIndex={2000}
> >
<div className={styles['info-label']}> <div className={styles['info-label']}>
<ExclamationCircleFilled style={{color: '#FCAC0F', fontSize: '16px'}}/> <ExclamationCircleFilled style={{ color: '#FCAC0F', fontSize: '16px' }} />
<span>用户首次登录之前必须修改密码</span> <span>用户首次登录之前必须修改密码</span>
</div> </div>
<Form labelAlign="left" {...formItemLayout} form={form}> <Form labelAlign="left" {...formItemLayout} form={form}>
...@@ -100,16 +104,9 @@ const ValidContainer = props => { ...@@ -100,16 +104,9 @@ const ValidContainer = props => {
message: '请输入新密码', message: '请输入新密码',
}, },
{ {
pattern: /^(?![0-9]+$)(?![a-zA-Z]+$)[a-zA-Z0-9_]{8,16}$/, pattern: reg,
message: '密码需为8-16个数字、字符和下划线', message: rulesTip,
}, },
({ getFieldValue }) => ({
validator(rule, value) {
if(value === `${infoPre}${props?.global?.userInfo?.loginName ?? info}` || value === 'panda666')
return Promise.reject('密码规则不允许');
return Promise.resolve();
},
})
]} ]}
hasFeedback hasFeedback
> >
...@@ -127,13 +124,13 @@ const ValidContainer = props => { ...@@ -127,13 +124,13 @@ const ValidContainer = props => {
}, },
({ getFieldValue }) => ({ ({ getFieldValue }) => ({
validator(rule, value) { validator(rule, value) {
if (!/^(?![0-9]+$)(?![a-zA-Z]+$)[a-zA-Z0-9_]{8,16}$/.test(value)) if (!reg.test(value))
return Promise.reject('密码需为8-16个数字、字符和下划线'); // eslint-disable-next-line prefer-promise-reject-errors
if (value === `${infoPre}${props?.global?.userInfo?.loginName ?? info}` || value === 'panda666') return Promise.reject(rulesTip);
return Promise.reject('密码规则不允许');
if (!value || getFieldValue('newPwd') === value) { if (!value || getFieldValue('newPwd') === value) {
return Promise.resolve(); return Promise.resolve();
} }
// eslint-disable-next-line prefer-promise-reject-errors
return Promise.reject('确认密码与新密码输入不一致'); return Promise.reject('确认密码与新密码输入不一致');
}, },
}), }),
......
...@@ -41,7 +41,16 @@ class AvatarDropdown extends React.Component { ...@@ -41,7 +41,16 @@ class AvatarDropdown extends React.Component {
popVisible: false, popVisible: false,
path: null, path: null,
action: API.UPLOAD_FILE_URL, action: API.UPLOAD_FILE_URL,
rulesTip: localStorage.getItem('password_pwdRegexTip'),
reg: ''
}; };
let rules = localStorage.getItem('password_pwdRegex');
try {
this.state.reg = new RegExp(rules);
} catch (error) {
rules = '';
this.state.reg = new RegExp(rules);
}
} }
loginout = (event) => { loginout = (event) => {
// eslint-disable-next-line no-undef // eslint-disable-next-line no-undef
...@@ -424,8 +433,8 @@ class AvatarDropdown extends React.Component { ...@@ -424,8 +433,8 @@ class AvatarDropdown extends React.Component {
message: '请输入新密码', message: '请输入新密码',
}, },
{ {
pattern: /^(?![0-9]+$)(?![a-zA-Z]+$)[a-zA-Z0-9!@#$%^&*_]{8,16}$/, pattern: this.state.reg,
message: '密码字符长度为8-16个字符', message: this.state.rulesTip,
}, },
]} ]}
hasFeedback hasFeedback
......
...@@ -8,11 +8,7 @@ import sha1 from 'sha1'; ...@@ -8,11 +8,7 @@ import sha1 from 'sha1';
import { SlideVerify } from '@wisdom-utils/components'; 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 { import { SERVICE_APP_LOGIN_MODE, SERVICE_INTERFACE_SUCCESS_CODE, WX_REDIRECT_URI } from '@/constants';
SERVICE_APP_LOGIN_MODE,
SERVICE_INTERFACE_SUCCESS_CODE,
WX_REDIRECT_URI,
} from '@/constants';
import store from '@/stores'; import store from '@/stores';
import { import {
DEFAULT_MQTT_PATH, DEFAULT_MQTT_PATH,
...@@ -23,8 +19,7 @@ import { ...@@ -23,8 +19,7 @@ import {
// eslint-disable-next-line no-undef // eslint-disable-next-line no-undef
const Logger = logger('login'); const Logger = logger('login');
const getGlobalConfig = () => const getGlobalConfig = () => store.getState().toJS().global?.globalConfig ?? {};
store.getState().toJS().global?.globalConfig ?? {};
class Login { class Login {
constructor(props, callback, isInit) { constructor(props, callback, isInit) {
this.events = window.share.event; this.events = window.share.event;
...@@ -54,9 +49,7 @@ class Login { ...@@ -54,9 +49,7 @@ class Login {
let { ddCode } = this.globalConfig; let { ddCode } = this.globalConfig;
let { loginName } = this.globalConfig; let { loginName } = this.globalConfig;
let { password } = this.globalConfig; let { password } = this.globalConfig;
loginName = params.getParams('loginName') loginName = params.getParams('loginName') ? params.getParams('loginName') : loginName;
? params.getParams('loginName')
: loginName;
const homepage = params.getParams('homepage'); const homepage = params.getParams('homepage');
const generateType = params.getParams('generateType'); const generateType = params.getParams('generateType');
if (homepage) { if (homepage) {
...@@ -68,9 +61,7 @@ class Login { ...@@ -68,9 +61,7 @@ class Login {
} }
self.updateConfig && self.updateConfig(self.globalConfig); self.updateConfig && self.updateConfig(self.globalConfig);
password = params.getParams('password') password = params.getParams('password') ? params.getParams('password') : 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;
// self.qrcodeLogin(self.globalConfig.qrcodeData.code); // self.qrcodeLogin(self.globalConfig.qrcodeData.code);
...@@ -86,15 +77,11 @@ class Login { ...@@ -86,15 +77,11 @@ class Login {
self.otherLoginIn(loginName, password); self.otherLoginIn(loginName, password);
} else if ( } else if (
self.globalConfig.qrcodeData && self.globalConfig.qrcodeData &&
(self.globalConfig.qrcodeData.state && (self.globalConfig.qrcodeData.state && self.globalConfig.qrcodeData.state === this.redirect_state) &&
self.globalConfig.qrcodeData.state === this.redirect_state) &&
self.globalConfig.qrcodeData.code !== '' self.globalConfig.qrcodeData.code !== ''
) { ) {
self.qrcodeLogin(self.globalConfig.qrcodeData.code); self.qrcodeLogin(self.globalConfig.qrcodeData.code);
} else if ( } else if (!!self.globalConfig.isSingleLogin && !!self.globalConfig.singleLoginCode) {
!!self.globalConfig.isSingleLogin &&
!!self.globalConfig.singleLoginCode
) {
// //
} else if (self.goLogin()) { } else if (self.goLogin()) {
return false; return false;
...@@ -105,7 +92,6 @@ class Login { ...@@ -105,7 +92,6 @@ class Login {
this.globalConfig.token = token; this.globalConfig.token = token;
const self = this; const self = this;
// eslint-disable-next-line no-undef // eslint-disable-next-line no-undef
getUserInfo({ getUserInfo({
token: this.globalConfig.token, token: this.globalConfig.token,
subOID: 'subOID', subOID: 'subOID',
...@@ -116,7 +102,6 @@ class Login { ...@@ -116,7 +102,6 @@ class Login {
if (response && response.code === 0) { if (response && response.code === 0) {
self.globalConfig.userInfo = window?.globalConfig?.transformUserInfo?.(response.data) ?? {}; self.globalConfig.userInfo = window?.globalConfig?.transformUserInfo?.(response.data) ?? {};
self.updateConfig && self.updateConfig(self.globalConfig); self.updateConfig && self.updateConfig(self.globalConfig);
self.getUserInfoAndConfig(); self.getUserInfoAndConfig();
} else { } else {
self.logout && self.logout(); self.logout && self.logout();
...@@ -125,10 +110,7 @@ class Login { ...@@ -125,10 +110,7 @@ class Login {
window.location.href = `${window.location.origin}`; window.location.href = `${window.location.origin}`;
return false; return false;
} }
if ( if (self.globalConfig.style === 'ios' && self.globalConfig.loginTemplate === 'IOSCloud.html') {
self.globalConfig.style === 'ios' &&
self.globalConfig.loginTemplate === 'IOSCloud.html'
) {
window.location.href = `${window.location.origin}`; window.location.href = `${window.location.origin}`;
return false; return false;
} }
...@@ -140,8 +122,7 @@ class Login { ...@@ -140,8 +122,7 @@ class Login {
writeLogs() { writeLogs() {
if (this.globalConfig.userInfo.UserImge === '') { if (this.globalConfig.userInfo.UserImge === '') {
// _config.userInfo.UserImge = __webpack_public_path__ + "assets/images/icon/熊猫新2.png"; // _config.userInfo.UserImge = __webpack_public_path__ + "assets/images/icon/熊猫新2.png";
this.globalConfig.userInfo.UserImge = this.globalConfig.userInfo.UserImge = 'https://panda-water.cn/web4/assets/images/icon/熊猫新2.png';
'https://panda-water.cn/web4/assets/images/icon/熊猫新2.png';
} }
if (this.globalConfig.userInfo.site) { if (this.globalConfig.userInfo.site) {
...@@ -150,10 +131,7 @@ class Login { ...@@ -150,10 +131,7 @@ class Login {
.writeLogs({ .writeLogs({
origin: window.location.origin, origin: window.location.origin,
client: this.globalConfig.client, client: this.globalConfig.client,
site: site: this.globalConfig.userInfo && this.globalConfig.userInfo.site ? this.globalConfig.userInfo.site : '',
this.globalConfig.userInfo && this.globalConfig.userInfo.site
? this.globalConfig.userInfo.site
: '',
loginName: loginName:
this.globalConfig.userInfo && this.globalConfig.userInfo.fullName this.globalConfig.userInfo && this.globalConfig.userInfo.fullName
? this.globalConfig.userInfo.fullName ? this.globalConfig.userInfo.fullName
...@@ -167,10 +145,7 @@ class Login { ...@@ -167,10 +145,7 @@ class Login {
.loginLogs({ .loginLogs({
origin: window.location.origin, origin: window.location.origin,
client: this.globalConfig.client, client: this.globalConfig.client,
site: site: this.globalConfig.userInfo && this.globalConfig.userInfo.site ? this.globalConfig.userInfo.site : '',
this.globalConfig.userInfo && this.globalConfig.userInfo.site
? this.globalConfig.userInfo.site
: '',
loginName: loginName:
this.globalConfig.userInfo && this.globalConfig.userInfo.fullName this.globalConfig.userInfo && this.globalConfig.userInfo.fullName
? this.globalConfig.userInfo.fullName ? this.globalConfig.userInfo.fullName
...@@ -182,15 +157,9 @@ class Login { ...@@ -182,15 +157,9 @@ class Login {
getIndustry(flag, token, getIndustry) { getIndustry(flag, token, getIndustry) {
this.globalConfig.userInfo.Industries = []; this.globalConfig.userInfo.Industries = [];
if ( if (this.globalConfig.userInfo.Groups && this.globalConfig.userInfo.Groups.length) {
this.globalConfig.userInfo.Groups &&
this.globalConfig.userInfo.Groups.length
) {
this.globalConfig.userInfo.Groups.forEach(group => { this.globalConfig.userInfo.Groups.forEach(group => {
if ( if (group.industry && this.globalConfig.userInfo.Industries.indexOf(group.industry) < 0) {
group.industry &&
this.globalConfig.userInfo.Industries.indexOf(group.industry) < 0
) {
this.globalConfig.userInfo.Industries.push(group.industry); this.globalConfig.userInfo.Industries.push(group.industry);
} }
}); });
...@@ -237,19 +206,16 @@ class Login { ...@@ -237,19 +206,16 @@ class Login {
if (res.data[0]) { if (res.data[0]) {
const data = res.data[0]; const data = res.data[0];
mqttConfig.mqtt_IsSSL = data.IsSSL ? data.IsSSL : false; mqttConfig.mqtt_IsSSL = data.IsSSL ? data.IsSSL : false;
mqttConfig.mqtt_mess.site_code = mqttConfig.mqtt_mess.site_code = data.SiteCode || self.globalConfig.userInfo.site;
data.SiteCode || self.globalConfig.userInfo.site;
mqttConfig.mqtt_mess.TcpIP = data.TcpIP; mqttConfig.mqtt_mess.TcpIP = data.TcpIP;
mqttConfig.mqtt_mess.TcpPort = data.TcpPort // eslint-disable-next-line radix
? parseInt(data.TcpPort) mqttConfig.mqtt_mess.TcpPort = data.TcpPort ? parseInt(data.TcpPort) : 8083;
: 8083; mqttConfig.mqtt_mess.MessageLevel = data.MessageLevel ? data.MessageLevel : DEFAULT_PARSE_LEVEL;
mqttConfig.mqtt_mess.MessageLevel = data.MessageLevel
? data.MessageLevel
: DEFAULT_PARSE_LEVEL;
if (data.NginxStart) { if (data.NginxStart) {
mqttConfig.nginxStart = data.NginxStart; mqttConfig.nginxStart = data.NginxStart;
mqttConfig.mqtt_mess.TcpIP = window.location.hostname; mqttConfig.mqtt_mess.TcpIP = window.location.hostname;
// eslint-disable-next-line radix
mqttConfig.mqtt_mess.TcpPort = parseInt(window.location.port); mqttConfig.mqtt_mess.TcpPort = parseInt(window.location.port);
mqttConfig.mqtt_path = '/ws/'; mqttConfig.mqtt_path = '/ws/';
} else { } else {
...@@ -258,13 +224,9 @@ class Login { ...@@ -258,13 +224,9 @@ class Login {
} else { } else {
mqttConfig.mqtt_mess.TcpIP = DEFAULT_TCP_IP; mqttConfig.mqtt_mess.TcpIP = DEFAULT_TCP_IP;
mqttConfig.mqtt_mess.TcpPort = DEFAULT_TCP_PORT; mqttConfig.mqtt_mess.TcpPort = DEFAULT_TCP_PORT;
mqttConfig.mqtt_IsSSL = `${mqttConfig.mqtt_mess.TcpIP}:${ mqttConfig.mqtt_IsSSL = `${mqttConfig.mqtt_mess.TcpIP}:${mqttConfig.mqtt_mess.TcpPort}`;
mqttConfig.mqtt_mess.TcpPort
}`;
} }
mqttConfig.mqtt_iotIP = `${mqttConfig.mqtt_mess.TcpIP}:${ mqttConfig.mqtt_iotIP = `${mqttConfig.mqtt_mess.TcpIP}:${mqttConfig.mqtt_mess.TcpPort}`;
mqttConfig.mqtt_mess.TcpPort
}`;
self.globalConfig = Object.assign(self.globalConfig, { self.globalConfig = Object.assign(self.globalConfig, {
...mqttConfig, ...mqttConfig,
...@@ -287,11 +249,8 @@ class Login { ...@@ -287,11 +249,8 @@ class Login {
const config = result.shift(); const config = result.shift();
const homeType = config.productType || 'civweb4'; const homeType = config.productType || 'civweb4';
// 产品类型和首页路径同时有才行 // 产品类型和首页路径同时有才行
let homepage = params.getParams('homepage') // eslint-disable-next-line prettier/prettier
? params.getParams('homepage') const homepage = params.getParams('homepage') ? params.getParams('homepage') : (homeType && config.homepage ? `${homeType}/${params.getParams('homepage') || config.homepage}` : '');
: homeType && config.homepage
? `${homeType}/${params.getParams('homepage') || config.homepage}`
: '';
self.globalConfig = Object.assign(self.globalConfig, config, { self.globalConfig = Object.assign(self.globalConfig, config, {
theme: self.globalConfig.theme, theme: self.globalConfig.theme,
...@@ -347,20 +306,16 @@ class Login { ...@@ -347,20 +306,16 @@ class Login {
if (resultData && resultData.length > 0) { if (resultData && resultData.length > 0) {
const mainConf = resultData.shift(); const mainConf = resultData.shift();
const mainType = mainConf.productType || 'civweb4'; const mainType = mainConf.productType || 'civweb4';
if (mainConf.homepage) if (mainConf.homepage) self.globalConfig.homepage = `${mainType}/${mainConf.homepage}`;
self.globalConfig.homepage = `${mainType}/${ if (mainConf.bannerLogo) self.globalConfig.bannerLogo = mainConf.bannerLogo;
mainConf.homepage
}`;
if (mainConf.bannerLogo)
self.globalConfig.bannerLogo = mainConf.bannerLogo;
if (mainConf.logo) self.globalConfig.logo = mainConf.logo; if (mainConf.logo) self.globalConfig.logo = mainConf.logo;
if (mainConf.mdi) self.globalConfig.mdi = mainConf.mdi; if (mainConf.mdi) self.globalConfig.mdi = mainConf.mdi;
if (mainConf.menu) self.globalConfig.menu = mainConf.menu; if (mainConf.menu) self.globalConfig.menu = mainConf.menu;
if (mainConf.shortcutIcon) if (mainConf.shortcutIcon) self.globalConfig.shortcutIcon = mainConf.shortcutIcon;
self.globalConfig.shortcutIcon = mainConf.shortcutIcon; // eslint-disable-next-line no-prototype-builtins
if (mainConf && mainConf.hasOwnProperty('topMenu')) if (mainConf && mainConf.hasOwnProperty('topMenu')) self.globalConfig.topMenu = mainConf.topMenu;
self.globalConfig.topMenu = mainConf.topMenu; if (mainConf && mainConf.navTheme && self.globalConfig.CloudStyle !== '否')
if (mainConf && mainConf.navTheme && self.globalConfig.CloudStyle !== '否') self.globalConfig.navTheme = mainConf.navTheme; // 云平台统一navTheme self.globalConfig.navTheme = mainConf.navTheme; // 云平台统一navTheme
// 云平台切换站点 应用站点自己主题配置 // 云平台切换站点 应用站点自己主题配置
if (config.CloudStyle === '否') { if (config.CloudStyle === '否') {
...@@ -368,13 +323,13 @@ class Login { ...@@ -368,13 +323,13 @@ class Login {
primaryColor: config.primaryColor, primaryColor: config.primaryColor,
navTheme: config.navTheme, navTheme: config.navTheme,
headerPrimaryColor: config.headerPrimaryColor, headerPrimaryColor: config.headerPrimaryColor,
} };
} else { } else {
self.globalConfig.variableTheme = { self.globalConfig.variableTheme = {
primaryColor: mainConf.primaryColor, primaryColor: mainConf.primaryColor,
navTheme: mainConf.navTheme, navTheme: mainConf.navTheme,
headerPrimaryColor: mainConf.headerPrimaryColor, headerPrimaryColor: mainConf.headerPrimaryColor,
} };
} }
// if (mainConf.productType) // if (mainConf.productType)
// self.globalConfig.productType = mainConf.productType; // self.globalConfig.productType = mainConf.productType;
...@@ -385,19 +340,14 @@ class Login { ...@@ -385,19 +340,14 @@ class Login {
self.callback && self.callback(); self.callback && self.callback();
// console.log("===loginSuccess===") // console.log("===loginSuccess===")
getIndustry getIndustry ? self.events.emit('toggleIndustry') : self.events.emit('loginSuccess', self.history);
? self.events.emit('toggleIndustry')
: self.events.emit('loginSuccess', self.history);
}); });
} else { } else {
// loginSuccess // loginSuccess
self.updateConfig && self.updateConfig(self.globalConfig); self.updateConfig && self.updateConfig(self.globalConfig);
// console.log("===loginSuccess===") // console.log("===loginSuccess===")
getIndustry getIndustry ? self.events.emit('toggleIndustry') : self.events.emit('loginSuccess', self.history);
? self.events.emit('toggleIndustry')
: self.events.emit('loginSuccess', self.history);
window.share.event = self.events; window.share.event = self.events;
self.callback && self.callback(); self.callback && self.callback();
} }
...@@ -430,13 +380,8 @@ class Login { ...@@ -430,13 +380,8 @@ class Login {
// eslint-disable-next-line radix // eslint-disable-next-line radix
MAX_BOTTOM = parseInt(item.bottom); MAX_BOTTOM = parseInt(item.bottom);
} }
if (!isScale && item.url.toLowerCase().indexOf('widgets/zoom') > -1) if (!isScale && item.url.toLowerCase().indexOf('widgets/zoom') > -1) isScale = true;
isScale = true; if (widgetIndex === -1 && item.url.indexOf('ToggleProject/ToggleProject') > -1) widgetIndex = index;
if (
widgetIndex === -1 &&
item.url.indexOf('ToggleProject/ToggleProject') > -1
)
widgetIndex = index;
}); });
const { layers = [] } = this.globalConfig.mapsettings || {}; const { layers = [] } = this.globalConfig.mapsettings || {};
...@@ -467,8 +412,7 @@ class Login { ...@@ -467,8 +412,7 @@ class Login {
} }
if (layer.backgroundColor) { if (layer.backgroundColor) {
this.globalConfig.mapsettings.areasettings.backgroundColor = this.globalConfig.mapsettings.areasettings.backgroundColor = layer.backgroundColor;
layer.backgroundColor;
} }
if (layer.boundColor) { if (layer.boundColor) {
...@@ -481,11 +425,9 @@ class Login { ...@@ -481,11 +425,9 @@ class Login {
// eslint-disable-next-line radix // eslint-disable-next-line radix
if (Number.isInteger(parseInt(layer.backgroundOpacity))) { if (Number.isInteger(parseInt(layer.backgroundOpacity))) {
this.globalConfig.mapsettings.areasettings.backgroundOpacity = this.globalConfig.mapsettings.areasettings.backgroundOpacity = layer.backgroundOpacity;
layer.backgroundOpacity;
} }
if (layer.extent) if (layer.extent) this.globalConfig.mapsettings.areasettings.extent = layer.extent;
this.globalConfig.mapsettings.areasettings.extent = layer.extent;
if (layer.basemaps && layer.basemaps.length > 0) { if (layer.basemaps && layer.basemaps.length > 0) {
this.globalConfig.mapsettings.basemaps = layer.basemaps; this.globalConfig.mapsettings.basemaps = layer.basemaps;
} }
...@@ -519,10 +461,7 @@ class Login { ...@@ -519,10 +461,7 @@ class Login {
} }
goLogin() { goLogin() {
if ( if (this.globalConfig.style === 'ios' && this.globalConfig.loginTemplate === 'IOSCloud.html') {
this.globalConfig.style === 'ios' &&
this.globalConfig.loginTemplate === 'IOSCloud.html'
) {
window.location.href = `${window.location.origin}/#login`; window.location.href = `${window.location.origin}/#login`;
return true; return true;
} }
...@@ -580,7 +519,7 @@ class Login { ...@@ -580,7 +519,7 @@ class Login {
self.getUserInfoAndConfig(); self.getUserInfoAndConfig();
} else { } else {
self.handleLoginError(); self.handleLoginError();
message.error("登录失败,用户信息错误"); message.error('登录失败,用户信息错误');
self.hasTry = true; // 已经输错过密码 self.hasTry = true; // 已经输错过密码
} }
}); });
...@@ -704,9 +643,7 @@ class Login { ...@@ -704,9 +643,7 @@ class Login {
expiration: this.globalConfig.expiration, // token过期时间(单位:秒) expiration: this.globalConfig.expiration, // token过期时间(单位:秒)
client: 'referer', client: 'referer',
username: usr, username: usr,
password: params.getParams('generateType') password: params.getParams('generateType') ? pwd : sha1(pwd).toUpperCase(),
? pwd
: sha1(pwd).toUpperCase(),
referer: this.globalConfig.client, referer: this.globalConfig.client,
skipMenuTest: 1, skipMenuTest: 1,
generateType: params.getParams('generateType') || '', generateType: params.getParams('generateType') || '',
...@@ -792,14 +729,11 @@ class Login { ...@@ -792,14 +729,11 @@ class Login {
/* eslint-disable */ /* eslint-disable */
let _industrySite = null; let _industrySite = null;
if (industry) { if (industry) {
const userInfo = const userInfo =
self.globalConfig.userInfo && self.globalConfig.userInfo &&
self.globalConfig.userInfo.Groups && self.globalConfig.userInfo.Groups &&
self.globalConfig.userInfo.Groups instanceof Array self.globalConfig.userInfo.Groups instanceof Array
? self.globalConfig.userInfo.Groups.find( ? self.globalConfig.userInfo.Groups.find(enter => enter.industry === industry)
enter => enter.industry === industry,
)
: null; : null;
if (industry === '熊猫新产品' && site) { if (industry === '熊猫新产品' && site) {
...@@ -832,8 +766,7 @@ class Login { ...@@ -832,8 +766,7 @@ class Login {
if (self.isSignIn || !!industry) { if (self.isSignIn || !!industry) {
// eslint-disable-next-line no-undef // eslint-disable-next-line no-undef
getUserInfo( getUserInfo({
{
token, token,
subOID: 'subOID', subOID: 'subOID',
industry, industry,
...@@ -842,8 +775,7 @@ class Login { ...@@ -842,8 +775,7 @@ class Login {
'request.preventCache': Date.now(), 'request.preventCache': Date.now(),
// 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),
}, })
)
.then(response => { .then(response => {
try { try {
if (response && response.code === 0) { if (response && response.code === 0) {
...@@ -901,17 +833,24 @@ class Login { ...@@ -901,17 +833,24 @@ class Login {
transformLoginHander(response, isRememberPWD) { transformLoginHander(response, isRememberPWD) {
const self = this; const self = this;
const token = response && ( response.token ? response.token: ( response.access_token !== null && response.user_token !== null) ? response.user_token: ''); const token =
response &&
(response.token
? response.token
: response.access_token !== null && response.user_token !== null
? response.user_token
: '');
if (token) { if (token) {
const exp = 86400000; const exp = 86400000;
self.globalConfig.token = token; self.globalConfig.token = token;
if(response.access_token!== "") { if (response.access_token !== '') {
self.globalConfig.access_token = response.access_token; self.globalConfig.access_token = response.access_token;
localStorage.setItem('access_token', response.access_token); localStorage.setItem('access_token', response.access_token);
localStorage.setItem('password_token', self.globalConfig.password);
Cookies.set('client', self.globalConfig.client, { Cookies.set('client', self.globalConfig.client, {
expires: exp / (24 * 60 * 60 * 1000), expires: exp / (24 * 60 * 60 * 1000),
path: '/', path: '/',
}) });
} }
if (isRememberPWD) { if (isRememberPWD) {
Cookies.set('client', self.globalConfig.client, { Cookies.set('client', self.globalConfig.client, {
...@@ -939,36 +878,42 @@ class Login { ...@@ -939,36 +878,42 @@ class Login {
login(usr, pwd, userPhone, isRememberPWD, mode = SERVICE_APP_LOGIN_MODE.password) { login(usr, pwd, userPhone, isRememberPWD, mode = SERVICE_APP_LOGIN_MODE.password) {
this.globalConfig = getGlobalConfig(); this.globalConfig = getGlobalConfig();
const self = this; const self = this;
if(window.globalConfig && window.globalConfig.hasGateWay) { self.globalConfig.password = pwd;
usr = userPhone ? userPhone: usr; if (window.globalConfig && window.globalConfig.hasGateWay) {
appService.authorizationToken({ usr = userPhone ? userPhone : usr;
appService
.authorizationToken({
loginName: usr, loginName: usr,
password: pwd ? (params.getParams('generateType') ? pwd : sha1(pwd).toUpperCase()) : '', password: pwd ? (params.getParams('generateType') ? pwd : sha1(pwd).toUpperCase()) : '',
type: mode, type: mode,
generateType: params.getParams('generateType') || '' generateType: params.getParams('generateType') || '',
}).then(res => { })
.then(res => {
if(res.code === 0) { if (res.code === 0) {
const data = res.data; const data = res.data;
self.updateConfig && self.updateConfig(Object.assign({}, self.globalConfig, { self.updateConfig &&
self.updateConfig(
Object.assign({}, self.globalConfig, {
access_token: data.access_token, access_token: data.access_token,
token: data.user_token, token: data.user_token,
})); }),
return data );
return data;
} else { } else {
message.error({ message.error({
duration: 3, duration: 3,
content: `授权失败:${res.msg}` content: `授权失败:${res.msg}`,
}); });
self.events.emit('loginError', res.msg); self.events.emit('loginError', res.msg);
return Promise.reject(res) return Promise.reject(res);
} }
}).then((res) => {
self.transformLoginHander(res, isRememberPWD)
}) })
.then(res => {
self.transformLoginHander(res, isRememberPWD);
});
} else { } else {
appService.generateToken( appService
{ .generateToken({
f: 'json', f: 'json',
expiration: this.globalConfig.expiration, // token过期时间(单位:秒) expiration: this.globalConfig.expiration, // token过期时间(单位:秒)
client: 'referer', client: 'referer',
...@@ -980,22 +925,18 @@ class Login { ...@@ -980,22 +925,18 @@ class Login {
'request.preventCache': Date.now(), 'request.preventCache': Date.now(),
ignoreSite: true, ignoreSite: true,
loginName: usr, loginName: usr,
generateType: params.getParams('generateType') || '' generateType: params.getParams('generateType') || '',
}, })
)
.then(response => { .then(response => {
self.transformLoginHander(response, isRememberPWD) self.transformLoginHander(response, isRememberPWD);
}) })
.catch(error => { .catch(error => {
self.hasTry = true; self.hasTry = true;
self.handleLoginError(); self.handleLoginError();
self.events.emit('loginError', error.message); self.events.emit('loginError', error.message);
message.error('登录服务异常'); message.error('登录服务异常');
}); });
} }
} }
loginHandler(user, pwd, userPhone, isRememberPWD, ref) { loginHandler(user, pwd, userPhone, isRememberPWD, ref) {
......
import React, { useEffect } from 'react'; import React, { useEffect } from 'react';
import ReactDOM from 'react-dom'; import ReactDOM from 'react-dom';
import { import { ConfigProvider, message, Modal, notification } from 'antd';
ConfigProvider,
message,
Modal,
notification,
} from 'antd';
import { ConnectedRouter } from 'connected-react-router/immutable'; import { ConnectedRouter } from 'connected-react-router/immutable';
import Cookies from 'js-cookie'; import Cookies from 'js-cookie';
import canUseDom from 'rc-util/lib/Dom/canUseDom'; import canUseDom from 'rc-util/lib/Dom/canUseDom';
...@@ -15,19 +10,13 @@ import { Provider } from 'react-redux'; ...@@ -15,19 +10,13 @@ import { Provider } from 'react-redux';
import { LocaleContainer } from '@wisdom-utils/components'; import { LocaleContainer } from '@wisdom-utils/components';
import { history } from '@wisdom-utils/runtime'; import { history } from '@wisdom-utils/runtime';
import { import { params, Storeage } from '@wisdom-utils/utils/lib/helpers';
params,
Storeage,
} from '@wisdom-utils/utils/lib/helpers';
import { appService } from './api'; import { appService } from './api';
import Container from './components/Container'; import Container from './components/Container';
import App from './containers/App'; import App from './containers/App';
import { actionCreators } from './containers/App/store'; import { actionCreators } from './containers/App/store';
import { import { defaultApp, initMicroApps } from './micro';
defaultApp,
initMicroApps,
} from './micro';
import Login from './pages/user/login/login'; import Login from './pages/user/login/login';
import store from './stores'; import store from './stores';
import { getToken } from './utils/utils'; import { getToken } from './utils/utils';
...@@ -36,53 +25,48 @@ const { getThemeVariables } = require('antd/dist/theme'); ...@@ -36,53 +25,48 @@ const { getThemeVariables } = require('antd/dist/theme');
const defaultSetting = require('../config/defaultSetting'); const defaultSetting = require('../config/defaultSetting');
const MOUNT_NODE = document.getElementById('root'); const MOUNT_NODE = document.getElementById('root');
const customPrefixCls = 'panda-console-base'; const customPrefixCls = 'panda-console-base';
// eslint-disable-next-line no-restricted-globals
const namespace = `__PANDA_STORE__${location.hostname}`; const namespace = `__PANDA_STORE__${location.hostname}`;
window.createStoreage = new Storeage(namespace); window.createStoreage = new Storeage(namespace);
const dynamicStyleMark = `-panda-${Date.now()}-${Math.random()}`; const dynamicStyleMark = `-panda-${Date.now()}-${Math.random()}`;
function getStyle(prefixCls, theme) { function getStyle(prefixCls, theme) {
const variables = {}; const variables = {};
Object.keys(theme).forEach(item => { Object.keys(theme).forEach(item => {
variables[item] = theme[item] variables[item] = theme[item];
}) });
const cssList = Object.keys(variables).map( const cssList = Object.keys(variables).map(key => `--${prefixCls}-${key}: ${variables[key]};`);
key => `--${prefixCls}-${key}: ${variables[key]};`,
);
return ` return `
:root { :root {
${cssList.join('\n')} ${cssList.join('\n')}
} }
`.trim(); `.trim();
} }
const registerTheme = function(prefixCls, theme) { const registerTheme = function(prefixCls, theme) {
const style = getStyle(prefixCls, theme); const style = getStyle(prefixCls, theme);
if(canUseDom()) { if (canUseDom()) {
updateCSS(style, `${dynamicStyleMark}-dynamic-theme`) updateCSS(style, `${dynamicStyleMark}-dynamic-theme`);
} }
} };
export const AppInitState = () => { export const AppInitState = () => {
const getClient = () => { const getClient = () => {
const value = params.getParams('client') || sessionStorage.getItem('client'); const value = params.getParams('client') || sessionStorage.getItem('client');
const client = value && value !== 'undefined' ? value : 'city'; const client = value && value !== 'undefined' ? value : 'city';
return client; return client;
} };
const client = getClient(); const client = getClient();
let config = window.globalConfig || {}; let config = window.globalConfig || {};
// eslint-disable-next-line no-undef, no-restricted-globals
createStoreage.remove(`__PANDA_STORE__${location.hostname}`); createStoreage.remove(`__PANDA_STORE__${location.hostname}`);
window.globalConfig = {}; window.globalConfig = {};
// eslint-disable-next-line no-underscore-dangle
window.__INITIAL_STATE__ = {}; window.__INITIAL_STATE__ = {};
if (!getToken() || config.token == null) { if (!getToken() || config.token == null) {
...@@ -105,53 +89,82 @@ export const AppInitState = () => { ...@@ -105,53 +89,82 @@ export const AppInitState = () => {
} }
const initGeteWay = () => { const initGeteWay = () => {
appService.getWateWayConfig({ignoreSite: true}).then(res => { appService
const hasGateWay = !res || !res.data ? false : _.isString(res.data) ? JSON.parse(res.data) : typeof res.data === 'boolean' ? res.data : false; .getWateWayConfig({ ignoreSite: true })
.then(res => {
// eslint-disable-next-line prettier/prettier, no-undef
const hasGateWay = !res || !res.data ? false : _.isString(res.data) ? JSON.parse(res.data) : (typeof res.data === 'boolean' ? res.data : false);
return { return {
hasGateWay, hasGateWay,
apiGatewayDomain: `${window.location.origin}${hasGateWay ? '/PandaCore/GateWay' : ''}`, apiGatewayDomain: `${window.location.origin}${hasGateWay ? '/PandaCore/GateWay' : ''}`,
}; };
}).then(gateWayConfig => { })
.then(gateWayConfig => {
// eslint-disable-next-line no-use-before-define
initGlobalConfig(gateWayConfig); initGlobalConfig(gateWayConfig);
}).catch(err => { })
.catch(err => {
// eslint-disable-next-line no-use-before-define
initGlobalConfig(); initGlobalConfig();
}); });
} };
const initGlobalConfig = (gateWayConfig = {}) => { const initGlobalConfig = (gateWayConfig = {}) => {
appService.queryConfig({ appService
.queryConfig({
client: client || 'city', client: client || 'city',
ignoreSite: true, ignoreSite: true,
}).then(res => { })
.then(res => {
if (res) { if (res) {
const { data } = res; const { data } = res;
if (!data.client) { if (!data.client) {
data.client = client; data.client = client;
} }
store.dispatch(actionCreators.getConfig(Object.assign({},data,{ if (data.pwdRegex) {
localStorage.setItem('password_pwdRegex', data.pwdRegex);
}
if (data.pwdRegexTip) {
localStorage.setItem('password_pwdRegexTip', data.pwdRegexTip);
}
store.dispatch(
actionCreators.getConfig(
Object.assign(
{},
data,
{
token: '', token: '',
access_token: '', access_token: '',
userInfo: null, userInfo: null,
},gateWayConfig))); },
gateWayConfig,
),
),
);
const products = (data.products || []).map(item => { const products = (data.products || []).map(item => {
if (item.PackageName === 'civweb4') { if (item.PackageName === 'civweb4') {
return 'web4_console' return 'web4_console';
} }
return `${item.PackageName}-main`; return `${item.PackageName}-main`;
}); });
if(products && products.length > 0) { if (products && products.length > 0) {
Object.keys(products).forEach(item => { Object.keys(products).forEach(item => {
window[products[item]] && window[products[item]] && window[products[item]].unmount && window[products[item]].unmount({ store: store }); window[products[item]] &&
window[products[item]] &&
window[products[item]].unmount &&
window[products[item]].unmount({ store });
}); });
initMicroApps(); initMicroApps();
} }
// eslint-disable-next-line no-new // eslint-disable-next-line no-new
if (getToken()) { if (getToken()) {
// eslint-disable-next-line no-new // eslint-disable-next-line no-new
const action = new Login({ const action = new Login(
global: Object.assign({}, data, {
global: Object.assign(
{},
data,
{ {
token: getToken(), token: getToken(),
}, },
...@@ -164,28 +177,27 @@ export const AppInitState = () => { ...@@ -164,28 +177,27 @@ export const AppInitState = () => {
}, },
() => { () => {
(async () => { (async () => {
(await (getToken() && (await (getToken() && window.globalConfig && window.globalConfig.token)) &&
window.globalConfig && // eslint-disable-next-line no-use-before-define
window.globalConfig.token)) &&
initMicroApps(loader, store); initMicroApps(loader, store);
})(); })();
}, },
true, true,
); );
action.events.on('loginSuccess', event =>{ action.events.on('loginSuccess', event => {
window.history.pushState('', '', `/?client=${client}`); window.history.pushState('', '', `/?client=${client}`);
defaultApp(); defaultApp();
}) });
} }
return window.globalConfig.variableTheme return window.globalConfig.variableTheme;
} }
}) })
.then(themeConfig => { .then(themeConfig => {
ConfigProvider.config({ ConfigProvider.config({
prefixCls: customPrefixCls, prefixCls: customPrefixCls,
theme: { theme: {
primaryColor: themeConfig.primaryColor primaryColor: themeConfig.primaryColor,
} },
}); });
registerTheme(customPrefixCls, { registerTheme(customPrefixCls, {
...@@ -196,8 +208,7 @@ export const AppInitState = () => { ...@@ -196,8 +208,7 @@ export const AppInitState = () => {
.catch(error => { .catch(error => {
store.dispatch(actionCreators.getConfigError(error)); store.dispatch(actionCreators.getConfigError(error));
}); });
} };
const initLocale = () => { const initLocale = () => {
localStorage.setItem('umi_locale', 'zh-CN'); localStorage.setItem('umi_locale', 'zh-CN');
...@@ -221,33 +232,33 @@ export const AppInitState = () => { ...@@ -221,33 +232,33 @@ export const AppInitState = () => {
// 添加主题变更事件监听 // 添加主题变更事件监听
const initAppTheme = () => { const initAppTheme = () => {
const hasThemeChanged = (preTheme, theme) => { const hasThemeChanged = (preTheme, theme) => {
if (!preTheme && !theme) return false if (!preTheme && !theme) return false;
if ( if (
preTheme && theme && preTheme &&
theme &&
(!theme.primaryColor || theme.primaryColor === preTheme.primaryColor) && (!theme.primaryColor || theme.primaryColor === preTheme.primaryColor) &&
(!theme.navTheme || theme.navTheme === preTheme.navTheme) && (!theme.navTheme || theme.navTheme === preTheme.navTheme) &&
(!theme.headerPrimaryColor || theme.headerPrimaryColor === preTheme.headerPrimaryColor) (!theme.headerPrimaryColor || theme.headerPrimaryColor === preTheme.headerPrimaryColor)
) return false )
return true return false;
} return true;
store.subscribe((function() { };
let preVariableTheme = store.getState().toJS().global?.globalConfig?.variableTheme; store.subscribe(
(function() {
const preVariableTheme = store.getState().toJS().global?.globalConfig?.variableTheme;
return function() { return function() {
// if (!preVariableTheme) // if (!preVariableTheme)
const variableTheme = store.getState().toJS().global?.globalConfig?.variableTheme; const variableTheme = store.getState().toJS().global?.globalConfig?.variableTheme;
if(!hasThemeChanged(preVariableTheme, variableTheme)) return false if (!hasThemeChanged(preVariableTheme, variableTheme)) return false;
const { const { primaryColor: prePrimaryColor, navTheme: preNavTheme, headerPrimaryColor: preHeaderPrimaryColor } =
primaryColor: prePrimaryColor, preVariableTheme || {};
navTheme: preNavTheme,
headerPrimaryColor: preHeaderPrimaryColor,
} = (preVariableTheme || {});
const { primaryColor, headerPrimaryColor } = variableTheme; const { primaryColor, headerPrimaryColor } = variableTheme;
if (primaryColor && primaryColor !== prePrimaryColor) { if (primaryColor && primaryColor !== prePrimaryColor) {
ConfigProvider.config({ ConfigProvider.config({
prefixCls: customPrefixCls, prefixCls: customPrefixCls,
theme: { theme: {
primaryColor, primaryColor,
} },
}); });
} }
if (headerPrimaryColor && headerPrimaryColor !== preHeaderPrimaryColor) { if (headerPrimaryColor && headerPrimaryColor !== preHeaderPrimaryColor) {
...@@ -255,17 +266,17 @@ export const AppInitState = () => { ...@@ -255,17 +266,17 @@ export const AppInitState = () => {
'header-bg-color': headerPrimaryColor, 'header-bg-color': headerPrimaryColor,
}); });
} }
}
})())
}; };
})(),
);
};
initLocale(); initLocale();
initMessageVoice(); initMessageVoice();
initGeteWay(); initGeteWay();
initAppTheme(); initAppTheme();
} };
const RootContainer = (props) => { const RootContainer = props => {
const { loading } = props; const { loading } = props;
useEffect(() => { useEffect(() => {
...@@ -284,7 +295,7 @@ const RootContainer = (props) => { ...@@ -284,7 +295,7 @@ const RootContainer = (props) => {
}; };
if (finalConfig.prefixCls) { if (finalConfig.prefixCls) {
Modal.config({ ConfigProvider.config({
rootPrefixCls: customPrefixCls, rootPrefixCls: customPrefixCls,
}); });
message.config({ message.config({
...@@ -295,27 +306,45 @@ const RootContainer = (props) => { ...@@ -295,27 +306,45 @@ const RootContainer = (props) => {
}); });
} }
return React.createElement(Provider, { return React.createElement(
store: store, Provider,
}, React.createElement(ConnectedRouter, { {
history: history, store,
}, React.createElement(LocaleContainer, { },
React.createElement(
ConnectedRouter,
{
history,
},
React.createElement(
LocaleContainer,
{
prefixCls: customPrefixCls, prefixCls: customPrefixCls,
}, React.createElement(ConfigProvider, { },
React.createElement(
ConfigProvider,
{
prefixCls: customPrefixCls, prefixCls: customPrefixCls,
}, React.createElement(Container, null, React.createElement(App , { },
React.createElement(
Container,
null,
React.createElement(App, {
loading, loading,
})))))); }),
),
),
),
),
);
}; };
export const render = ({ loading }) => { export const render = ({ loading }) => {
// eslint-disable-next-line react-hooks/rules-of-hooks // eslint-disable-next-line react-hooks/rules-of-hooks
ReactDOM.render(<RootContainer loading={loading} />, MOUNT_NODE); ReactDOM.render(<RootContainer loading={loading} />, MOUNT_NODE);
}; };
// updateTheme('#ff9600'); // updateTheme('#ff9600');
const loader = (loading) => render({ loading }); const loader = loading => render({ loading });
export default loader; export default loader;
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