account.jsx 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296
  1. import React from 'react';
  2. import { Form, Input, Tooltip, Icon, Cascader, Select, Row, Col, Checkbox, Button, Spin, message } from 'antd';
  3. import "./account.less";
  4. import ajax from 'jquery/src/ajax/xhr.js'
  5. import $ from 'jquery/src/ajax';
  6. import Modal from './modal';
  7. import weixin from '../../../image/weixin-w.png';
  8. import qq from '../../../image/qq-w.png';
  9. import weibo from '../../../image/weibo-w.png';
  10. const FormItem = Form.Item;
  11. const Option = Select.Option;
  12. const LoginContent = Form.create()(React.createClass({
  13. getInitialState() {
  14. return {
  15. passwordDirty: false,
  16. getCodeButton: true,
  17. loading: false,
  18. mCodeText: '获取验证码',
  19. vCodeUrl: globalConfig.context + '/open/getVCode'
  20. };
  21. },
  22. handleSubmit(e) {
  23. e.preventDefault();
  24. this.props.form.validateFieldsAndScroll((err, values) => {
  25. if (!err) {
  26. this.setState({
  27. loading: true
  28. });
  29. $.ajax({
  30. method: "POST",
  31. dataType: "json",
  32. crossDomain: false,
  33. url: globalConfig.context + "/register",
  34. data: {
  35. "mobile": values.phone,
  36. "password": values.password,
  37. "type": 0,
  38. "mobileCode": values.phonecaptcha
  39. }
  40. }).done(function (data) {
  41. if (!data.error.length) {
  42. message.success('注册成功,5秒后跳转到登录页!');
  43. let interval = setInterval(function () {
  44. window.location.href = "./login.html"
  45. clearInterval(interval);
  46. }, 5000);
  47. } else {
  48. message.warning(data.error[0].message);
  49. this.reloadVCode();
  50. }
  51. }.bind(this)).always(function () {
  52. this.setState({
  53. loading: false
  54. });
  55. }.bind(this));
  56. }
  57. });
  58. },
  59. handlePasswordBlur(e) {
  60. const value = e.target.value;
  61. this.setState({ passwordDirty: this.state.passwordDirty || !!value });
  62. },
  63. checkPassowrd(rule, value, callback) {
  64. const form = this.props.form;
  65. if (value && value !== form.getFieldValue('password')) {
  66. callback('两次密码输入必须相同!');
  67. } else {
  68. callback();
  69. }
  70. },
  71. checkPhone(rule, value, callback) {
  72. const form = this.props.form;
  73. const _me = this;
  74. if (!(/^1[34578]\d{9}$/.test(value))) {
  75. callback('请输入正确的手机号码!');
  76. _me.setState({
  77. getCodeButton: true
  78. });
  79. } else {
  80. callback();
  81. _me.setState({
  82. getCodeButton: false
  83. });
  84. }
  85. },
  86. getMCode() {
  87. const _me = this;
  88. const form = this.props.form;
  89. if (!form.getFieldValue('captcha')) {
  90. message.warning('图形验证码不能为空!');
  91. return;
  92. };
  93. this.setState({
  94. loading: true
  95. });
  96. $.ajax({
  97. method: "get",
  98. dataType: "json",
  99. url: globalConfig.context + "/open/getMCode",
  100. data: {
  101. "mobile": form.getFieldValue('phone'),
  102. "sign": false,
  103. "verificationCode": form.getFieldValue('captcha')
  104. },
  105. success: function (data) {
  106. if (data.error && data.error.length) {
  107. message.warning(data.error[0].message);
  108. } else {
  109. message.success('验证码发送成功!');
  110. this.setState({
  111. getCodeButton: true
  112. });
  113. let interval = setInterval(function () {
  114. _me.setState({
  115. getCodeButton: false
  116. });
  117. clearInterval(interval);
  118. }, 60000);
  119. let i = 59;
  120. let countDown = setInterval(function () {
  121. _me.setState({
  122. mCodeText: '剩余' + i + '秒'
  123. });
  124. i--;
  125. if (i == 0) {
  126. clearInterval(countDown);
  127. _me.setState({
  128. mCodeText: '获取验证码'
  129. });
  130. };
  131. }, 1000);
  132. };
  133. }.bind(this)
  134. }).always(function () {
  135. this.setState({
  136. loading: false
  137. });
  138. }.bind(this));
  139. },
  140. checkConfirm(rule, value, callback) {
  141. const form = this.props.form;
  142. if (value && value.length < 6) {
  143. callback('密码长度必须大于或者等于6位!');
  144. };
  145. if (value && this.state.passwordDirty) {
  146. form.validateFields(['confirm'], { force: true });
  147. }
  148. callback();
  149. },
  150. reloadVCode() {
  151. this.setState({ vCodeUrl: globalConfig.context + '/open/getVCode?t=' + Math.random() })
  152. },
  153. closeModal() {
  154. this.setState({ showDesc: false });
  155. },
  156. render() {
  157. const { getFieldDecorator } = this.props.form;
  158. const formItemLayout = {
  159. labelCol: { span: 6 },
  160. wrapperCol: { span: 14 },
  161. };
  162. const tailFormItemLayout = {
  163. wrapperCol: {
  164. span: 14,
  165. offset: 6,
  166. },
  167. };
  168. return (
  169. <div className="account-content clearfix">
  170. <Spin spinning={this.state.loading} >
  171. <Form className="account-left" horizontal onSubmit={this.handleSubmit}>
  172. <FormItem
  173. {...formItemLayout}
  174. label="手机号码"
  175. extra={<span><Icon type="exclamation-circle" /> 请输入正确的手机号码</span>}
  176. hasFeedback
  177. >
  178. {getFieldDecorator('phone', {
  179. rules: [{ required: true, message: '请输入手机号码!' },
  180. {
  181. validator: this.checkPhone,
  182. }],
  183. })(
  184. <Input size="large" />
  185. )}
  186. </FormItem>
  187. <FormItem
  188. {...formItemLayout}
  189. label="密码"
  190. extra={<span><Icon type="exclamation-circle" /> 建议字母、数字和符号两种以上组合,6-20个字符</span>}
  191. hasFeedback
  192. >
  193. {getFieldDecorator('password', {
  194. rules: [{
  195. required: true, message: '请输入密码!',
  196. }, {
  197. validator: this.checkConfirm,
  198. }],
  199. })(
  200. <Input type="password" onBlur={this.handlePasswordBlur} />
  201. )}
  202. </FormItem>
  203. <FormItem
  204. {...formItemLayout}
  205. label="确认密码"
  206. extra={<span><Icon type="exclamation-circle" /> 请再次输入密码</span>}
  207. hasFeedback
  208. >
  209. {getFieldDecorator('confirm', {
  210. rules: [{
  211. required: true, message: '请再次输入密码!',
  212. }, {
  213. validator: this.checkPassowrd,
  214. }],
  215. })(
  216. <Input type="password" />
  217. )}
  218. </FormItem>
  219. <FormItem
  220. {...formItemLayout}
  221. label="验证码"
  222. extra={<span className="redFont"><Icon type="exclamation-circle" /> 看不清?点击图片更换验证码</span>}
  223. >
  224. <Row gutter={8}>
  225. <Col span={16}>
  226. {getFieldDecorator('captcha', {
  227. rules: [{ required: true, message: '请输入图片中的验证码' }],
  228. })(
  229. <Input size="large" />
  230. )}
  231. </Col>
  232. <Col span={8}>
  233. <div className="acc-getVcode">
  234. <img id="VCode" src={this.state.vCodeUrl} alt="点击刷新验证码" onClick={this.reloadVCode} />
  235. </div>
  236. </Col>
  237. </Row>
  238. </FormItem>
  239. <FormItem
  240. {...formItemLayout}
  241. label="手机验证码"
  242. extra={<span><Icon type="exclamation-circle" /> 点击获取后我们将发送验证码到上面手机号</span>}
  243. >
  244. <Row gutter={8}>
  245. <Col span={16}>
  246. {getFieldDecorator('phonecaptcha', {
  247. rules: [{ required: true, message: '请输入手机获取到的验证码' }],
  248. })(
  249. <Input size="large" />
  250. )}
  251. </Col>
  252. <Col span={8}>
  253. <Button size="large" onClick={this.getMCode} disabled={this.state.getCodeButton}>{this.state.mCodeText}</Button>
  254. </Col>
  255. </Row>
  256. </FormItem>
  257. <FormItem {...tailFormItemLayout} style={{ marginBottom: 8 }}>
  258. {getFieldDecorator('agreement', {
  259. valuePropName: 'checked',
  260. })(
  261. <Checkbox>同意 <a onClick={() => { this.setState({ showDesc: true }); }}> 技淘网会员服务协议条款</a></Checkbox>
  262. )}
  263. </FormItem>
  264. <FormItem {...tailFormItemLayout}>
  265. <Button disabled={!this.props.form.getFieldValue('agreement')} type="primary" htmlType="submit" size="large">提 交</Button>
  266. </FormItem>
  267. </Form>
  268. <div className="account-right">
  269. <p className="haveID title">已有账号 <Icon type="right" /> <a href="./login.html">直接登录</a></p>
  270. <div className="relateID" style={{ 'display': 'none' }}>
  271. <p className="title">关联账号</p>
  272. <p><Button className="relateqq"><img src={qq} alt="" /> QQ账号登录</Button></p>
  273. <p><Button className="relateweibo"><img src={weibo} alt="" />微博账号登录</Button></p>
  274. <p><Button className="relateweixin"><img src={weixin} alt="" />微信账号登录</Button></p>
  275. </div>
  276. <div className="about">
  277. <p className="title">关于阿凡提通行证</p>
  278. <p className="about-content">
  279. 阿凡提通行证推出的统一账号管理系统,注册阿凡提通行证的用户可以使用同一通行证账号及密码登录阿凡提网及其他关联互联网平台。
  280. </p>
  281. </div>
  282. </div>
  283. </Spin>
  284. <Modal showDesc={this.state.showDesc} closeModal={this.closeModal} />
  285. </div>
  286. );
  287. },
  288. }));
  289. export default LoginContent;