import React, {Component} from 'react'
|
import PropTypes from 'prop-types'
|
import { is, fromJS } from 'immutable'
|
import { Form, Input, Button, notification, Checkbox } from 'antd'
|
import { UserOutlined, LockOutlined } from '@ant-design/icons'
|
|
import MKEmitter from '@/utils/events.js'
|
import './index.scss'
|
|
class LoginTabForm extends Component {
|
static propTpyes = {
|
wrap: PropTypes.object
|
}
|
|
state = {
|
activeWay: null,
|
signWays: []
|
}
|
|
UNSAFE_componentWillMount () {
|
const { wrap } = this.props
|
|
this.setState({
|
signWays: wrap.signWays,
|
activeWay: wrap.signWays[0]
|
})
|
}
|
|
UNSAFE_componentWillReceiveProps (nextProps) {
|
const { wrap } = this.props
|
|
if (!is(fromJS(wrap), fromJS(nextProps.wrap))) {
|
this.setState({
|
signWays: nextProps.wrap.signWays,
|
activeWay: nextProps.wrap.signWays[0]
|
})
|
}
|
}
|
|
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, signWays } = this.state
|
|
return (
|
<Form className="login-edit-form">
|
{activeWay === 'uname_pwd' ? <div className="form-item-wrap">
|
<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>
|
{wrap.groups ? <div className={'protocol-wrap '}>
|
<Checkbox>{wrap.tip}</Checkbox>{wrap.groups.map((item, i) => (<span className="protocol" key={i}>《{item.label}》</span>))}
|
</div> : null}
|
<Form.Item className="btn-login">
|
<Button type="primary" onDoubleClick={() => this.changeMenu()} className="sign-form-button">
|
注册
|
</Button>
|
</Form.Item>
|
</div> : null}
|
{activeWay === '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>
|
{wrap.groups ? <div className={'protocol-wrap '}>
|
<Checkbox>{wrap.tip}</Checkbox>{wrap.groups.map((item, i) => (<span className="protocol" key={i}>《{item.label}》</span>))}
|
</div> : null}
|
<Form.Item className="btn-login">
|
<Button type="primary" onDoubleClick={() => this.changeMenu()} className="sign-form-button">
|
注册
|
</Button>
|
</Form.Item>
|
</div> : null}
|
<div className={'login-ways '}>
|
<div>其他登录方式</div>
|
{signWays.map((item, i) => {
|
return (<span key={i} onClick={() => this.onChangeTab(item)}>{item}</span>)
|
})}
|
</div>
|
</Form>
|
)
|
}
|
}
|
|
export default LoginTabForm
|