king
2025-04-03 d4d2b680baff18f950da5e77463c1f0e26dbd567
src/views/login/index.jsx
@@ -1,5 +1,5 @@
import React, { Component } from 'react'
import { message, Modal } from 'antd'
import { message, Modal, notification } from 'antd'
import md5 from 'md5'
import moment from 'moment'
@@ -7,8 +7,6 @@
import Utils from '@/utils/utils.js' 
import MKEmitter from '@/utils/events.js'
import { styles } from '@/store/options.js'
import zhCN from '@/locales/zh-CN/login.js'
import enUS from '@/locales/en-US/login.js'
import asyncComponent from '@/utils/asyncComponent'
import asyncLoadComponent from '@/utils/asyncLoadComponent'
import './index.scss'
@@ -16,14 +14,10 @@
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]
const LoginCodeForm = asyncComponent(() => import('./logincodeform'))
class Login extends Component {
  state = {
    selectedlang: iszhCN ? 'zh-CN' : 'en-US',
    dict: iszhCN ? zhCN : enUS,
    isDisabled: false,
    auth: false,
    authError: '',
@@ -37,8 +31,25 @@
    langList: [],
    syncApp: false,
    loginWays: null,
    touristLogin: false,
    syncing: false,
  }
  UNSAFE_componentWillMount() {
    localStorage.removeItem('UserID')
    localStorage.removeItem('LoginUID')
    localStorage.removeItem('User_Name')
    localStorage.removeItem('Full_Name')
    localStorage.removeItem('avatar')
    localStorage.removeItem('dataM')
    localStorage.removeItem('localDataM')
    localStorage.removeItem('debug')
    localStorage.removeItem('role_id')
    let lang = sessionStorage.getItem('lang') || 'zh-CN'
    sessionStorage.clear()
    sessionStorage.setItem('lang', lang)
  }
  handleSubmit = () => {
@@ -77,7 +88,20 @@
          return
        }
      }
      localStorage.setItem('UserID', res.UserID)
      localStorage.setItem('LoginUID', res.LoginUID)
      localStorage.setItem('User_Name', res.UserName)
      localStorage.setItem('Full_Name', res.FullName)
      localStorage.setItem('avatar', res.icon || '')
      localStorage.setItem('dataM', res.dataM ? 'true' : '')
      localStorage.setItem('localDataM', res.dataM ? 'true' : '')
      localStorage.setItem('debug', res.debug || '')
      localStorage.setItem('role_id', res.role_id || '')
      localStorage.setItem('departmentcode', res.departmentcode || '')
      localStorage.setItem('organization', res.organization || '')
      localStorage.setItem('mk_user_type', res.mk_user_type || '')
      sessionStorage.setItem('UserID', res.UserID)
      sessionStorage.setItem('LoginUID', res.LoginUID)
      sessionStorage.setItem('User_Name', res.UserName)
@@ -95,13 +119,13 @@
        window.GLOB.externalDatabase = `[${res.paas_externalDatabase}]..`
      }
      localStorage.setItem(_href + 'lang', param.lang || 'zh-CN')
      sessionStorage.setItem('lang', param.lang || 'zh-CN')
      // localStorage.setItem(_href + 'lang', param.lang || 'zh-CN')
      // sessionStorage.setItem('lang', param.lang || 'zh-CN')
      sessionStorage.removeItem('visitorUserID')
      sessionStorage.removeItem('visitorLoginUID')
      
      let users = localStorage.getItem(_href + 'users')
      let users = localStorage.getItem(window.GLOB.sysSign + 'users')
      
      if (users) {
        try {
@@ -113,6 +137,16 @@
      } else {
        users = []
      }
      // positecgroup
      if (res.token) {
        this.setState({
          isDisabled: false,
          verify: {...res, $password: param.password},
          codeVisible: true
        })
        return
      }
      users = users.filter(item => item.username !== param.username)
@@ -122,9 +156,9 @@
      users.unshift({username: param.username, password: param.remember ? param.password : ''})
      localStorage.setItem(_href + 'users', window.btoa(window.encodeURIComponent(JSON.stringify(users))))
      localStorage.setItem(window.GLOB.sysSign + 'users', window.btoa(window.encodeURIComponent(JSON.stringify(users))))
      let level = localStorage.getItem(_href + 'pwdlevel')
      let level = localStorage.getItem(window.GLOB.sysSign + 'pwdlevel')
      if (level && process.env.NODE_ENV === 'production') {
        let visible = false
@@ -159,12 +193,31 @@
        }
      }
      let iframe = sessionStorage.getItem('iframe')
      if (iframe) {
        sessionStorage.removeItem('iframe')
        this.props.history.replace(iframe.replace(/@loginuid@/, res.LoginUID))
      if (process.env.NODE_ENV === 'production' && param.username !== 'IF_DMS_APP') {
        let _param = {
          UserName: param.username,
          Password: param.password,
          BasePath: '/'
        }
        Api.loginAndRedirect(_param).then(result => {
          if (result.IsError) {
            this.setState({
              isDisabled: false
            })
            message.warning('登录失败,用户名或密码错误!')
          } else {
            let lang = sessionStorage.getItem('lang') !== 'en-US' ? '/zh-CN' : '/en-US'
            window.location.replace(document.location.origin + lang + '/Home/Index')
          }
        })
      } else {
        this.props.history.replace('/main')
        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')
        }
      }
    } else if (res.ErrCode === 'Need_Get_Appkey' && window.GLOB.sysType === 'SSO') {
      message.warning('应用尚未创建,请向云端同步应用!')
@@ -214,8 +267,8 @@
        window.GLOB.externalDatabase = `[${res.paas_externalDatabase}]..`
      }
      localStorage.setItem(_href + 'lang', param.lang || 'zh-CN')
      sessionStorage.setItem('lang', param.lang || 'zh-CN')
      // localStorage.setItem(_href + 'lang', param.lang || 'zh-CN')
      // sessionStorage.setItem('lang', param.lang || 'zh-CN')
      sessionStorage.removeItem('visitorUserID')
      sessionStorage.removeItem('visitorLoginUID')
@@ -325,14 +378,14 @@
      }
    }
    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'))
@@ -379,7 +432,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({
@@ -469,12 +522,12 @@
            localStorage.setItem(_authUrl, box)
            if (res.e_files === 'true') {
              localStorage.setItem(_href + 'files', md5(_href + 'files'))
              localStorage.setItem(_href + 'filesDate', res.e_files_end_date)
              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(_href + 'files')
              localStorage.removeItem(window.GLOB.sysSign + 'files')
              window.GLOB.storeFiles = false
            }
    
@@ -490,7 +543,7 @@
            }
          } else {
            localStorage.removeItem(_authUrl)
            localStorage.removeItem(_href + 'files')
            localStorage.removeItem(window.GLOB.sysSign + 'files')
            window.GLOB.storeFiles = false
            this.setState({
@@ -499,10 +552,15 @@
          }
          if (res.query_address !== 'true') {
            localStorage.setItem(_addressUrl, 'false')
            localStorage.removeItem(_addressUrl)
          } else {
            localStorage.setItem(_addressUrl, 'true')
            this.queryAddress()
          }
          if (res.deekseek !== 'true') {
            localStorage.removeItem(window.GLOB.sysSign + 'ds')
          } else {
            localStorage.setItem(window.GLOB.sysSign + 'ds', 'true')
          }
        } else if (res.ErrCode === 'N') {
          localStorage.removeItem(_authUrl)
@@ -564,16 +622,16 @@
        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 '${appkey}'`,
          appkey: appkey
        }
        if (window.GLOB.style_appkey) {
          _param.style_appkey = window.GLOB.style_appkey
        }
        _param.userid = result.UserID
@@ -585,38 +643,52 @@
          if (!res) return
          
          if (res.status) {
            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: '知道了'
                })
                this.setState({
                  auth: false,
                  authError: '密钥错误,请联系管理员!'
                })
                return
              } else if (res.member_type === 'personal' && res.registry_date) {
                let saveDelay = 0
                try {
                  saveDelay = parseInt((new Date().getTime() - new Date(res.registry_date).getTime()) / 4320000)
                  sessionStorage.setItem('mkDelay', saveDelay)
                } catch(e) {}
              }
            }
            // positecgroup
            // if (res.member_type && window.GLOB.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({
            //       title: '密钥错误,请联系管理员!',
            //       okText: '知道了'
            //     })
            //     this.setState({
            //       auth: false,
            //       authError: '密钥错误,请联系管理员!'
            //     })
            //     return
            //   } else if (res.member_type === 'personal' && res.registry_date) {
            //     let saveDelay = 0
            //     try {
            //       saveDelay = parseInt((new Date().getTime() - new Date(res.registry_date).getTime()) / 4320000)
            //       sessionStorage.setItem('mkDelay', saveDelay)
            //     } catch(e) {}
            //   }
            // }
            if (!['shutter', 'linkage_navigation', 'linkage', 'menu_board', 'menu_board_navigation'].includes(res.menu_type)) {
              res.menu_type = 'shutter'
            }
            let loginOtop = ''
            let loginOleft = ''
            let windowWidth = window.innerWidth
            let fix = null
            res.login_screen_offset && res.login_screen_offset.forEach(item => {
              if (!item.offset_x && !item.offset_y) return
            let _url = _href + 'system'
              if (fix === null || Math.abs(windowWidth - item.resolution_width) < fix) {
                fix = Math.abs(windowWidth - item.resolution_width)
                loginOtop = item.offset_y + item.y_unit
                loginOleft = item.offset_x + item.x_unit
              }
            })
            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 || '',
@@ -626,7 +698,9 @@
              navBar: res.menu_type, // shutter 百叶窗、linkage_navigation 联动菜单、linkage 联动菜单_无导航栏、menu_board 菜单面板、menu_board_navigation 菜单面板_标签页
              app_version: res.app_version,
              Member_Level: 0,
              appname: res.appname || ''
              appname: res.appname || '',
              loginOtop: loginOtop,
              loginOleft: loginOleft
            }
            if ([10, 20, 30, 40, 50, 60, 70, 80, 90, 100].includes(res.member_level)) {
@@ -645,15 +719,9 @@
              level = ''
            }
            localStorage.setItem(_href + 'pwdlevel', level)
            localStorage.setItem(window.GLOB.sysSign + 'pwdlevel', level)
            if (res.srcid) {
              localStorage.setItem(_href + 'srcId', res.srcid)
            } else {
              localStorage.removeItem(_href + 'srcId')
            }
            sessionStorage.setItem('home_background', res.index_background_color || '')
            res.index_background_color && sessionStorage.setItem('home_background', res.index_background_color)
            let seconds = 0
            if (res.sys_datetime) {
@@ -665,21 +733,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'].includes(item.msn_code)) {
                  item.translation = ' ' + item.translation
                }
                if (['input_tip', 'select_tip', 'max_limit', 'less_limit'].includes(item.msn_code)) {
                  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,
@@ -719,6 +807,16 @@
                }
              }
            }
            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
            }
            window.GLOB.loginOtop = systemMsg.loginOtop
            window.GLOB.loginOleft = systemMsg.loginOleft
            
            this.setState({
              loginWays: login_ways,
@@ -745,32 +843,32 @@
            }
            // positecgroup
            // if (res.users_upt === 'true' && window.GLOB.systemType === 'production') {
            //   Api.genericInterface ({
            //     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.genericInterface ({
            //         func: 's_get_local_u_create',
            //         user_ids_local: ssores.user_ids_local,
            //         userid: result.UserID,
            //         LoginUID: result.LoginUID
            //       })
            //     })
            //   })
            // }
            if (res.users_upt === 'true' && window.GLOB.systemType === 'production') {
              Api.genericInterface({
                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.genericInterface({
                    func: 's_get_local_u_create',
                    user_ids_local: ssores.user_ids_local,
                    userid: result.UserID,
                    LoginUID: result.LoginUID
                  })
                })
              })
            }
          } else {
            message.warning(res.message)
          }
@@ -780,7 +878,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)))
@@ -880,6 +978,59 @@
    })
  }
  codeSubmit = () => {
    const { verify } = this.state
    this.codeRef.handleConfirm().then(res => {
      this.setState({
        codeLoading: true
      })
      Api.verifycode({...verify, code: res.code}).then(result => {
        this.setState({
          codeVisible: false,
          codeLoading: false
        })
        if (result.verifyResult === 'success') {
          let level = localStorage.getItem(window.GLOB.sysSign + 'pwdlevel')
          if (level) {
            let visible = false
            let tip = '密码强度不够,请修改密码!'
            if (verify.$password.length < 8) {
              visible = true
            } else if (level === 'letter_num' && /^([^0-9]*|[^a-zA-Z]*)$/.test(verify.$password)) {
              visible = true
            } else if ((level === 'char_num' || level === 'char_num_90') && /^([^0-9]*|[^a-zA-Z]*|[^!@#$%^&*()_]*)$/.test(verify.$password)) {
              visible = true
            } else if (level === 'char_num_90' && verify.modifydate) {
              let s = (new Date().getTime() - new Date(verify.modifydate).getTime()) / (1000 * 24 * 60 * 60)
              if (!isNaN(s) && s > 90) {
                visible = true
                tip = '您已90天未修改密码,请更换密码后使用!'
              }
            }
            if (visible) {
              message.warning(tip)
              this.setState({
                isDisabled: false,
                visible: true
              })
              return
            }
          }
          this.props.history.replace('/main')
        } else {
          notification.warning({
            top: 92,
            message: '验证码无效,请重新登录!',
            duration: 5
          })
        }
      })
    }, () => {})
  }
  /**
   * @description 组件销毁,清除state更新
   */
@@ -890,22 +1041,31 @@
  }
  render () {
    const { lineColor, bgImage, loginlogo, copyRight, webSite, ICP, loginWays, touristLogin } = this.state
    const { lineColor, loginlogo, bgImage, copyRight, webSite, ICP, loginWays, platName } = this.state
    let wrapStyle = {}
    if (bgImage) {
      wrapStyle.backgroundImage = `url(${bgImage})`
    }
    if (window.GLOB.loginOtop) {
      wrapStyle['--mk-login-offset-top'] = window.GLOB.loginOtop
    }
    if (window.GLOB.loginOleft) {
      wrapStyle['--mk-login-offset-left'] = window.GLOB.loginOleft
    }
    return (
      <div className="login-container" id="mk-login-view" style={bgImage ? {backgroundImage: 'url(' + bgImage + ')'} : {}}>
      <div className="login-container" id="mk-login-view" style={wrapStyle}>
        <div className="logo" style={lineColor ? {borderColor: lineColor} : {}}>
          {loginlogo ? <img src={loginlogo} alt=""/> : null}
          {this.state.platName ? <p className="plat-name">{this.state.platName}</p> : null}
        </div>
        <div className="login-middle" style={lineColor ? {borderColor: lineColor} : {}}>
        <div className="login-middle">
          {loginWays ? <LoginForm
            dict={this.state.dict}
            auth={this.state.auth}
            authError={this.state.authError}
            touristLogin={touristLogin}
            platName={platName}
            loginWays={loginWays}
            lang={this.state.selectedlang}
            langList={this.state.langList}
            isDisabled={this.state.isDisabled}
            handleSubmit={() => this.handleSubmit()}
@@ -918,14 +1078,11 @@
            <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>
          }
          <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}
@@ -939,6 +1096,20 @@
        </Modal>
        {/* 修改密码 */}
        <Resetpwd />
        {/* 二次验证 */}
        <Modal
          title="二次验证"
          okText={window.GLOB.dict['ok'] || '确定'}
          cancelText={window.GLOB.dict['cancel'] || '取消'}
          visible={this.state.codeVisible}
          onOk={this.codeSubmit}
          maskClosable={false}
          confirmLoading={this.state.codeLoading}
          onCancel={() => this.setState({codeVisible: false, codeLoading: false})}
          destroyOnClose
        >
          <LoginCodeForm verify={this.state.verify} wrappedComponentRef={(inst) => this.codeRef = inst} handleSubmit={this.codeSubmit}/>
        </Modal>
      </div>
    )
  }