king
2021-03-12 e2a0980e4a701a3dd07c339ff24ec4221dbed2dd
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')) {
@@ -70,6 +70,10 @@
    })
  }
  /**
   * @description 账号密码登录
   * @param {Object} param 用户名密码等信息
   */
  async loginsubmit (param) {
    if (options.sysType === 'local' && !window.GLOB.mainSystemApi) { // 业务系统必须设置单点地址
      Modal.warning({
@@ -86,21 +90,22 @@
      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('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')
      if (param.remember) { // 记住密码时账号密码存入localStorage
        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 +124,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
      })
@@ -141,8 +157,16 @@
      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 || '')
      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')
      let _history = sessionStorage.getItem('history')
      if (_history) {
@@ -170,66 +194,75 @@
  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
    }
    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 => {
      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
          })
        }
      } else if (res.ErrCode === 'N') {
        localStorage.removeItem(_authUrl)
        this.setState({
          auth: false
        })
      }
    })
    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)
    if (index > -1) {
      this.setState({
        auth: true
      })
    }
    if (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('aHR0cDovL2VwYy5tazloL$mkmNuL3dlYmFwaS9kb3N0YXJz'.replace(/\$mk/ig, ''))
      let _func = window.atob('c0VtcG93ZXJDbG91$mkZF9HZXRfTGlua1VybA=='.replace(/\$mk/ig, ''))
      let _id = window.atob('YmgwYmFwYWJ0ZDQ1ZXBz$mkZ3JhNzlzZWdiY2g2YzFpYms='.replace(/\$mk/ig, ''))
      let param = {
        rduri: _rduri,
        func: _func,
        AppID: _appId,
        TimeStamp: timeStamp,
        appkey: window.GLOB.appkey,
        userid: _id,
        LoginUID: _id
      }
      Api.dostarToDostars(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(_authUrl, box)
            this.setState({
              auth: true
            })
          } else {
            localStorage.removeItem(_authUrl)
            this.setState({
              auth: false
            })
          }
        } else if (res.ErrCode === 'N') {
          localStorage.removeItem(_authUrl)
          this.setState({
            auth: false
          })
        }
      })
    }
    Api.getTouristMsg().then(result => {
      if (result.status) {
        if (!sessionStorage.getItem('UserID') && result.UserID) {
        if (result.UserID && !sessionStorage.getItem('UserID')) {
          sessionStorage.setItem('UserID', result.UserID)
        }
        if (!sessionStorage.getItem('LoginUID') && result.LoginUID) {
        if (result.LoginUID && !sessionStorage.getItem('LoginUID')) {
          sessionStorage.setItem('LoginUID', result.LoginUID)
        }
@@ -261,8 +294,12 @@
              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)
            // url标题
            document.title = systemMsg.platTitle
@@ -312,9 +349,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) {
@@ -330,6 +368,16 @@
            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)
            }
            if (res.users_upt === 'true' && window.GLOB.systemType === 'production') {
              Api.getLocalConfig ({func: 's_Get_local_u_deleted', users_upt_date: res.users_upt_date}).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}).then(ssores => {
                  if (!ssores.status) return
                  Api.getLocalConfig ({func: 's_get_local_u_create', user_ids_local: ssores.user_ids_local})
                })
              })
            }
          } else {
            message.warning(res.message)
@@ -456,7 +504,7 @@
        </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}
@@ -468,6 +516,7 @@
          cancelText={this.state.dict['login.auth.cancel']}
          visible={this.state.syncApp}
          onOk={this.syncSubmit}
          maskClosable={false}
          className="sync-cloud-application"
          width={'430px'}
          confirmLoading={this.state.syncing}