| | |
| | | import React, {Component} from 'react' |
| | | import { Form, Icon, Input, Button, Checkbox, Dropdown, Menu, message } from 'antd' |
| | | import { Form, Icon, Input, Button, Checkbox, Dropdown, Menu, message, Modal } from 'antd' |
| | | import md5 from 'md5' |
| | | import moment from 'moment' |
| | | import Api from '@/api' |
| | | import zhCN from '@/locales/zh-CN/login.js' |
| | | import enUS from '@/locales/en-US/login.js' |
| | | import options from '@/store/options.js' |
| | | import logourl from '../../assets/img/login-logo.png' |
| | | import './index.scss' |
| | | |
| | | const { confirm } = Modal |
| | | |
| | | class Login extends Component { |
| | | state = { |
| | | langs: [{ |
| | | name: '中文简体', |
| | | value: 'zh-CN' |
| | | }, { |
| | | name: 'English', |
| | | value: 'en-US' |
| | | }], |
| | | selectedlang: { |
| | | name: '中文简体', |
| | | value: 'zh-CN' |
| | | }, |
| | | dict: zhCN, |
| | | isDisabled: false |
| | | constructor (props) { |
| | | super(props) |
| | | |
| | | const iszhCN = !localStorage.getItem('lang') || localStorage.getItem('lang') === 'zh-CN' |
| | | |
| | | this.state = { |
| | | langs: [{ |
| | | name: '中文简体', |
| | | value: 'zh-CN' |
| | | }, { |
| | | name: 'English', |
| | | value: 'en-US' |
| | | }], |
| | | selectedlang: iszhCN ? |
| | | { |
| | | name: '中文简体', |
| | | value: 'zh-CN' |
| | | } : |
| | | { |
| | | name: 'English', |
| | | value: 'en-US' |
| | | }, |
| | | dict: iszhCN ? zhCN : enUS, |
| | | isDisabled: false, |
| | | auth: false |
| | | } |
| | | } |
| | | |
| | | changelang (item) { |
| | |
| | | // md5密码加密 |
| | | const salt = 'minkesoft' |
| | | return md5(md5(pwd + salt)) |
| | | // return pwd |
| | | } |
| | | |
| | | handleSubmit = e => { |
| | | // 登录参数检验 |
| | | e.preventDefault() |
| | | if (!this.state.auth) { |
| | | confirm({ |
| | | title: this.state.dict['login.auth.tip'], |
| | | okText: this.state.dict['login.auth.ok'], |
| | | cancelText: this.state.dict['login.auth.cancel'], |
| | | onOk() {}, |
| | | onCancel() {} |
| | | }) |
| | | return |
| | | } |
| | | this.props.form.validateFields((err, values) => { |
| | | if (err) return |
| | | this.setState({ |
| | |
| | | let password = this.md5Password(param.password) |
| | | let result = await Api.loginsystem(param.username, password) |
| | | if (result.status) { |
| | | // if (!result.IsError) { |
| | | sessionStorage.setItem('UserID', result.userid) |
| | | sessionStorage.setItem('lang', this.state.selectedlang.value) |
| | | localStorage.setItem('lang', this.state.selectedlang.value) |
| | | |
| | | if (param.remember) { // 记住密码时账号密码存入localStorage |
| | | localStorage.setItem('username', param.username) |
| | |
| | | } |
| | | } else { |
| | | message.warning(result.message) |
| | | // message.warning(result.Message) |
| | | this.setState({ |
| | | isDisabled: false |
| | | }) |
| | | } |
| | | } |
| | | |
| | | UNSAFE_componentWillMount () { |
| | | let timeStamp = new Date().getTime() |
| | | // let str = md5('MK19' + options.AppId + timeStamp) |
| | | Api.systemauth(options.AppId, timeStamp).then(res => { |
| | | if (res.status) { |
| | | 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('AuthCode', box) |
| | | |
| | | this.setState({ |
| | | auth: true |
| | | }) |
| | | } else { |
| | | localStorage.removeItem('AuthCode') |
| | | this.setState({ |
| | | auth: false |
| | | }) |
| | | } |
| | | // console.log(str) |
| | | }) |
| | | |
| | | let authCode = localStorage.getItem('AuthCode') |
| | | let _s = md5('mksoft' + moment().format('YYYYMMDD')) |
| | | if (authCode && authCode.includes(_s)) { |
| | | this.setState({ |
| | | auth: true |
| | | }) |
| | | } |
| | | } |
| | | |
| | | render () { |
| | | const { getFieldDecorator } = this.props.form |
| | | const menu = ( |