import React, {Component} from 'react'
|
import { Spin, notification } from 'antd'
|
import md5 from 'md5'
|
import moment from 'moment'
|
|
import Api from '@/api'
|
import Utils from '@/utils/utils.js'
|
import { styles } from '@/store/options.js'
|
import './index.scss'
|
|
class SSOLogin extends Component {
|
UNSAFE_componentWillMount() {
|
try {
|
let _param = JSON.parse(window.decodeURIComponent(window.atob(this.props.match.params.param)))
|
|
if (typeof(_param) === 'object') {
|
this.authLogin(_param.appid, _param.openid, _param.memberId, _param.key)
|
} else {
|
this.props.history.replace('/login')
|
}
|
} catch (e) {
|
this.props.history.replace('/login')
|
}
|
}
|
|
authLogin = (appid, openid, memberid, scanId) => {
|
Api.getTouristMsg('mk', appid, openid, memberid, scanId).then(res => {
|
if (res.status) {
|
sessionStorage.setItem('UserID', res.UserID)
|
sessionStorage.setItem('LoginUID', res.LoginUID)
|
sessionStorage.setItem('User_Name', res.UserName)
|
sessionStorage.setItem('Full_Name', res.FullName)
|
sessionStorage.setItem('avatar', res.icon || '')
|
sessionStorage.setItem('dataM', res.dataM ? 'true' : '')
|
sessionStorage.setItem('debug', res.debug || '')
|
sessionStorage.setItem('role_id', res.role_id || '')
|
sessionStorage.setItem('departmentcode', res.departmentcode || '')
|
sessionStorage.setItem('organization', res.organization || '')
|
sessionStorage.setItem('mk_user_type', res.mk_user_type || '')
|
|
this.getMessage()
|
} else {
|
notification.warning({
|
top: 92,
|
message: res.message,
|
duration: 5
|
})
|
this.props.history.replace('/login')
|
}
|
})
|
}
|
|
getMessage = () => {
|
let _param = {
|
func: 's_Get_style',
|
TypeCharOne: 'PC',
|
LText: `select '${window.GLOB.appkey}'`,
|
}
|
|
_param.timestamp = moment().format('YYYY-MM-DD HH:mm:ss')
|
_param.secretkey = Utils.encrypt(_param.LText, _param.timestamp)
|
|
Api.getSystemConfig(_param).then(res => {
|
if (res.status) {
|
if (!['shutter', 'linkage_navigation', 'linkage', 'menu_board', 'menu_board_navigation'].includes(res.menu_type)) {
|
res.menu_type = 'shutter'
|
}
|
|
let systemMsg = {
|
favicon: res.titlelogo || '',
|
platTitle: res.titleName || '',
|
platName: res.SysName || '',
|
bgImage: res.Banner || '',
|
loginlogo: res.loginlogo || '',
|
copyRight: res.CopyRightYear && res.CopyRightOrg ? `Copyright©${res.CopyRightYear} 所有相关版权归 ${res.CopyRightOrg}` : '',
|
ICP: res.ICP || '',
|
mainlogo: res.indexlogo || '',
|
doclogo: res.doclogo || '',
|
style: res.CSS || '',
|
showline: res.split_line_show || 'true',
|
webSite: res.WebSite || '',
|
navBar: res.menu_type,
|
app_version: res.app_version,
|
Member_Level: 0,
|
appname: res.appname || ''
|
}
|
|
if ([10, 20, 30, 40, 50, 60, 70, 80, 90, 100].includes(res.member_level)) {
|
systemMsg.Member_Level = md5('mksoft' + window.GLOB.appkey + res.member_level)
|
if (!window.GLOB.memberLevel) {
|
Object.defineProperty(window.GLOB, 'memberLevel', {
|
writable: false,
|
value: res.member_level
|
})
|
}
|
}
|
|
let level = res.pwd_level || ''
|
|
if (level && !['letter_num', 'char_num', 'char_num_90', 'char_num_90_sms'].includes(level)) {
|
level = ''
|
}
|
|
localStorage.setItem(window.GLOB.sysSign + 'pwdlevel', level)
|
|
if (res.srcid) {
|
localStorage.setItem(window.GLOB.sysSign + 'srcId', res.srcid)
|
} else {
|
localStorage.removeItem(window.GLOB.sysSign + 'srcId')
|
}
|
|
sessionStorage.setItem('home_background', res.index_background_color || '')
|
|
let seconds = 0
|
if (res.sys_datetime) {
|
seconds = Math.floor((new Date(res.sys_datetime).getTime() - new Date().getTime()) / 1000)
|
}
|
sessionStorage.setItem('sys_time_shim', isNaN(seconds) ? 0 : seconds)
|
|
// url标题
|
document.title = systemMsg.platTitle
|
|
try {
|
localStorage.setItem(window.GLOB.sysSign + 'system', window.btoa(window.encodeURIComponent(JSON.stringify(systemMsg))))
|
} catch (e) {
|
localStorage.removeItem(window.GLOB.sysSign + 'system')
|
}
|
|
window.GLOB.mainlogo = systemMsg.mainlogo
|
window.GLOB.style = systemMsg.style
|
window.GLOB.navBar = systemMsg.navBar
|
window.GLOB.appVersion = systemMsg.app_version
|
sessionStorage.setItem('appname', res.appname || '')
|
|
if (window.GLOB.style && styles[window.GLOB.style]) {
|
document.body.className = styles[window.GLOB.style] + ' ' + (res.split_line_show === 'false' ? 'hidden-split-line' : '')
|
}
|
|
if (res.titlelogo && window.GLOB.favicon !== res.titlelogo) {
|
let link = document.querySelector("link[rel*='icon']") || document.createElement('link')
|
link.type = 'image/x-icon'
|
link.rel = 'shortcut icon'
|
link.href = res.titlelogo
|
document.getElementsByTagName('head')[0].appendChild(link)
|
}
|
|
this.props.history.replace('/main')
|
} else {
|
notification.warning({
|
top: 92,
|
message: res.message,
|
duration: 5
|
})
|
this.props.history.replace('/login')
|
}
|
}, () => {
|
this.props.history.replace('/login')
|
})
|
}
|
|
render () {
|
return (
|
<div className="sso-login">
|
<Spin size="large" />
|
</div>
|
)
|
}
|
}
|
|
export default SSOLogin
|