From 31ec63f0419895876cbaba99637a884a32d33d0d Mon Sep 17 00:00:00 2001
From: king <18310653075@163.com>
Date: 星期三, 01 九月 2021 10:31:45 +0800
Subject: [PATCH] 2021-09-01

---
 src/views/login/index.jsx |  370 +++++++++++++++++++++++++++++++++++++++++-----------
 1 files changed, 290 insertions(+), 80 deletions(-)

diff --git a/src/views/login/index.jsx b/src/views/login/index.jsx
index 318cb49..8469483 100644
--- a/src/views/login/index.jsx
+++ b/src/views/login/index.jsx
@@ -6,7 +6,7 @@
 
 import Api from '@/api'
 import Utils from '@/utils/utils.js' 
-import options from '@/store/options.js'
+import options, { styles } from '@/store/options.js'
 import zhCN from '@/locales/zh-CN/login.js'
 import enUS from '@/locales/en-US/login.js'
 import asyncLoadComponent from '@/utils/asyncLoadComponent'
@@ -15,7 +15,7 @@
 
 const LoginForm = asyncLoadComponent(() => import('./loginform'))
 const LoginCloudForm = asyncLoadComponent(() => import('./logincloudform'))
-const iszhCN = localStorage.getItem('lang') !== 'en-US'
+const iszhCN = sessionStorage.getItem('lang') !== 'en-US'
 
 const _href = window.location.href.split('#')[0]
 if (localStorage.getItem(_href + 'paramsmain')) {
@@ -29,6 +29,7 @@
     dict: iszhCN ? zhCN : enUS,
     isDisabled: false,
     auth: false,
+    authError: '',
     loginlogo: window.GLOB.loginlogo || '',
     bgImage: window.GLOB.bgImage || '',
     platName: window.GLOB.platName || '',
@@ -49,12 +50,6 @@
       dict: item === 'zh-CN' ? zhCN : enUS
     })
   }
-  
-  md5Password (pwd) {
-    // md5瀵嗙爜鍔犲瘑
-    const salt = 'minkesoft'
-    return md5(md5(pwd + salt))
-  }
 
   handleSubmit = () => {
     this.loginformRef.handleConfirm().then(res => {
@@ -70,6 +65,10 @@
     })
   }
 
+  /**
+   * @description 璐﹀彿瀵嗙爜鐧诲綍
+   * @param {Object} param 鐢ㄦ埛鍚嶅瘑鐮佺瓑淇℃伅
+   */
   async loginsubmit (param) {
     if (options.sysType === 'local' && !window.GLOB.mainSystemApi) { // 涓氬姟绯荤粺蹇呴』璁剧疆鍗曠偣鍦板潃
       Modal.warning({
@@ -78,29 +77,38 @@
       return
     }
 
+    let city = sessionStorage.getItem('city') || ''
+    let ipAddress = sessionStorage.getItem('ipAddress') || ''
+
     // 鐧诲綍鎻愪氦
-    let res = await Api.getusermsg(param.username, param.password)
+    let res = await Api.getusermsg(param.username, param.password, false, ipAddress, city)
     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 || '')
-
-      localStorage.setItem('lang', param.lang || 'zh-CN')
-
+      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('departmentcode', res.departmentcode || '')
+      sessionStorage.setItem('organization', res.organization || '')
+      sessionStorage.setItem('localRole_id', res.role_id || '')
+      
       let _url = window.location.href.split('#')[0]
 
+      localStorage.setItem(_url + 'lang', param.lang || 'zh-CN')
+      sessionStorage.setItem('lang', param.lang || 'zh-CN')
+
+      sessionStorage.removeItem('visitorUserID')
+      sessionStorage.removeItem('visitorLoginUID')
+      
       if (param.remember) { // 璁颁綇瀵嗙爜鏃惰处鍙峰瘑鐮佸瓨鍏ocalStorage
         localStorage.setItem(_url, window.btoa(window.encodeURIComponent(JSON.stringify({username: param.username, password: param.password}))))
       } else {
         localStorage.removeItem(_url)
       }
-
-      // if (this.props.location.state && this.props.location.state.from.pathname) {
-      //   // 鏌ョ湅鏄惁涓哄叾浠栭〉闈㈣烦杞紝璺緞瀛樺湪鏃讹紝璺冲洖鍘熼〉闈�
-      //   this.props.history.replace(this.props.location.state.from.pathname)
-      // }
 
       let _history = sessionStorage.getItem('history')
       if (_history) {
@@ -119,6 +127,17 @@
       })
     } else {
       message.warning(res.message)
+      if (res.message.indexOf('瀵嗙爜閿欒') > -1) {
+        const input = document.getElementById('password')
+        if (input) {
+          input.select()
+        }
+      } else if (res.message.indexOf('鐧诲綍鏉冮檺') > -1) {
+        const input = document.getElementById('username')
+        if (input) {
+          input.select()
+        }
+      }
       this.setState({
         isDisabled: false
       })
@@ -133,16 +152,32 @@
       return
     }
 
+    let city = sessionStorage.getItem('city') || ''
+    let ipAddress = sessionStorage.getItem('ipAddress') || ''
+
     // 鐧诲綍鎻愪氦
-    let res = await Api.getphoneusermsg(param.phone, param.vercode)
+    let res = await Api.getphoneusermsg(param.phone, param.vercode, false, ipAddress, city)
     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('departmentcode', res.departmentcode || '')
+      sessionStorage.setItem('organization', res.organization || '')
+      sessionStorage.setItem('localRole_id', res.role_id || '')
 
-      localStorage.setItem('lang', param.lang || 'zh-CN')
+      let _url = window.location.href.split('#')[0]
+
+      localStorage.setItem(_url + 'lang', param.lang || 'zh-CN')
+      sessionStorage.setItem('lang', param.lang || 'zh-CN')
+
+      sessionStorage.removeItem('visitorUserID')
+      sessionStorage.removeItem('visitorLoginUID')
 
       let _history = sessionStorage.getItem('history')
       if (_history) {
@@ -167,71 +202,201 @@
     }
   }
 
-  componentDidMount () {
-    const timeStamp = new Date().getTime()
-    const _authUrl = window.location.href.split('#')[0] + 'AuthCode'
-    let _appId = window.GLOB.appId
-
-    if (options.sysType === 'cloud') { // 浜戠浣跨敤绯荤粺閰嶇疆appid
-      _appId = options.caId
+  authLogin = (appid, openid, memberid, scanId) => {
+    if (options.sysType === 'local' && !window.GLOB.mainSystemApi) { // 涓氬姟绯荤粺蹇呴』璁剧疆鍗曠偣鍦板潃
+      Modal.warning({
+        title: '鏈缃崟鐐规湇鍔″櫒鍦板潃锛岃鑱旂郴绠$悊鍛橈紒'
+      })
+      return
     }
-
-    let str = md5('MK19' + _appId + timeStamp)
-
-    let param = {
-      rduri: 'http://minkesoft.com/mksepc/webapi/dostars',
-      func: 'sEmpowerCloud_Get_LinkUrl',
-      AppID: _appId,
-      TimeStamp: timeStamp,
-      appkey: window.GLOB.appkey,
-      userid: 'bh0bapabtd45epsgra79segbch6c1ibk',
-      LoginUID: 'bh0bapabtd45epsgra79segbch6c1ibk'
-    }
-
-    Api.dostarToDostars(param).then(res => {
+    Api.getTouristMsg(appid, openid, memberid, scanId).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(_authUrl, box)
+        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('departmentcode', res.departmentcode || '')
+        sessionStorage.setItem('organization', res.organization || '')
+        sessionStorage.setItem('localRole_id', res.role_id || '')
   
-          this.setState({
-            auth: true
-          })
+        sessionStorage.removeItem('visitorUserID')
+        sessionStorage.removeItem('visitorLoginUID')
+  
+        let _history = sessionStorage.getItem('history')
+        if (_history) {
+          sessionStorage.removeItem('history')
+          // 鏌ョ湅鏄惁涓哄叾浠栭〉闈㈣烦杞紝璺緞瀛樺湪鏃讹紝璺冲洖鍘熼〉闈�
+          this.props.history.replace(_history)
         } else {
-          localStorage.removeItem(_authUrl)
-          this.setState({
-            auth: false
-          })
+          this.props.history.replace('/main')
         }
-      } else if (res.ErrCode === 'N') {
-        localStorage.removeItem(_authUrl)
+      } else if (res.ErrCode === 'Need_Get_Appkey' && options.sysType === 'SSO') {
+        message.warning('搴旂敤灏氭湭鍒涘缓锛岃鍚戜簯绔悓姝ュ簲鐢紒')
+  
         this.setState({
-          auth: false
+          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'
 
     let authCode = localStorage.getItem(_authUrl)
     let _s = md5('mksoft' + moment().format('YYYYMMDD'))
-    if (authCode && authCode.includes(_s)) {
+    authCode = authCode ? authCode.split(',') : []
+    let index = authCode.findIndex(key => key === _s)
+
+    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 (window.GLOB.licenseKey !== key && (index === -1 || index > 5)) {
+      let _appId = window.GLOB.appId
+  
+      if (options.sysType === 'cloud') { // 浜戠浣跨敤绯荤粺閰嶇疆appid
+        _appId = options.caId
+      }
+  
+      let str = md5('MK19' + _appId + timeStamp)
+      let _rduri = window.atob('aHR0cHM6Ly9lcGMubWs5aC5$mkjbi93ZWJhcGkvZG9zdGFycw=='.replace(/\$mk/ig, ''))
+      let _func = window.atob('c0VtcG93ZXJDbG91$mkZF9HZXRfTGlua1VybA=='.replace(/\$mk/ig, ''))
+      let _id = window.atob('YmgwYmFwYWJ0ZDQ1ZXBz$mkZ3JhNzlzZWdiY2g2YzFpYms='.replace(/\$mk/ig, ''))
+  
+      let param = {
+        func: _func,
+        AppID: _appId,
+        TimeStamp: timeStamp,
+        appkey: window.GLOB.appkey,
+        userid: _id,
+        LoginUID: _id,
+        nonc: Utils.getuuid()
+      }
+
+      // param = {
+      //   func: _func,
+      //   VerificationCode: '鎺堟潈鐮�',
+      //   TimeStamp: timeStamp,
+      //   userid: _id,
+      //   LoginUID: _id,
+      //   nonc: Utils.getuuid()
+      // }
+
+      let keys = Object.keys(param).sort()
+      let values = ''
+      keys.forEach(key => {
+        values += key + param[key]
+      })
+      param.sign = md5(values)
+      param.t = new Date().getTime()
+  
+      Api.directRequest(_rduri + '/' + _func, 'post', param, 'true').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(_authUrl, box)
+    
+            this.setState({
+              auth: true
+            })
+          } else {
+            localStorage.removeItem(_authUrl)
+            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)
+          this.setState({
+            auth: false,
+            authError: res.message
+          })
+        }
+      })
+    }
+
     Api.getTouristMsg().then(result => {
       if (result.status) {
-        if (!sessionStorage.getItem('UserID') && result.UserID) {
-          sessionStorage.setItem('UserID', result.UserID)
-        }
-        if (!sessionStorage.getItem('LoginUID') && result.LoginUID) {
-          sessionStorage.setItem('LoginUID', result.LoginUID)
-        }
+        sessionStorage.setItem('visitorUserID', result.UserID || '')
+        sessionStorage.setItem('visitorLoginUID', result.LoginUID || '')
 
         if (result.UserID && result.LoginUID) {
           this.setState({touristLogin: true})
@@ -244,11 +409,19 @@
           LText: `select '${window.GLOB.appkey}'`,
         }
 
+        _param.userid = result.UserID
+        _param.LoginUID = result.LoginUID
         _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) {
+            // positecgroup
+            // res.Banner = res.Banner ? res.Banner.replace(/:8080/ig, '').replace(/http:/ig, 'https:') : ''
+            // res.doclogo = res.doclogo ? res.doclogo.replace(/:8080/ig, '').replace(/http:/ig, 'https:') : ''
+            // res.indexlogo = res.indexlogo ? res.indexlogo.replace(/:8080/ig, '').replace(/http:/ig, 'https:') : ''
+            // res.loginlogo = res.loginlogo ? res.loginlogo.replace(/:8080/ig, '').replace(/http:/ig, 'https:') : ''
+
             let _url = window.location.href.split('#')[0] + 'system'
             let systemMsg = {
               favicon: res.titlelogo || '',
@@ -261,7 +434,15 @@
               mainlogo: res.indexlogo || '',
               doclogo: res.doclogo || '',
               style: res.CSS || '',
-              webSite: res.WebSite || ''
+              showline: res.split_line_show || 'true',
+              webSite: res.WebSite || '',
+              navBar: res.menu_type
+            }
+
+            sessionStorage.setItem('home_background', res.index_background_color || '')
+            if (res.sys_datetime) {
+              sessionStorage.setItem('sys_datetime', res.sys_datetime)
+              sessionStorage.setItem('app_datetime', new Date().getTime())
             }
 
             // url鏍囬
@@ -269,7 +450,7 @@
 
             try {
               localStorage.setItem(_url, window.btoa(window.encodeURIComponent(JSON.stringify(systemMsg))))
-            } catch {
+            } catch (e) {
               localStorage.removeItem(_url)
             }
 
@@ -300,7 +481,7 @@
 
             try {
               localStorage.setItem(_loginurl, window.btoa(window.encodeURIComponent(JSON.stringify(login_ways))))
-            } catch {
+            } catch (e) {
               localStorage.removeItem(_loginurl)
             }
             
@@ -312,9 +493,10 @@
 
             window.GLOB.mainlogo = systemMsg.mainlogo
             window.GLOB.style = systemMsg.style
+            window.GLOB.navBar = systemMsg.navBar
         
-            if (window.GLOB.style && options.styles[window.GLOB.style]) {
-              document.getElementById('root').className = options.styles[window.GLOB.style]
+            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) {
@@ -331,6 +513,33 @@
               sessionStorage.setItem('Member_Level', md5('mksoft' + moment().format('YYYYMM') + memberLevel))
               this.props.modifyMemberLevel(memberLevel)
             }
+
+            if (res.users_upt === 'true' && window.GLOB.systemType === 'production') {
+              Api.getLocalConfig ({
+                func: 's_Get_local_u_deleted',
+                users_upt_date: res.users_upt_date,
+                userid: result.UserID,
+                LoginUID: result.LoginUID
+              }).then(localres => {
+                if (!localres.status) return
+                Api.getSystemConfig({
+                  func: 's_get_sso_u_create',
+                  user_ids: localres.user_ids,
+                  user_ids_local: localres.user_ids_local,
+                  users_upt_date: localres.users_upt_date,
+                  userid: result.UserID,
+                  LoginUID: result.LoginUID
+                }).then(ssores => {
+                  if (!ssores.status) return
+                  Api.getLocalConfig ({
+                    func: 's_get_local_u_create',
+                    user_ids_local: ssores.user_ids_local,
+                    userid: result.UserID,
+                    LoginUID: result.LoginUID
+                  })
+                })
+              })
+            }
           } else {
             message.warning(res.message)
           }
@@ -344,15 +553,13 @@
     if (loginWays) {
       try {
         loginWays = JSON.parse(window.decodeURIComponent(window.atob(loginWays)))
-      } catch {
-        localStorage.removeItem(window.location.href.split('#')[0] + 'loginways')
+      } catch (e) {
+        loginWays = null
       }
 
-      if (loginWays) {
-        this.setState({
-          loginWays: loginWays
-        })
-      }
+      this.setState({
+        loginWays: loginWays
+      })
     }
   }
 
@@ -444,6 +651,7 @@
             platName={this.state.platName}
             dict={this.state.dict}
             auth={this.state.auth}
+            authError={this.state.authError}
             touristLogin={touristLogin}
             loginWays={loginWays}
             lang={this.state.selectedlang}
@@ -451,12 +659,13 @@
             isDisabled={this.state.isDisabled}
             changelang={(value) => this.changelang(value)}
             handleSubmit={() => this.handleSubmit()}
+            authLogin={this.authLogin}
             wrappedComponentRef={(inst) => this.loginformRef = inst}
           /> : null}
         </div>
         <div className="login-bottom">
           {webSite && copyRight ?
-            <a target="blank" href={webSite} dangerouslySetInnerHTML={{ __html: copyRight.replace(/\s/ig, '&nbsp;') }}></a> :
+            <a target="_blank" rel="noopener noreferrer" href={webSite} dangerouslySetInnerHTML={{ __html: copyRight.replace(/\s/ig, '&nbsp;') }}></a> :
             <p dangerouslySetInnerHTML={{ __html: copyRight ? copyRight.replace(/\s/ig, '&nbsp;') : '' }}></p>
           }
           {ICP ? <p dangerouslySetInnerHTML={{ __html: ICP.replace(/\s/ig, '&nbsp;') }}></p> : null}
@@ -464,10 +673,11 @@
         {/* 缂栬緫鐘舵�佺櫥褰� */}
         <Modal
           title={this.state.dict['login.sync.cloud']}
-          okText={this.state.dict['login.auth.ok']}
-          cancelText={this.state.dict['login.auth.cancel']}
+          okText={this.state.dict['login.ok']}
+          cancelText={this.state.dict['login.cancel']}
           visible={this.state.syncApp}
           onOk={this.syncSubmit}
+          maskClosable={false}
           className="sync-cloud-application"
           width={'430px'}
           confirmLoading={this.state.syncing}

--
Gitblit v1.8.0