king
2020-12-30 e003a8ee8843aa60b0b7135f413b2b99857acff9
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
import React, {Component} from 'react'
import PropTypes from 'prop-types'
// import { is, fromJS } from 'immutable'
import { InputItem, Checkbox, Button, Picker, Toast } from 'antd-mobile'
import { createForm } from 'rc-form'
 
// import Api from '@/api'
import './index.scss'
 
const CheckboxItem = Checkbox.CheckboxItem
const CustomChildren = props => (
  <div onClick={props.onClick} style={{display: 'inline-block', width: '50%', textAlign: 'right'}}>
    <div className="test" style={{ display: 'flex', height: '45px', lineHeight: '45px' }}>
      <div style={{ flex: 1, overflow: 'hidden', textOverflow: 'ellipsis', whiteSpace: 'nowrap' }}>{props.children}</div>
    </div>
  </div>
)
 
class MobLogin extends Component {
  static propTpyes = {
    config: PropTypes.object
  }
 
  state = {
    langs: [
      {value: 'zh-CN', label: '简体中文'},
      {value: 'en-US', label: 'English'}
    ],
    lang: {value: 'zh-CN', label: '简体中文'},
    loading: false,
    rember: true
  }
 
  UNSAFE_componentWillMount () {
 
  }
 
  // shouldComponentUpdate (nextProps, nextState) {
  //   return !is(fromJS(this.props), fromJS(nextProps)) || !is(fromJS(this.state), fromJS(nextState))
  // }
 
  onChange = (e) => {
    const { rember } = this.state
    e.stopPropagation()
 
    this.setState({
      rember: !rember
    })
  }
 
  onChangeLang = (value) => {
    const { langs } = this.state
    let lang = null
 
    langs.forEach(cell => {
      if (cell.value === value[0]) {
        lang = cell
      }
    })
    Toast.success('切换成功', 3)
    
    this.setState({
      lang: lang
    })
  }
 
  execLogin = () => {
    const { config } = this.props
    // const { getFieldProps } = this.props.form
    // const { loading } = this.state
 
    // if (loading) return
 
    // let userName = getFieldProps('userName')
    // let password = getFieldProps('password')
 
    // if (!userName.value) {
    //   this.UserName.focus()
    // } else if (!password.value) {
    //   this.Password.focus()
    // } else {
      // this.setState({loading: true})
      // Api.getusermsg(userName.value, password.value).then((res) => {
      //   if (res.status) {
      //     sessionStorage.setItem('UserID', res.UserID)
      //     sessionStorage.setItem('LoginUID', res.LoginUID)
      //     this.setState({loading: false})
      //   } else {
      //     this.setState({loading: false})
      //     Toast.fail(res.message, 3)
      //   }
      // })
      this.props.history.replace({pathname: `/loading/${config.NextMenuID}`})
    // }
  }
 
  execEnter = (e) => {
    if (e.nativeEvent.keyCode === 13) {
      this.execLogin()
    }
  }
 
  render () {
    const { config } = this.props
    const { getFieldProps } = this.props.form
    const { rember, langs, lang, loading } = this.state
 
    return (
      <div className="mob-login-1" style={config.box.style}>
        <div className="mob-login-body">
          {config.logo ? <div className="logo" style={config.logo.style}>
            <img src={config.logo.content} alt=""/>
          </div> : null}
          {config.title ? <div className="plat-name" style={config.title.style}>
            {config.title.content}
          </div> : null}
          <InputItem
            placeholder="UserName"
            prefixListCls="mk-login-item am-list"
            {...getFieldProps('userName', {
              initialValue: '',
            })}
            ref={el => this.UserName = el}
            onKeyPress={this.execEnter}
          >
            <i className="minke-user" />
          </InputItem>
          <InputItem
            placeholder="Password"
            prefixListCls="mk-login-item am-list"
            {...getFieldProps('password', {
              initialValue: '',
            })}
            type={'password'}
            ref={el => this.Password = el}
            onKeyPress={this.execEnter}
          >
            <i className="minke-lock" />
          </InputItem>
          <div className="other-setting">
            <CheckboxItem checked={rember} onChange={this.onChange}>
              <span onClick={this.onChange}>记住密码</span>
            </CheckboxItem>
            <Picker data={langs} cols={1} onChange={this.onChangeLang} className="forss">
              <CustomChildren>{lang.label}</CustomChildren>
            </Picker>
            <div className="clear-both"></div>
          </div>
          <Button 
            type="primary"
            className="login"
            style={config.login.style}
            loading={loading}
            onClick={this.execLogin}
          >
            {config.login.content}
          </Button>
        </div>
        {config.copyright ? <div className="company-msg" style={config.copyright.style}>
          {config.copyright.content}
        </div> : null}
      </div>
    )
  }
}
 
export default createForm()(MobLogin)