king
2024-06-21 2bccb9ec7bdefe23292a22bc153463cfa1479a49
src/views/login/index.jsx
@@ -6,9 +6,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'
import { styles } from '@/store/options.js'
import asyncComponent from '@/utils/asyncComponent'
import asyncLoadComponent from '@/utils/asyncLoadComponent'
import './index.scss'
@@ -16,14 +14,9 @@
const LoginForm = asyncLoadComponent(() => import('./loginform'))
const Resetpwd = asyncLoadComponent(() => import('@/components/resetPassword'))
const LoginCloudForm = asyncComponent(() => import('./logincloudform'))
const iszhCN = sessionStorage.getItem('lang') !== 'en-US'
const _href = window.location.href.split('#')[0]
class Login extends Component {
  state = {
    selectedlang: iszhCN ? 'zh-CN' : 'en-US',
    dict: iszhCN ? zhCN : enUS,
    isDisabled: false,
    auth: false,
    authError: '',
@@ -37,15 +30,7 @@
    langList: [],
    syncApp: false,
    loginWays: null,
    touristLogin: false,
    syncing: false,
  }
  changelang (item) {
    // 切换语言
    this.setState({
      dict: item === 'zh-CN' ? zhCN : enUS
    })
  }
  handleSubmit = () => {
@@ -102,19 +87,33 @@
        window.GLOB.externalDatabase = `[${res.paas_externalDatabase}]..`
      }
      localStorage.setItem(_href + 'lang', param.lang || 'zh-CN')
      sessionStorage.setItem('lang', param.lang || 'zh-CN')
      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(window.GLOB.sysSign + 'users')
      if (users) {
        try {
          users = JSON.parse(window.decodeURIComponent(window.atob(users)))
        } catch (e) {
          console.warn('Parse Failure')
          users = []
        }
      } else {
        localStorage.removeItem(_href)
        users = []
      }
      let level = localStorage.getItem(_href + 'pwdlevel')
      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(window.GLOB.sysSign + 'users', window.btoa(window.encodeURIComponent(JSON.stringify(users))))
      let level = localStorage.getItem(window.GLOB.sysSign + 'pwdlevel')
      if (level && process.env.NODE_ENV === 'production') {
        let visible = false
@@ -156,7 +155,7 @@
      } else {
        this.props.history.replace('/main')
      }
    } else if (res.ErrCode === 'Need_Get_Appkey' && options.sysType === 'SSO') {
    } else if (res.ErrCode === 'Need_Get_Appkey' && window.GLOB.sysType === 'SSO') {
      message.warning('应用尚未创建,请向云端同步应用!')
      this.setState({
@@ -171,7 +170,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()
        }
@@ -203,9 +203,6 @@
        window.GLOB.externalDatabase = `[${res.paas_externalDatabase}]..`
      }
      localStorage.setItem(_href + 'lang', param.lang || 'zh-CN')
      sessionStorage.setItem('lang', param.lang || 'zh-CN')
      sessionStorage.removeItem('visitorUserID')
      sessionStorage.removeItem('visitorLoginUID')
@@ -216,7 +213,7 @@
      } else {
        this.props.history.replace('/main')
      }
    } else if (res.ErrCode === 'Need_Get_Appkey' && options.sysType === 'SSO') {
    } else if (res.ErrCode === 'Need_Get_Appkey' && window.GLOB.sysType === 'SSO') {
      message.warning('应用尚未创建,请向云端同步应用!')
      this.setState({
@@ -261,7 +258,7 @@
        } else {
          this.props.history.replace('/main')
        }
      } else if (res.ErrCode === 'Need_Get_Appkey' && options.sysType === 'SSO') {
      } else if (res.ErrCode === 'Need_Get_Appkey' && window.GLOB.sysType === 'SSO') {
        message.warning('应用尚未创建,请向云端同步应用!')
  
        this.setState({
@@ -299,6 +296,9 @@
    // 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")
    sessionStorage.removeItem('subLangList')
    sessionStorage.removeItem('langList')
    setTimeout(() => {
      Api.delCacheConfig()
    }, 50)
@@ -311,20 +311,21 @@
      }
    }
    const _addressUrl = _href + 'queryAddress'
    const _addressUrl = window.location.href.split('#')[0] + 'queryAddress'
    if (localStorage.getItem(_addressUrl) === 'true') {
      this.queryAddress()
    }
    const timeStamp = new Date().getTime()
    const _authUrl = _href + 'AuthCode'
    const _authUrl = window.location.href.split('#')[0] + 'AuthCode'
    let authCode = localStorage.getItem(_authUrl)
    let _s = md5('mksoft' + moment().format('YYYYMMDD'))
    authCode = authCode ? authCode.split(',') : []
    let index = authCode.findIndex(key => key === _s)
    let license = false
    let appkey = window.GLOB.localkey || window.GLOB.appkey
    if (window.GLOB.licenseKey) {
      if (window.GLOB.licenseKey.length !== 20) {
@@ -333,7 +334,7 @@
          okText: '知道了'
        })
      } else {
        let key = md5(window.GLOB.appId + 'minke_software' + window.GLOB.appkey).toUpperCase().substr(-6)
        let key = md5(window.GLOB.appId + 'minke_software' + appkey).toUpperCase().substr(-6)
  
        let key1 = window.GLOB.licenseKey.substring(0, 6)
        let key2 = window.GLOB.licenseKey.substring(6, 14)
@@ -341,7 +342,7 @@
        let key4 = md5(key1 + key2).toUpperCase().substr(-6)
  
        if (key === key1 && key3 === key4) {
          let last = window.GLOB.appkey[window.GLOB.appkey.length - 1]
          let last = appkey[appkey.length - 1]
          let offset = 0
          let keys = {}
      
@@ -364,7 +365,7 @@
          lictime = Math.floor(new Date(lictime).getTime() / 86400000)
          let curtime = Math.floor(new Date().getTime() / 86400000)
          let licday = lictime - curtime
          let _mindUrl = _href + 'notMind'
          let _mindUrl = window.location.href.split('#')[0] + 'notMind'
          if (licday < 0 || isNaN(licday)) {
            Modal.warning({
@@ -405,22 +406,17 @@
    }
    if (!window.GLOB.licenseKey && (index === -1 || index > 5)) {
      let _appId = window.GLOB.appId
      if (options.sysType === 'cloud') { // 云端使用系统配置appid
        _appId = options.caId
      }
      let str = md5('MK19' + _appId + timeStamp)
      let str = md5('MK19' + window.GLOB.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,
        AppID: window.GLOB.appId,
        TimeStamp: timeStamp,
        appkey: window.GLOB.appkey,
        appkey: appkey,
        SessionUid: localStorage.getItem('SessionUid') || '',
        userid: _id,
        LoginUID: _id,
        nonc: Utils.getuuid()
@@ -457,6 +453,16 @@
            }
            box = box.join(',')
            localStorage.setItem(_authUrl, box)
            if (res.e_files === 'true') {
              localStorage.setItem(window.GLOB.sysSign + 'files', md5(window.GLOB.sysSign + 'files'))
              localStorage.setItem(window.GLOB.sysSign + 'filesDate', res.e_files_end_date)
              window.GLOB.storeFiles = true
              window.GLOB.storeDate = Math.ceil((new Date(res.e_files_end_date).getTime() - new Date().getTime()) / 86400000)
            } else {
              localStorage.removeItem(window.GLOB.sysSign + 'files')
              window.GLOB.storeFiles = false
            }
    
            this.setState({
              auth: true
@@ -470,6 +476,9 @@
            }
          } else {
            localStorage.removeItem(_authUrl)
            localStorage.removeItem(window.GLOB.sysSign + 'files')
            window.GLOB.storeFiles = false
            this.setState({
              auth: false
            })
@@ -523,33 +532,30 @@
    Api.getTouristMsg().then(result => {
      if (result.status) {
        if (result.website && process.env.NODE_ENV === 'production') {
          let website = result.website.replace(/http(s)?:\/\/|\/$/ig, '').toLowerCase()
          let current = window.GLOB.baseurl.replace(/http(s)?:\/\/|\/$/ig, '').toLowerCase()
        // if (result.website && process.env.NODE_ENV === 'production') {
        //   let website = result.website.replace(/http(s)?:\/\/|\/$/ig, '').toLowerCase()
        //   let current = window.GLOB.baseurl.replace(/http(s)?:\/\/|\/$/ig, '').toLowerCase()
          if (website !== current) {
            try {
              window.history.replaceState(null, null, result.website.replace(/\/$/ig, '') + '/admin/index.html#/login')
              window.location.reload()
            } catch(e) {
              window.location.href = result.website.replace(/\/$/ig, '') + '/admin/index.html#/login'
            }
            return
          }
        }
        //   if (website !== current) {
        //     try {
        //       window.history.replaceState(null, null, result.website.replace(/\/$/ig, '') + '/admin/index.html#/login')
        //       window.location.reload()
        //     } catch(e) {
        //       window.location.href = result.website.replace(/\/$/ig, '') + '/admin/index.html#/login'
        //     }
        //     return
        //   }
        // }
        
        sessionStorage.setItem('visitorUserID', result.UserID || '')
        sessionStorage.setItem('visitorLoginUID', result.LoginUID || '')
        if (result.UserID && result.LoginUID) {
          this.setState({touristLogin: true})
        }
        // 获取系统信息
        let _param = {
          func: 's_Get_style',
          TypeCharOne: 'PC',
          LText: `select '${window.GLOB.appkey}'`,
          LText: `select '${appkey}'`,
          appkey: appkey
        }
        _param.userid = result.UserID
@@ -561,14 +567,8 @@
          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) {
            if (res.member_type && window.GLOB.sysType === 'local' && window.GLOB.systemType !== 'production') {
              if (md5(('mk' + appkey + res.sys_datetime + res.member_type + res.registry_date).toLowerCase()) !== res.secret_key) {
                Modal.warning({
                  title: '密钥错误,请联系管理员!',
                  okText: '知道了'
@@ -591,14 +591,13 @@
              res.menu_type = 'shutter'
            }
            let _url = _href + '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}` : '',
              copyRight: res.CopyRightYear && res.CopyRightOrg ? `Copyright©${res.CopyRightYear}    ${window.GLOB.dict['copyrights_by'] || '所有相关版权归'}    ${res.CopyRightOrg}` : '',
              ICP: res.ICP || '',
              mainlogo: res.indexlogo || '',
              doclogo: res.doclogo || '',
@@ -606,7 +605,19 @@
              showline: res.split_line_show || 'true',
              webSite: res.WebSite || '',
              navBar: res.menu_type, // shutter 百叶窗、linkage_navigation 联动菜单、linkage 联动菜单_无导航栏、menu_board 菜单面板、menu_board_navigation 菜单面板_标签页
              app_version: res.app_version
              app_version: res.app_version,
              Member_Level: 0,
              appname: res.appname || ''
            }
            if ([10, 20, 30, 40, 50, 60, 70, 80, 90, 100].includes(res.member_level)) {
              systemMsg.Member_Level = md5('mksoft' + appkey + res.member_level)
              if (!window.GLOB.memberLevel) {
                Object.defineProperty(window.GLOB, 'memberLevel', {
                  writable: false,
                  value: res.member_level
                })
              }
            }
            let level = res.pwd_level || ''
@@ -615,12 +626,12 @@
              level = ''
            }
            localStorage.setItem(_href + 'pwdlevel', level)
            localStorage.setItem(window.GLOB.sysSign + 'pwdlevel', level)
            if (res.srcid) {
              localStorage.setItem(_href + 'srcId', res.srcid)
              localStorage.setItem(window.GLOB.sysSign + 'srcId', res.srcid)
            } else {
              localStorage.removeItem(_href + 'srcId')
              localStorage.removeItem(window.GLOB.sysSign + 'srcId')
            }
            sessionStorage.setItem('home_background', res.index_background_color || '')
@@ -635,21 +646,41 @@
            document.title = systemMsg.platTitle
            try {
              localStorage.setItem(_url, window.btoa(window.encodeURIComponent(JSON.stringify(systemMsg))))
              localStorage.setItem(window.GLOB.sysSign + 'system', window.btoa(window.encodeURIComponent(JSON.stringify(systemMsg))))
            } catch (e) {
              localStorage.removeItem(_url)
              localStorage.removeItem(window.GLOB.sysSign + 'system')
            }
            let _loginurl = _href + 'loginways'
            if (res.lang_translation_js && res.lang_data && res.lang_data[0] && (res.lang_data.length > 1 || res.lang_data[0].Lang !== 'zh-CN')) {
              let lang = sessionStorage.getItem('lang')
              let js_trans = res.lang_translation_js.map(item => {
                if (['not_empty', 'not_zero', 'max_limit', 'less_limit']) {
                  item.translation = ' ' + item.translation
                }
                if (['input_tip', 'select_tip', 'max_limit', 'less_limit']) {
                  item.translation = item.translation + ' '
                }
                if (lang === item.lang) {
                  window.GLOB.dict[item.msn_code] = item.translation
                }
                return {
                  lang: item.lang,
                  key: item.msn_code,
                  val: item.translation
                }
              })
              localStorage.setItem(window.GLOB.sysSign + 'js_trans', JSON.stringify(js_trans))
            }
            let _loginurl = window.GLOB.sysSign + 'loginways'
            let login_ways = []
            let login_types = []
            if (res.login_ways && res.login_ways.length > 0) {
              res.login_ways.forEach(item => {
                // 短信验证码登录,必须设置短信Id
                if (item.way_no === 'sms_vcode' && !item.sms_id) return
                if (login_types.includes(item.way_no)) return
                login_types.push(item.way_no)
                if (!['sms_vcode', 'uname_pwd', 'app_scan', 'weixin_scan'].includes(item.way_no)) return
                login_ways.push({
                  type: item.way_no,
@@ -672,6 +703,30 @@
            } catch (e) {
              localStorage.removeItem(_loginurl)
            }
            if (res.lang_data && res.lang_data.length > 1 && window.GLOB.systemType !== 'production') {
              let list = res.lang_data.map(item => item.Lang)
              let lang = 'zh-CN'
              if (window.GLOB.defLang && list.includes(window.GLOB.defLang)) {
                lang = window.GLOB.defLang
              }
              if (list.includes(lang)) {
                list = [lang, ...list.filter(item => item !== lang)]
                if (lang === sessionStorage.getItem('lang')) {
                  sessionStorage.setItem('langList', JSON.stringify(list))
                } else {
                  sessionStorage.setItem('subLangList', JSON.stringify(list))
                }
              }
            }
            if (res.lang_data.length === 1 && res.lang_data[0].Lang !== sessionStorage.getItem('lang')) {
              localStorage.setItem(window.location.href.split('#')[0] + 'lang', res.lang_data[0].Lang)
              sessionStorage.setItem('lang', res.lang_data[0].Lang)
              window.location.reload()
              return
            }
            
            this.setState({
              loginWays: login_ways,
@@ -683,6 +738,7 @@
            window.GLOB.style = systemMsg.style
            window.GLOB.navBar = systemMsg.navBar
            window.GLOB.appVersion = systemMsg.app_version
            sessionStorage.setItem('appname', res.appname || '')
        
            if (window.GLOB.style && styles[window.GLOB.style]) {
              document.body.className = styles[window.GLOB.style] + ' ' + (res.split_line_show === 'false' ? 'hidden-split-line' : '')
@@ -694,13 +750,6 @@
              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' + window.GLOB.appkey + new Date().getFullYear() + new Date().getMonth() + memberLevel))
              window.GLOB.memberLevel = memberLevel
            }
            // positecgroup
@@ -739,7 +788,7 @@
      }
    })
    
    let loginWays = localStorage.getItem(_href + 'loginways')
    let loginWays = localStorage.getItem(window.GLOB.sysSign + 'loginways')
    if (loginWays) {
      try {
        loginWays = JSON.parse(window.decodeURIComponent(window.atob(loginWays)))
@@ -784,15 +833,15 @@
      func: 's_get_app_from_cloud',
      UserName: '',
      Password: '',
      systemType: options.sysType,
      systemType: window.GLOB.sysType,
      Type: 'X',
      debug: 'Y'
    }
    param.appkey = window.GLOB.appkey || ''
    if (options.cloudServiceApi) {
      param.rduri = options.cloudServiceApi.replace('dostars', 'dostar')
    if (window.GLOB.cloudServiceApi) {
      param.rduri = window.GLOB.cloudServiceApi.replace('dostars', 'dostar')
    }
    this.logincloudRef.handleConfirm().then(result => {
@@ -849,7 +898,7 @@
  }
  render () {
    const { lineColor, bgImage, loginlogo, copyRight, webSite, ICP, loginWays, touristLogin } = this.state
    const { lineColor, bgImage, loginlogo, copyRight, webSite, ICP, loginWays } = this.state
    return (
      <div className="login-container" id="mk-login-view" style={bgImage ? {backgroundImage: 'url(' + bgImage + ')'} : {}}>
@@ -859,16 +908,11 @@
        </div>
        <div className="login-middle" style={lineColor ? {borderColor: lineColor} : {}}>
          {loginWays ? <LoginForm
            platName={this.state.platName}
            dict={this.state.dict}
            auth={this.state.auth}
            authError={this.state.authError}
            touristLogin={touristLogin}
            loginWays={loginWays}
            lang={this.state.selectedlang}
            langList={this.state.langList}
            isDisabled={this.state.isDisabled}
            changelang={(value) => this.changelang(value)}
            handleSubmit={() => this.handleSubmit()}
            authLogin={this.authLogin}
            wrappedComponentRef={(inst) => this.loginformRef = inst}
@@ -879,13 +923,12 @@
            <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}
          <br/>
          {ICP ? <a target="_blank" rel="noopener noreferrer" href="https://beian.miit.gov.cn/#/Integrated/index" dangerouslySetInnerHTML={{ __html: ICP.replace(/\s/ig, '&nbsp;') }}></a> : null}
        </div>
        {/* 编辑状态登录 */}
        <Modal
          title={this.state.dict['login.sync.cloud']}
          okText={this.state.dict['login.ok']}
          cancelText={this.state.dict['login.cancel']}
          title="同步云端应用"
          visible={this.state.syncApp}
          onOk={this.syncSubmit}
          maskClosable={false}