king
2023-01-07 5b66fe77e55767eabbf1df66a026157356dd807d
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
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
import React, {Component} from 'react'
import PropTypes from 'prop-types'
import { is, fromJS } from 'immutable'
import { Form, Input, Button, Checkbox, notification } from 'antd'
import { QrcodeOutlined, UserOutlined, LockOutlined } from '@ant-design/icons'
 
import asyncElementComponent from '@/utils/asyncComponent'
import MKEmitter from '@/utils/events.js'
import './index.scss'
 
const QrCode = asyncElementComponent(() => import('@/components/qrcode'))
 
class LoginTabForm extends Component {
  static propTpyes = {
    wrap: PropTypes.object,
    changeway: PropTypes.func
  }
 
  state = {
    activeWay: null,
    loginWays: [],
    scanWay: null
  }
 
  UNSAFE_componentWillMount () {
    const { wrap } = this.props
 
    let scanWay = null
 
    let loginWays = []
    wrap.loginWays.forEach(way => {
      if (way === 'sms_vcode') {
        loginWays.push({
          type: 'sms_vcode',
          label: '短信登录',
          tempId: wrap.tempId,
          sort: 2
        })
      } else if (way === 'uname_pwd') {
        loginWays.push({
          type: 'uname_pwd',
          label: '账号登录',
          shortcut: wrap.shortcut,
          sort: 1
        })
      } else if (way === 'app_scan') {
        scanWay = {
          type: 'app_scan',
          label: '扫码登录',
          sort: 3
        }
        loginWays.push(scanWay)
      }
    })
 
    loginWays.sort((a, b) => a.sort - b.sort)
 
    this.setState({
      loginWays: loginWays,
      activeWay: loginWays[0],
      scanWay
    })
  }
 
  UNSAFE_componentWillReceiveProps (nextProps) {
    const { wrap } = this.props
 
    if (!is(fromJS(wrap), fromJS(nextProps.wrap))) {
      let scanWay = null
      let loginWays = []
      nextProps.wrap.loginWays.forEach(way => {
        if (way === 'sms_vcode') {
          loginWays.push({
            type: 'sms_vcode',
            label: '短信登录',
            tempId: wrap.tempId,
            sort: 2
          })
        } else if (way === 'uname_pwd') {
          loginWays.push({
            type: 'uname_pwd',
            label: '账号登录',
            shortcut: wrap.shortcut,
            sort: 1
          })
        } else if (way === 'app_scan') {
          scanWay = {
            type: 'app_scan',
            label: '扫码登录',
            sort: 3
          }
          loginWays.push(scanWay)
        }
      })
      loginWays.sort((a, b) => a.sort - b.sort)
 
      this.setState({
        loginWays: loginWays,
        activeWay: loginWays[0],
        scanWay
      })
    }
  }
 
  onChangeTab = (activeWay) => {
    this.setState({activeWay})
  }
 
  changeMenu = () => {
    const { wrap } = this.props
 
    if (!wrap.linkmenu) {
      notification.warning({
        top: 92,
        message: '请设置关联菜单!',
        duration: 5
      })
      return
    }
 
    MKEmitter.emit('changeEditMenu', {
      MenuID: wrap.linkmenu,
      copyMenuId: '',
      MenuNo: '',
      MenuName: ''
    })
  }
 
  /**
   * @description 组件销毁,清除state更新
   */
  componentWillUnmount () {
    this.setState = () => {
      return
    }
  }
 
  render() {
    const { wrap } = this.props
    const { activeWay, loginWays, scanWay } = this.state
 
    let style = {}
    if (wrap.borderRadius) {
      style.borderRadius = wrap.borderRadius
    }
 
    return (
      <Form className="login-edit-form">
        {wrap.topTip !== 'hidden' ? <div className="login-way-title">{activeWay.label}</div> : null}
        {scanWay && activeWay.type !== 'app_scan' ? <div className="scan-icon" onClick={() => this.onChangeTab(scanWay)}><QrcodeOutlined /></div> : null}
        {activeWay.type === 'uname_pwd' ? <div className={'form-item-wrap ' + (activeWay.shortcut === 'none' ? 'no-short' : '')}>
          <Form.Item>
            <Input
              prefix={<UserOutlined style={{ color: 'rgba(0,0,0,.25)' }} />}
              placeholder="用户名/手机号/邮箱"
              autoComplete="off"
            />
          </Form.Item>
          <Form.Item>
            <Input.Password placeholder="密码" prefix={<LockOutlined style={{ color: 'rgba(0,0,0,.25)' }} />} />
          </Form.Item>
          {!activeWay.shortcut || activeWay.shortcut === 'remember' ? <Form.Item className="minline">
            <Checkbox>记住密码</Checkbox>
          </Form.Item> : null}
          {activeWay.shortcut === 'autologon' ? <Form.Item className="minline">
            <Checkbox>自动登录</Checkbox>
          </Form.Item> : null}
          <Form.Item className="btn-login">
            <Button type="primary" style={style} onDoubleClick={() => this.changeMenu()} className="login-form-button">
              登录
            </Button>
          </Form.Item>
        </div> : null}
        {activeWay.type === 'sms_vcode' ? <div className="form-item-wrap">
          <Form.Item>
            <Input
              placeholder="手机号"
              autoComplete="off"
            />
          </Form.Item>
          <Form.Item style={{marginBottom: '35px'}}>
            <Input
              addonAfter={
                <Button type="link" className="vercode" size="small">
                  获取验证码
                </Button>
              }
              placeholder="验证码"
              autoComplete="off"
            />
          </Form.Item>
          <Form.Item className="btn-login">
            <Button type="primary" style={style} onDoubleClick={() => this.changeMenu()} className="login-form-button">
              登录
            </Button>
          </Form.Item>
        </div> : null}
        {activeWay.type === 'app_scan' ? <div className="form-scan-wrap">
          <div className="qr-wrap">
            <QrCode card={{qrWidth: 500, color: '#000000'}} value={'minkesoft'}/>
          </div>
          请使用客户端扫一扫登录
        </div> : null}
        {wrap.classify !== 'login' ? <span className="mk-jump-way" onClick={() => this.props.changeway()}>没有账号,去注册?</span> : null}
        <div className={'login-ways ' + (activeWay.type === 'app_scan' ? 'center' : '')}>
          {loginWays.map(item => {
            if (item.type === 'app_scan' || activeWay.type === item.type) return null
            return (<span key={item.type} onClick={() => this.onChangeTab(item)}>{item.label}</span>)
          })}
        </div>
      </Form>
    )
  }
}
 
export default LoginTabForm