index.js 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241
  1. import React, { Component } from 'react';
  2. import './index.less';
  3. import { Modal, Icon, Button, Tooltip } from 'antd';
  4. import Assets from '@src/components/Assets';
  5. import { Icon as GIcon } from '../Icon';
  6. import { Button as GButton } from '../Button';
  7. const LOGIN_PHONE = 'LOGIN_PHONE';
  8. const REGISTER_PHONE = 'REGISTER_PHONE';
  9. const LOGIN_WX = 'LOGIN_WX';
  10. const BIND_PHONE = 'BIND_PHONE';
  11. const BIND_WX = 'BIND_WX';
  12. const BIND_WX_ERROR = 'BIND_WX_ERROR';
  13. export default class Login extends Component {
  14. constructor(props) {
  15. super(props);
  16. this.state = { show: false, type: BIND_WX_ERROR };
  17. }
  18. render() {
  19. const { show, type } = this.state;
  20. return (
  21. <Modal wrapClassName={`login-modal ${type}`} visible={show} footer={null} closable={false} width={470}>
  22. {this.renderBody(type)}
  23. <GIcon name="close" />
  24. </Modal>
  25. );
  26. }
  27. renderBody(type) {
  28. switch (type) {
  29. case LOGIN_PHONE:
  30. return this.renderLoginPhone();
  31. case REGISTER_PHONE:
  32. return this.renderRegisterPhone();
  33. case LOGIN_WX:
  34. return this.renderLoginWx();
  35. case BIND_PHONE:
  36. return this.renderBindPhone();
  37. case BIND_WX:
  38. return this.renderBindWx();
  39. case BIND_WX_ERROR:
  40. return this.renderBindWxError();
  41. default:
  42. return this.LOGIN_PHONE();
  43. }
  44. }
  45. renderLoginPhone() {
  46. return (
  47. <div className="body">
  48. <div className="title">手机号登录</div>
  49. <SelectInput placeholder="请输入手机号" />
  50. <VerificationInput placeholder="请输入验证码" />
  51. <Button type="primary" size="large" block>
  52. 登录
  53. </Button>
  54. <Tooltip overlayClassName="gray" placement="left" title="微信扫码登录">
  55. <a className="other">
  56. <Assets name="code" />
  57. </a>
  58. </Tooltip>
  59. </div>
  60. );
  61. }
  62. renderRegisterPhone() {
  63. return (
  64. <div className="body">
  65. <div className="title">手机号登录</div>
  66. <div className="tip">
  67. <Assets name="notice" />
  68. 该手机号尚未注册,将自动为您注册账户
  69. </div>
  70. <SelectInput placeholder="请输入手机号" />
  71. <VerificationInput placeholder="请输入验证码" />
  72. <Input placeholder="请输入邮箱" />
  73. <Button type="primary" size="large" block>
  74. 登录
  75. </Button>
  76. <Tooltip overlayClassName="gray" placement="left" title="微信扫码登录">
  77. <a className="other">
  78. <Assets name="code" />
  79. </a>
  80. </Tooltip>
  81. </div>
  82. );
  83. }
  84. renderLoginWx() {
  85. return (
  86. <div className="body">
  87. <div className="title">微信扫码登录</div>
  88. <div className="qr-code">
  89. <Assets name="qrcode" />
  90. <div className="text">请使用微信扫描二维码登录</div>
  91. </div>
  92. <Tooltip overlayClassName="gray" placement="left" title="手机号登录">
  93. <a className="other">
  94. <Assets name="phone" />
  95. </a>
  96. </Tooltip>
  97. </div>
  98. );
  99. }
  100. renderBindPhone() {
  101. return (
  102. <div className="body">
  103. <div className="title">绑定手机号</div>
  104. <div className="tip">
  105. <Assets name="notice" />
  106. 微信登录成功!为更好的使用服务,请您绑定手机号和邮箱。
  107. </div>
  108. <SelectInput placeholder="请输入手机号" />
  109. <VerificationInput placeholder="请输入验证码" />
  110. <Input placeholder="请输入邮箱" />
  111. <Button type="primary" size="large" block>
  112. 绑定
  113. </Button>
  114. </div>
  115. );
  116. }
  117. renderBindWx() {
  118. return (
  119. <div className="body">
  120. <div className="title">绑定微信号</div>
  121. <div className="tip">
  122. <Assets name="notice" />
  123. 手机号注册成功!为更好的使用服务,建议您绑定微信号。
  124. </div>
  125. <div className="qr-code">
  126. <Assets name="qrcode" />
  127. <div className="text">请使用微信扫描二维码登录</div>
  128. <div className="jump">跳过</div>
  129. </div>
  130. </div>
  131. );
  132. }
  133. renderBindWxError() {
  134. return (
  135. <div className="body">
  136. <div className="title">绑定失败</div>
  137. <div className="text">该微信账户已绑定其他手机号,您可直接使用微信登入。</div>
  138. <div className="btn">
  139. <GButton radius>Ok</GButton>
  140. </div>
  141. </div>
  142. );
  143. }
  144. }
  145. class Input extends Component {
  146. render() {
  147. const { className = '', onChange, placeholder, error, left, right } = this.props;
  148. return (
  149. <div className={`g-input-container ${className}`}>
  150. <div className={`g-input-wrapper ${error ? 'error' : ''}`}>
  151. {left && <div className="g-input-left">{left}</div>}
  152. <input className="g-input" placeholder={placeholder} onChange={data => onChange && onChange(data)} />
  153. {right && <div className="g-input-right">{right}</div>}
  154. </div>
  155. <div hidden={!error} className="g-input-error">
  156. {error}
  157. </div>
  158. </div>
  159. );
  160. }
  161. }
  162. class SelectInput extends Component {
  163. render() {
  164. const { className = '', onChange, placeholder, value, selectValue, onSelect } = this.props;
  165. return (
  166. <Input
  167. className={className}
  168. left={
  169. <span className="g-input-left-select" onClick={() => onSelect && onSelect()}>
  170. {selectValue}
  171. <Icon type="down" />
  172. </span>
  173. }
  174. value={value}
  175. placeholder={placeholder}
  176. onChange={data => onChange && onChange(data)}
  177. />
  178. );
  179. }
  180. }
  181. class VerificationInput extends Component {
  182. constructor(props) {
  183. super(props);
  184. this.timeKey = null;
  185. this.state = { loading: 0 };
  186. }
  187. componentWillUnmount() {
  188. if (this.timeKey) clearTimeout(this.timeKey);
  189. }
  190. onSend() {
  191. const { onSend, time = 60 } = this.props;
  192. if (onSend) {
  193. onSend();
  194. }
  195. this.setTime(time);
  196. }
  197. setTime(time) {
  198. this.setState({ loading: time });
  199. this.timeKey = setTimeout(() => {
  200. this.setTime(time - 1);
  201. }, 1000);
  202. }
  203. render() {
  204. const { loading } = this.state;
  205. const { className = '', onChange, placeholder, value } = this.props;
  206. return (
  207. <Input
  208. className={className}
  209. right={
  210. loading <= 0 ? (
  211. <span className="g-input-right-verification" onClick={() => this.onSend()}>
  212. 获取验证码
  213. </span>
  214. ) : (
  215. <span className="g-input-right-verification-loading">等待{loading}秒</span>
  216. )
  217. }
  218. value={value}
  219. placeholder={placeholder}
  220. onChange={data => onChange && onChange(data)}
  221. />
  222. );
  223. }
  224. }