account.jsx 12 KB

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