king
2023-07-25 30e6518da8443c40063daf067970265d5da91929
src/views/login/index.jsx
@@ -5,6 +5,7 @@
import Api from '@/api'
import Utils from '@/utils/utils.js' 
import MKEmitter from '@/utils/events.js'
import options, { styles } from '@/store/options.js'
import zhCN from '@/locales/zh-CN/login.js'
import enUS from '@/locales/en-US/login.js'
@@ -13,7 +14,7 @@
import './index.scss'
const LoginForm = asyncLoadComponent(() => import('./loginform'))
const Resetpwd = asyncLoadComponent(() => import('@/components/header/resetpwd'))
const Resetpwd = asyncLoadComponent(() => import('@/components/resetPassword'))
const LoginCloudForm = asyncComponent(() => import('./logincloudform'))
const LoginCodeForm = asyncComponent(() => import('./logincodeform'))
const iszhCN = sessionStorage.getItem('lang') !== 'en-US'
@@ -39,8 +40,6 @@
    loginWays: null,
    touristLogin: false,
    syncing: false,
    visible: false,
    resetLoading: false
  }
  changelang (item) {
@@ -93,13 +92,11 @@
      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('mk_user_type', res.mk_user_type || '')
      sessionStorage.setItem('localRole_id', res.role_id || '')
      if (res.paas_externalDatabase) {
        sessionStorage.setItem('externalDatabase', res.paas_externalDatabase)
@@ -112,10 +109,17 @@
      sessionStorage.removeItem('visitorUserID')
      sessionStorage.removeItem('visitorLoginUID')
      
      if (param.remember) { // 记住密码时账号密码存入localStorage
        localStorage.setItem(_href, window.btoa(window.encodeURIComponent(JSON.stringify({username: param.username, password: param.password}))))
      let users = localStorage.getItem(_href + 'users')
      if (users) {
        try {
          users = JSON.parse(window.decodeURIComponent(window.atob(users)))
        } catch (e) {
          console.warn('Parse Failure')
          users = []
        }
      } else {
        localStorage.removeItem(_href)
        users = []
      }
      
      // positecgroup
@@ -127,6 +131,16 @@
        })
        return
      }
      users = users.filter(item => item.username !== param.username)
      if (users.length > 4) {
        users.length = 4
      }
      users.unshift({username: param.username, password: param.remember ? param.password : ''})
      localStorage.setItem(_href + 'users', window.btoa(window.encodeURIComponent(JSON.stringify(users))))
      let level = localStorage.getItem(_href + 'pwdlevel')
@@ -150,18 +164,23 @@
        if (visible) {
          message.warning(tip)
          this.setState({
            isDisabled: false,
            visible: true
            isDisabled: false
          })
          MKEmitter.emit('resetpassword', () => {
            const input = document.getElementById('password')
            if (input) {
              input.select()
            }
          })
          return
        }
      }
      let _history = sessionStorage.getItem('history')
      if (_history) {
        sessionStorage.removeItem('history')
        // 查看是否为其他页面跳转,路径存在时,跳回原页面
        this.props.history.replace(_history)
      let iframe = sessionStorage.getItem('iframe')
      if (iframe) {
        sessionStorage.removeItem('iframe')
        this.props.history.replace(iframe.replace(/@loginuid@/, res.LoginUID))
      } else {
        this.props.history.replace('/main')
      }
@@ -180,7 +199,8 @@
          input.select()
        }
      } else if (res.message.indexOf('登录权限') > -1) {
        const input = document.getElementById('username')
        const wrap = document.getElementById('username')
        const input = wrap ? wrap.getElementsByTagName('input')[0] : null
        if (input) {
          input.select()
        }
@@ -201,13 +221,11 @@
      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('mk_user_type', res.mk_user_type || '')
      sessionStorage.setItem('localRole_id', res.role_id || '')
      
      if (res.paas_externalDatabase) {
        sessionStorage.setItem('externalDatabase', res.paas_externalDatabase)
@@ -220,11 +238,10 @@
      sessionStorage.removeItem('visitorUserID')
      sessionStorage.removeItem('visitorLoginUID')
      let _history = sessionStorage.getItem('history')
      if (_history) {
        sessionStorage.removeItem('history')
        // 查看是否为其他页面跳转,路径存在时,跳回原页面
        this.props.history.replace(_history)
      let iframe = sessionStorage.getItem('iframe')
      if (iframe) {
        sessionStorage.removeItem('iframe')
        this.props.history.replace(iframe.replace(/@loginuid@/, res.LoginUID))
      } else {
        this.props.history.replace('/main')
      }
@@ -252,13 +269,11 @@
        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('mk_user_type', res.mk_user_type || '')
        sessionStorage.setItem('localRole_id', res.role_id || '')
        if (res.paas_externalDatabase) {
          sessionStorage.setItem('externalDatabase', res.paas_externalDatabase)
@@ -268,11 +283,10 @@
        sessionStorage.removeItem('visitorUserID')
        sessionStorage.removeItem('visitorLoginUID')
  
        let _history = sessionStorage.getItem('history')
        if (_history) {
          sessionStorage.removeItem('history')
          // 查看是否为其他页面跳转,路径存在时,跳回原页面
          this.props.history.replace(_history)
        let iframe = sessionStorage.getItem('iframe')
        if (iframe) {
          sessionStorage.removeItem('iframe')
          this.props.history.replace(iframe.replace(/@loginuid@/, res.LoginUID))
        } else {
          this.props.history.replace('/main')
        }
@@ -308,49 +322,22 @@
        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)
    // })
    setTimeout(() => {
      Api.delCacheConfig()
    }, 50)
    if (window.GLOB.filter) {
      let view = document.getElementById('mk-login-view')
      
      if (view) {
        view.style.filter = 'grayscale(100%)'
      }
    }
    if (sessionStorage.getItem('loginError')) {
      try {
        let res = JSON.parse(sessionStorage.getItem('loginError'))
        console.info(res.url)
        console.info(res.request)
        console.info(res.response)
        let result = JSON.parse(res.response)
        notification.warning({
          top: 92,
          message: result.message,
          duration: 5
        })
      } catch (e) {}
      setTimeout(() => {
        sessionStorage.removeItem('loginError')
      }, 2000)
    }
    const _addressUrl = _href + 'queryAddress'
@@ -485,7 +472,11 @@
      param.sign = md5(values)
      param.t = new Date().getTime()
  
      Api.directRequest(_rduri + '/' + _func, 'post', param, 'true').then(res => {
      Api.directRequest({
        url: _rduri + '/' + _func,
        method: 'post',
        data: JSON.stringify(param)
      }).then(res => {
        if (res.status) {
          if (res.EPC === str) {
            let box = []
@@ -524,6 +515,36 @@
          this.setState({
            auth: false,
            authError: res.message
          })
        }
      }, (error) => {
        if (error && error.ErrCode === 'LoginError') {
          let param = {
            func: 's_visitor_login',
            timestamp: moment().format('YYYY-MM-DD HH:mm:ss'),
            SessionUid: _id,
            TypeCharOne: 'pc',
            appkey: '202004041613277377A6A2456D34A4948AE84'
          }
          param.LText = md5(window.btoa(_id + param.timestamp))
          param.secretkey = md5(param.LText + 'mingke' + param.timestamp)
          let params = {
            url: _rduri.replace('dostars', 'dologon'),
            method: 'post',
            data: JSON.stringify(param)
          }
          Api.directRequest(params)
          return
        }
        if (index === -1 || index > 10) {
          this.setState({
            auth: false,
            authError: '网络错误导致系统授权失败,请联系管理员。'
          })
        }
      })
@@ -566,13 +587,10 @@
        _param.secretkey = Utils.encrypt(_param.LText, _param.timestamp)
        Api.getSystemConfig(_param).then(res => {
          if (!res) return
          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:') : ''
            // if (options.sysType === 'local' && window.GLOB.systemType !== 'production') {
            //   if (md5(('mk' + window.GLOB.appkey + res.sys_datetime + res.member_type + res.registry_date).toLowerCase()) !== res.secret_key) {
            //     Modal.warning({
@@ -630,10 +648,12 @@
            }
            sessionStorage.setItem('home_background', res.index_background_color || '')
            let seconds = 0
            if (res.sys_datetime) {
              sessionStorage.setItem('sys_datetime', res.sys_datetime)
              sessionStorage.setItem('app_datetime', new Date().getTime())
              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
@@ -658,7 +678,11 @@
                login_ways.push({
                  type: item.way_no,
                  smsId: item.sms_id
                })
                })
                if (item.way_no === 'sms_vcode' && item.sms_id) {
                  sessionStorage.setItem('mk_sms_id', item.sms_id)
                }
              })
            } else {
              login_ways.push({
@@ -705,7 +729,7 @@
            // positecgroup
            if (res.users_upt === 'true' && window.GLOB.systemType === 'production') {
              Api.getLocalConfig ({
              Api.genericInterface({
                func: 's_Get_local_u_deleted',
                users_upt_date: res.users_upt_date,
                userid: result.UserID,
@@ -721,7 +745,7 @@
                  LoginUID: result.LoginUID
                }).then(ssores => {
                  if (!ssores.status) return
                  Api.getLocalConfig ({
                  Api.genericInterface({
                    func: 's_get_local_u_create',
                    user_ids_local: ssores.user_ids_local,
                    userid: result.UserID,
@@ -880,60 +904,11 @@
            }
          }
          let _history = sessionStorage.getItem('history')
          if (_history) {
            sessionStorage.removeItem('history')
            // 查看是否为其他页面跳转,路径存在时,跳回原页面
            this.props.history.replace(_history)
          } else {
            this.props.history.replace('/main')
          }
          this.props.history.replace('/main')
        } else {
          notification.warning({
            top: 92,
            message: '验证码无效,请重新登录!',
            duration: 5
          })
        }
      })
    }, () => {})
  }
  resetPwdSubmit = () => {
    this.formRef.handleConfirm().then(res => {
      this.setState({
        resetLoading: true
      })
      let _param = {
        func: 's_PwdUpt',
        LText: `select '${res.originpwd}','${res.password}'`
      }
      _param.timestamp = moment().format('YYYY-MM-DD HH:mm:ss')          // 时间戳
      _param.LText = Utils.formatOptions(_param.LText)                   // 关键字符替换,base64加密
      _param.secretkey = Utils.encrypt(_param.LText, _param.timestamp)   // md5密钥
      Api.getSystemConfig(_param).then(result => {
        this.setState({
          visible: !result.status,
          resetLoading: false
        })
        if (result.status) {
          notification.success({
            top: 92,
            message: '修改成功,请重新登录。',
            duration: 2
          })
          const input = document.getElementById('password')
          if (input) {
            input.select()
          }
        } else {
          notification.warning({
            top: 92,
            message: result.message,
            duration: 5
          })
        }
@@ -1000,19 +975,7 @@
          <LoginCloudForm handleSubmit={() => this.syncSubmit()} wrappedComponentRef={(inst) => this.logincloudRef = inst}/>
        </Modal>
        {/* 修改密码 */}
        <Modal
          title="修改密码"
          okText={this.state.dict['login.ok']}
          cancelText={this.state.dict['login.cancel']}
          visible={this.state.visible}
          onOk={this.resetPwdSubmit}
          maskClosable={false}
          confirmLoading={this.state.resetLoading}
          onCancel={() => this.setState({visible: false, resetLoading: false})}
          destroyOnClose
        >
          <Resetpwd wrappedComponentRef={(inst) => this.formRef = inst} resetPwdSubmit={this.resetPwdSubmit}/>
        </Modal>
        <Resetpwd />
        {/* 二次验证 */}
        <Modal
          title="二次验证"