king
2023-07-17 d29a083f94142a4534c18df91582ed944e296a29
2023-07-17
5个文件已修改
182 ■■■■ 已修改文件
src/components/header/index.jsx 5 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/components/header/loginform.jsx 13 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/views/login/index.jsx 26 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/views/login/index.scss 18 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/views/login/loginform.jsx 120 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/components/header/index.jsx
@@ -347,10 +347,11 @@
          sessionStorage.setItem('isEditState', 'true')
          let _url = window.location.href.split('#')[0] + 'cloud'
          if (param.remember) {
            let _url = window.location.href.split('#')[0] + 'cloud'
            localStorage.setItem(_url, window.btoa(window.encodeURIComponent(JSON.stringify({time: new Date().getTime(), username: param.username, password: param.password}))))
          } else {
            localStorage.setItem(_url, window.btoa(window.encodeURIComponent(JSON.stringify({time: new Date().getTime(), username: param.username, password: ''}))))
          }
          this.props.modifyMainMenu(null)
src/components/header/loginform.jsx
@@ -43,7 +43,7 @@
      this.setState({
        remember: true,
        username: _user.username,
        password: '*********',
        password: _user.password ? '*********' : '',
        oripassword: _user.password
      })
    }
@@ -94,8 +94,15 @@
  }
  componentDidMount () {
    const input = document.getElementById('username')
    input && input.focus()
    const { username, password } = this.state
    if (username && !password) {
      const input = document.getElementById('password')
      input && input.focus()
    } else {
      const input = document.getElementById('username')
      input && input.focus()
    }
  }
  render() {
src/views/login/index.jsx
@@ -108,11 +108,28 @@
      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 = []
      }
      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')
@@ -171,7 +188,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()
        }
src/views/login/index.scss
@@ -115,6 +115,11 @@
      .form-item-wrap {
        // padding: 0.6vw 1.6vw 1.6vw;
        padding: 0.6vw 1.6vw 0vw;
        .ant-select-auto-complete.ant-select .ant-select-selection--single {
          height: calc(2vw + 5px);
          min-height: 30px;
        }
      }
      h4 {
@@ -283,6 +288,19 @@
    }
  }
}
.mk-user-option {
  .anticon-close-circle {
    float: right;
    opacity: 0;
    transition: opacity 0.3s;
    padding: 3px;
  }
}
.mk-user-option:hover {
  .anticon-close-circle {
    opacity: 1;
  }
}
.sync-cloud-application {
  .ant-modal-body {
    min-height: 176px;
src/views/login/loginform.jsx
@@ -1,7 +1,7 @@
import React, {Component} from 'react'
import PropTypes from 'prop-types'
import { Form, Input, Button, Checkbox, Select, Modal, message } from 'antd'
import { UserOutlined, LockOutlined, QrcodeOutlined, RedoOutlined } from '@ant-design/icons'
import { Form, Input, Button, Checkbox, Select, Modal, message, AutoComplete } from 'antd'
import { UserOutlined, LockOutlined, QrcodeOutlined, RedoOutlined, CloseCircleOutlined } from '@ant-design/icons'
import md5 from 'md5'
import moment from 'moment'
@@ -42,7 +42,8 @@
    smsId: '',
    verdisabled: false,
    hasScan: false,
    timeout: false
    timeout: false,
    users: []
  }
  timer = null
@@ -79,7 +80,27 @@
    let activeKey = _loginWays[0].type
    let users = localStorage.getItem(_url + 'users')
    let _user = null
    if (users) {
      try {
        users = JSON.parse(window.decodeURIComponent(window.atob(users)))
      } catch (e) {
        users = []
      }
    } else {
      users = []
    }
    if (users[0]) {
      _user = users[0]
    }
    this.setState({
      users: users,
      username: activeKey === 'uname_pwd' && _user ? _user.username : '',
      password: activeKey === 'uname_pwd' && _user ? _user.password : '',
      smsId: smsId,
      loginWays: _loginWays,
      activeKey,
@@ -161,7 +182,7 @@
  handleSubmit = e => {
    const { activeKey } = this.state
    // 登录参数检验
    e.preventDefault()
    e && e.preventDefault()
    if (!this.props.auth) {
      warning({
        title: this.props.authError || this.props.dict['login.auth.tip'],
@@ -175,7 +196,8 @@
    if (activeKey === 'uname_pwd') {
      if (!this.props.form.getFieldValue('username')) {
        const input = document.getElementById('username')
        const wrap = document.getElementById('username')
        const input = wrap ? wrap.getElementsByTagName('input')[0] : null
        if (input) {
          input.focus()
        }
@@ -205,33 +227,10 @@
  }
  componentDidMount () {
    let _url = window.location.href.split('#')[0]
    let _user = localStorage.getItem(_url)
    if (_user) {
      try {
        _user = JSON.parse(window.decodeURIComponent(window.atob(_user)))
      } catch (e) {
        console.warn('Parse Failure')
        _user = ''
      }
    }
    if (_user) {
      this.setState({
        username: _user.username,
        password: _user.password
      }, () => {
        const input = document.getElementById('username')
        if (input) {
          input.focus()
        }
      })
    } else {
      const input = document.getElementById('username')
      if (input) {
        input.focus()
      }
    const wrap = document.getElementById('username')
    const input = wrap ? wrap.getElementsByTagName('input')[0] : null
    if (input) {
      input.focus()
    }
  }
@@ -384,6 +383,38 @@
    localStorage.setItem(_url + 'remember', val)
  }
  complete = (val) => {
    const { users } = this.state
    let user = users.filter(m => m.username === val)[0]
    let password = user && user.password ? user.password : ''
    this.props.form.setFieldsValue({password: password})
    if (!password) {
      const input = document.getElementById('password')
      if (input) {
        input.focus()
      }
    } else {
      this.handleSubmit()
    }
  }
  deleteUser = (e, val) => {
    const { users } = this.state
    e.stopPropagation()
    let _users = users.filter(m => m.username !== val)
    this.setState({users: _users})
    let _url = window.location.href.split('#')[0]
    localStorage.setItem(_url + 'users', window.btoa(window.encodeURIComponent(JSON.stringify(_users))))
  }
  /**
   * @description 组件销毁,清除state更新
   */
@@ -396,7 +427,7 @@
  render() {
    const { getFieldDecorator } = this.props.form
    const { activeKey, verdisabled, delay, loginWays, remember, scanId, timeout, hasScan } = this.state
    const { activeKey, verdisabled, delay, loginWays, remember, scanId, timeout, hasScan, users } = this.state
    const wayLabels = {app_scan: '扫码登录', uname_pwd: '账号登录', sms_vcode: '短信登录'}
    return (
@@ -409,11 +440,24 @@
              rules: [{ required: true, message: this.props.dict['login.username.empty'] }],
              initialValue: this.state.username || '',
            })(
              <Input
                prefix={<UserOutlined style={{ color: 'rgba(0,0,0,.25)' }} />}
                placeholder={this.props.dict['login.username']}
                autoComplete="off"
              />,
              <AutoComplete
                className
                dataSource={users.map((cell, i) => <AutoComplete.Option className="mk-user-option" value={cell.username} key={i}>
                  {cell.username}
                  <CloseCircleOutlined onClick={(e) => this.deleteUser(e, cell.username)}/>
                </AutoComplete.Option>)}
                filterOption={false}
                onSelect={this.complete}
                defaultActiveFirstOption={false}
                defaultOpen={false}
                optionLabelProp="value"
              >
                <Input
                  prefix={<UserOutlined style={{ color: 'rgba(0,0,0,.25)' }} />}
                  placeholder={this.props.dict['login.username']}
                  autoComplete="off"
                />
              </AutoComplete>
            )}
          </Form.Item>
          <Form.Item>