From 48a18736c461ad730bd264b0ac7b40b68a0e33a1 Mon Sep 17 00:00:00 2001 From: king <18310653075@163.com> Date: 星期日, 28 六月 2020 20:30:20 +0800 Subject: [PATCH] 2020-06-28 --- src/views/login/index.jsx | 299 ++++++++++++++++++++++++++++++++++++++++++++++++----------- 1 files changed, 244 insertions(+), 55 deletions(-) diff --git a/src/views/login/index.jsx b/src/views/login/index.jsx index e226e96..b6cf556 100644 --- a/src/views/login/index.jsx +++ b/src/views/login/index.jsx @@ -1,20 +1,21 @@ -import React, {Component} from 'react' -import { message } from 'antd' +import React, { Component } from 'react' +import { message, Modal } from 'antd' +import { connect } from 'react-redux' import md5 from 'md5' import moment from 'moment' + import Api from '@/api' +import Utils from '@/utils/utils.js' +import options from '@/store/options.js' import zhCN from '@/locales/zh-CN/login.js' import enUS from '@/locales/en-US/login.js' -import options from '@/store/options.js' -import Utils from '@/utils/utils.js' -import asyncComponent from '@/utils/asyncComponent' -import logourl from '@/assets/img/login-logo.png' -import loginbg from '@/assets/img/loginbg.jpg' +import asyncLoadComponent from '@/utils/asyncLoadComponent' +import { modifyMemberLevel } from '@/store/action' import './index.scss' -const LoginForm = asyncComponent(() => import('./loginform')) -const Action = asyncComponent(() => import('@/tabviews/tableshare/actionList')) -const iszhCN = !localStorage.getItem('lang') || localStorage.getItem('lang') === 'zh-CN' +const LoginForm = asyncLoadComponent(() => import('./loginform')) +const LoginCloudForm = asyncLoadComponent(() => import('./logincloudform')) +const iszhCN = localStorage.getItem('lang') !== 'en-US' class Login extends Component { state = { @@ -22,15 +23,16 @@ dict: iszhCN ? zhCN : enUS, isDisabled: false, auth: false, - logo: window.GLOB.logo || logourl, - bgImage: window.GLOB.bgImage || loginbg, - platName: window.GLOB.platName || '鏄庣鍟嗕笟鏅鸿兘寮�鏀惧钩鍙�', - copyright: window.GLOB.copyRight || 'Copyright漏2017 鎵�鏈夌浉鍏崇増鏉冨綊 鍖椾含鏄庣鏅崕淇℃伅鎶�鏈湁闄愬叕鍙�', - ICP: window.GLOB.icp || 'ICP澶囨锛� 浜琁CP澶�12007830鍙�', - bgColor: window.GLOB.bgColor || '#000000', - lineColor: window.GLOB.lineColor || '#1890ff', - website: window.GLOB.website || (!window.GLOB.copyRight && 'http://minkesoft.com'), - loaded: false + loginlogo: window.GLOB.loginlogo || '', + bgImage: window.GLOB.bgImage || '', + platName: window.GLOB.platName || '', + copyRight: window.GLOB.copyRight || '', + ICP: window.GLOB.ICP || '', + lineColor: window.GLOB.lineColor || '', + webSite: window.GLOB.webSite || '', + langList: [], + syncApp: false, + syncing: false } changelang (item) { @@ -56,19 +58,24 @@ } async loginsubmit (param) { + if (options.sysType === 'local' && !window.GLOB.mainSystemApi) { // 涓氬姟绯荤粺蹇呴』璁剧疆鍗曠偣鍦板潃 + Modal.warning({ + title: '鏈缃崟鐐规湇鍔″櫒鍦板潃锛岃鑱旂郴绠$悊鍛橈紒' + }) + return + } + // 鐧诲綍鎻愪氦 - // let password = this.md5Password(param.password) - // let result = await Api.loginsystem(param.username, param.password) - // if (!result.IsError) { let res = await Api.getusermsg(param.username, param.password) if (res.status) { sessionStorage.setItem('UserID', res.UserID) sessionStorage.setItem('SessionUid', Utils.getuuid()) sessionStorage.setItem('LoginUID', res.LoginUID) sessionStorage.setItem('User_Name', res.UserName) + sessionStorage.setItem('Full_Name', res.FullName) sessionStorage.setItem('avatar', res.icon || '') - localStorage.setItem('lang', param.lang) + localStorage.setItem('lang', param.lang || 'zh-CN') let _url = window.location.href.split('#')[0] @@ -84,43 +91,59 @@ } else { this.props.history.replace('/main') } + } else if (res.ErrCode === 'Need_Get_Appkey' && options.sysType === 'SSO') { + message.warning('搴旂敤灏氭湭鍒涘缓锛岃鍚戜簯绔悓姝ュ簲鐢紒') + + this.setState({ + isDisabled: false, + syncApp: true + }) } else { message.warning(res.message) this.setState({ isDisabled: false }) } - // } else { - // message.warning(result.Message) - // this.setState({ - // isDisabled: false - // }) - // } } componentDidMount () { let timeStamp = new Date().getTime() let _appId = window.GLOB.appId - if (options.systemType === 'Cloud') { // 浜戠浣跨敤绯荤粺閰嶇疆appid - _appId = options.AppId + if (options.sysType === 'cloud') { // 浜戠浣跨敤绯荤粺閰嶇疆appid + _appId = options.caId } let str = md5('MK19' + _appId + timeStamp) - Api.systemauth(_appId, timeStamp).then(res => { - if (res.status && res.EPC === str) { - let box = [] - for (let i = 0; i < 15; i++) { - let s = 'mksoft' + moment().add(i, 'days').format('YYYYMMDD') - box.push(md5(s)) - } - box = box.join(',') - localStorage.setItem('AuthCode', box) - this.setState({ - auth: true - }) - } else { + let param = { + rduri: 'http://minkesoft.com/mksepc/webapi/dostar', + func: 'sEmpowerCloud_Get_LinkUrl', + AppID: _appId, + TimeStamp: timeStamp + } + + Api.dostarInterface(param).then(res => { + if (res.status) { + if (res.EPC === str) { + let box = [] + for (let i = 0; i < 15; i++) { + let s = 'mksoft' + moment().add(i, 'days').format('YYYYMMDD') + box.push(md5(s)) + } + box = box.join(',') + localStorage.setItem('AuthCode', box) + + this.setState({ + auth: true + }) + } else { + localStorage.removeItem('AuthCode') + this.setState({ + auth: false + }) + } + } else if (res.ErrCode === 'N') { localStorage.removeItem('AuthCode') this.setState({ auth: false @@ -135,39 +158,205 @@ auth: true }) } + + // 鑾峰彇绯荤粺淇℃伅 + let _param = { + func: 's_Get_style', + Appkey: window.GLOB.appkey || '', + TypeCharOne: 'PC', + LText: `select '${window.GLOB.appkey}'`, + } + + _param.timestamp = moment().format('YYYY-MM-DD HH:mm:ss') + '.000' + _param.secretkey = Utils.encrypt(_param.LText, _param.timestamp) + + if (window.GLOB.mainSystemApi) { + _param.rduri = window.GLOB.mainSystemApi.replace('dostars', 'dostar') + } + + Api.dostarInterface(_param).then(res => { + if (res.status) { + let _url = window.location.href.split('#')[0] + 'system' + 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 || '', + webSite: res.WebSite || '' + } + + // url鏍囬 + document.title = systemMsg.platTitle + + try { + localStorage.setItem(_url, window.btoa(window.encodeURIComponent(JSON.stringify(systemMsg)))) + } catch { + localStorage.removeItem(_url) + } + + this.setState({ + langList: res.lang_data || [], + ...systemMsg + }) + + window.GLOB.mainlogo = systemMsg.mainlogo + + 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) + } + + let memberLevel = res.member_level + + if (typeof(memberLevel) === 'number' && memberLevel > 10 && parseInt(memberLevel / 10) * 10 === memberLevel) { + sessionStorage.setItem('Member_Level', md5('mksoft' + moment().format('YYYYMM') + memberLevel)) + this.props.modifyMemberLevel(memberLevel) + } + } else { + message.warning(res.message) + } + }) + } + + syncSubmit = () => { + this.setState({ + syncing: true + }) + + let param = { + func: 's_get_app_from_cloud', + UserName: '', + Password: '', + systemType: options.sysType, + Type: 'X', + debug: 'Y' + } + + param.appkey = window.GLOB.appkey || '' + + if (options.cloudServiceApi) { + param.rduri = options.cloudServiceApi.replace('dostars', 'dostar') + } + + + this.logincloudRef.handleConfirm().then(result => { + param.UserName = result.cloudusername + param.Password = result.cloudpassword + + param.Password = Utils.formatOptions(param.Password) + + Api.dostarInterface(param).then(res => { + if (res.status) { + let _param = { + func: 's_sDataDictb_TBBack', + LTextOut: res.LTextOut, + lid: res.Lid, + Appkey: window.GLOB.appkey || '' + } + + _param.timestamp = moment().format('YYYY-MM-DD HH:mm:ss') + '.000' + _param.secretkey = Utils.encrypt(_param.LTextOut, _param.timestamp) + _param.open_key = Utils.encrypt(_param.secretkey, _param.timestamp, true) + + Api.dostarInterface(_param).then(response => { + if (response.status) { + message.success('搴旂敤鍒涘缓鎴愬姛銆�') + this.setState({ + syncing: false, + syncApp: false + }) + } else { + this.setState({ + syncing: false + }) + message.warning(response.message) + } + }) + + } else { + this.setState({ + syncing: false + }) + message.warning(res.message) + } + }) + }) + } + + /** + * @description 缁勪欢閿�姣侊紝娓呴櫎state鏇存柊 + */ + componentWillUnmount () { + this.setState = () => { + return + } } render () { + const { lineColor, bgImage, loginlogo, copyRight, webSite, ICP } = this.state return ( - <div className="login-container" style={{backgroundImage: 'url(' + this.state.bgImage + ')', backgroundColor: this.state.bgColor}}> - <div className="logo" style={{borderColor: this.state.lineColor}}> - <img src={this.state.logo} alt=""/> + <div className="login-container" style={bgImage ? {backgroundImage: 'url(' + bgImage + ')'} : {}}> + <div className="logo" style={lineColor ? {borderColor: lineColor} : {}}> + {loginlogo ? <img src={loginlogo} alt=""/> : null} </div> - <div className="login-middle" style={{borderColor: this.state.lineColor}}> + <div className="login-middle" style={lineColor ? {borderColor: lineColor} : {}}> <LoginForm platName={this.state.platName} dict={this.state.dict} auth={this.state.auth} lang={this.state.selectedlang} + langList={this.state.langList} isDisabled={this.state.isDisabled} changelang={(value) => this.changelang(value)} handleSubmit={() => this.handleSubmit()} - loaded={() => this.setState({ loaded: true })} wrappedComponentRef={(inst) => this.loginformRef = inst} /> </div> <div className="login-bottom"> - {this.state.website ? - <a target="blank" href={this.state.website} dangerouslySetInnerHTML={{ __html: this.state.copyright.replace(/\s/ig, ' ') }}></a> : - <p dangerouslySetInnerHTML={{ __html: this.state.copyright.replace(/\s/ig, ' ') }}></p> + {webSite && copyRight ? + <a target="blank" href={webSite} dangerouslySetInnerHTML={{ __html: copyRight.replace(/\s/ig, ' ') }}></a> : + <p dangerouslySetInnerHTML={{ __html: copyRight ? copyRight.replace(/\s/ig, ' ') : '' }}></p> } - <p dangerouslySetInnerHTML={{ __html: this.state.ICP.replace(/\s/ig, ' ') }}></p> + {ICP ? <p dangerouslySetInnerHTML={{ __html: ICP.replace(/\s/ig, ' ') }}></p> : null} </div> - {this.state.loaded ? <div style={{position: 'fixed', bottom: '-1000px'}}><Action setting={{}} actions={[]} /></div> : null } + {/* 缂栬緫鐘舵�佺櫥褰� */} + <Modal + title={this.state.dict['login.sync.cloud']} + okText={this.state.dict['login.auth.ok']} + cancelText={this.state.dict['login.auth.cancel']} + visible={this.state.syncApp} + onOk={this.syncSubmit} + className="sync-cloud-application" + width={'430px'} + confirmLoading={this.state.syncing} + onCancel={() => {this.setState({ syncApp: false, syncing: false })}} + destroyOnClose + > + <LoginCloudForm handleSubmit={() => this.syncSubmit()} wrappedComponentRef={(inst) => this.logincloudRef = inst}/> + </Modal> </div> ) } } -export default Login \ No newline at end of file +const mapStateToProps = () => { + return {} +} + +const mapDispatchToProps = (dispatch) => { + return { + modifyMemberLevel: (memberLevel) => dispatch(modifyMemberLevel(memberLevel)) + } +} + +export default connect(mapStateToProps, mapDispatchToProps)(Login) \ No newline at end of file -- Gitblit v1.8.0