From ec98e336b79afc2a43c998134b46b71e0e201049 Mon Sep 17 00:00:00 2001 From: king <18310653075@163.com> Date: 星期五, 20 八月 2021 18:24:09 +0800 Subject: [PATCH] 2021-08-20 --- src/views/login/index.jsx | 140 +++++++++++++++++++++++++++++++++++++++------- 1 files changed, 118 insertions(+), 22 deletions(-) diff --git a/src/views/login/index.jsx b/src/views/login/index.jsx index 3ef55be..099622e 100644 --- a/src/views/login/index.jsx +++ b/src/views/login/index.jsx @@ -41,9 +41,7 @@ syncApp: false, loginWays: null, touristLogin: false, - syncing: false, - ipAddress: '', - city: '' + syncing: false } changelang (item) { @@ -72,13 +70,15 @@ * @param {Object} param 鐢ㄦ埛鍚嶅瘑鐮佺瓑淇℃伅 */ async loginsubmit (param) { - const { ipAddress, city } = this.state if (options.sysType === 'local' && !window.GLOB.mainSystemApi) { // 涓氬姟绯荤粺蹇呴』璁剧疆鍗曠偣鍦板潃 Modal.warning({ title: '鏈缃崟鐐规湇鍔″櫒鍦板潃锛岃鑱旂郴绠$悊鍛橈紒' }) return } + + let city = sessionStorage.getItem('city') || '' + let ipAddress = sessionStorage.getItem('ipAddress') || '' // 鐧诲綍鎻愪氦 let res = await Api.getusermsg(param.username, param.password, false, ipAddress, city) @@ -143,13 +143,15 @@ } async phoneloginsubmit (param) { - const { ipAddress, city } = this.state if (options.sysType === 'local' && !window.GLOB.mainSystemApi) { // 涓氬姟绯荤粺蹇呴』璁剧疆鍗曠偣鍦板潃 Modal.warning({ title: '鏈缃崟鐐规湇鍔″櫒鍦板潃锛岃鑱旂郴绠$悊鍛橈紒' }) return } + + let city = sessionStorage.getItem('city') || '' + let ipAddress = sessionStorage.getItem('ipAddress') || '' // 鐧诲綍鎻愪氦 let res = await Api.getphoneusermsg(param.phone, param.vercode, false, ipAddress, city) @@ -196,17 +198,104 @@ } } - componentDidMount () { - // 鑾峰彇ip鍙婂煄甯備俊鎭� - let ipurl = window.atob('aHR0cHM6Ly9lcGMubWs5a$mkC5jbi93ZWJhcGkvaXBsb2M='.replace(/\$mk/ig, '')) - Api.directRequest(ipurl, 'get', null, 'true').then(res => { - if (!res || !res.location) return - sessionStorage.setItem('city', res.location) - this.setState({ - ipAddress: res.ip || '', - city: res.location + authLogin = (appid, openid, memberid, scanId) => { + if (options.sysType === 'local' && !window.GLOB.mainSystemApi) { // 涓氬姟绯荤粺蹇呴』璁剧疆鍗曠偣鍦板潃 + Modal.warning({ + title: '鏈缃崟鐐规湇鍔″櫒鍦板潃锛岃鑱旂郴绠$悊鍛橈紒' }) + return + } + Api.getTouristMsg(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('localDataM', res.dataM ? 'true' : '') + sessionStorage.setItem('debug', res.debug || '') + sessionStorage.setItem('role_id', res.role_id || '') + sessionStorage.setItem('localRole_id', res.role_id || '') + + sessionStorage.removeItem('visitorUserID') + sessionStorage.removeItem('visitorLoginUID') + + let _history = sessionStorage.getItem('history') + if (_history) { + sessionStorage.removeItem('history') + // 鏌ョ湅鏄惁涓哄叾浠栭〉闈㈣烦杞紝璺緞瀛樺湪鏃讹紝璺冲洖鍘熼〉闈� + this.props.history.replace(_history) + } 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 + }) + } }) + } + + jsonp(url) { + return new Promise((resolve, reject) => { + window.jsonCallBack = (result) => { + resolve(result) + } + + const JSONP = document.createElement('script') + JSONP.type = 'text/javascript' + JSONP.src = url + + document.getElementsByTagName('head')[0].appendChild(JSONP) + + setTimeout(() => { + document.getElementsByTagName('head')[0].removeChild(JSONP) + },500) + }) +} + + componentDidMount () { + // md5("/ws/location/v1/ip?callback=callbackFunction&key=key&output=jsonp secret key") + // md5("/ws/location/v1/ip?callback=callbackFunction&key=BA7BZ-4QB65-LFCIA-QPDA6-4G6O7-MJB4Q&output=jsonpuThL4ZM3XOj642ksEQh76tyHFjh4") + + // 鑾峰彇ip鍙婂煄甯備俊鎭� + // let ipurl = window.atob('aHR0cHM6Ly9lcGMubWs5a$mkC5jbi93ZWJhcGkvaXBsb2M='.replace(/\$mk/ig, '')) + // Api.directRequest(ipurl, 'get', null, 'true').then(res => { + // if (!res || !res.ip) return + // sessionStorage.setItem('ipAddress', res.ip) + // }) + const _addressUrl = window.location.href.split('#')[0] + 'queryAddress' + + if (_addressUrl !== 'true') { + sessionStorage.setItem('city', '') + sessionStorage.setItem('ipAddress', '') + } else { + window.callbackFunction = (res) => { + if (res.result && res.result.ad_info) { + sessionStorage.setItem('city', res.result.ad_info.city) + sessionStorage.setItem('ipAddress', res.result.ip) + } + } + + const JSONP = document.createElement('script') + JSONP.type = 'text/javascript' + JSONP.src = 'https://apis.map.qq.com/ws/location/v1/ip?callback=callbackFunction&key=BA7BZ-4QB65-LFCIA-QPDA6-4G6O7-MJB4Q&output=jsonp&sig=3e5ebecb324ba266bf80014dcc8380db' + document.getElementsByTagName('head')[0].appendChild(JSONP) + + setTimeout(() => { + document.getElementsByTagName('head')[0].removeChild(JSONP) + },500) + } + const timeStamp = new Date().getTime() const _authUrl = window.location.href.split('#')[0] + 'AuthCode' @@ -215,13 +304,15 @@ authCode = authCode ? authCode.split(',') : [] let index = authCode.findIndex(key => key === _s) - if (index > -1) { + let key = md5(window.GLOB.appId + 'minke_software' + window.GLOB.appkey).toUpperCase().substr(-6) + + if (index > -1 || window.GLOB.licenseKey === key) { this.setState({ auth: true }) } - if (index === -1 || index > 5) { + if (window.GLOB.licenseKey !== key && (index === -1 || index > 5)) { let _appId = window.GLOB.appId if (options.sysType === 'cloud') { // 浜戠浣跨敤绯荤粺閰嶇疆appid @@ -279,6 +370,12 @@ this.setState({ auth: false }) + } + + if (res.query_address !== 'true') { + localStorage.setItem(_addressUrl, 'false') + } else { + localStorage.setItem(_addressUrl, 'true') } } else if (res.ErrCode === 'N') { localStorage.removeItem(_authUrl) @@ -451,14 +548,12 @@ try { loginWays = JSON.parse(window.decodeURIComponent(window.atob(loginWays))) } catch { - localStorage.removeItem(window.location.href.split('#')[0] + 'loginways') + loginWays = null } - if (loginWays) { - this.setState({ - loginWays: loginWays - }) - } + this.setState({ + loginWays: loginWays + }) } } @@ -558,6 +653,7 @@ isDisabled={this.state.isDisabled} changelang={(value) => this.changelang(value)} handleSubmit={() => this.handleSubmit()} + authLogin={this.authLogin} wrappedComponentRef={(inst) => this.loginformRef = inst} /> : null} </div> -- Gitblit v1.8.0