account.jsx 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289
  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. $.ajax({
  90. method: "get",
  91. dataType: "json",
  92. url: globalConfig.context + "/open/getMCode",
  93. data: {
  94. "mobile": form.getFieldValue('phone'),
  95. "sign": false,
  96. "verificationCode": form.getFieldValue('captcha')
  97. },
  98. success: function (data) {
  99. if (data.error && data.error.length) {
  100. message.warning(data.error[0].message);
  101. } else {
  102. message.success('验证码发送成功!');
  103. this.setState({
  104. getCodeButton: true
  105. });
  106. let interval = setInterval(function () {
  107. _me.setState({
  108. getCodeButton: false
  109. });
  110. clearInterval(interval);
  111. }, 60000);
  112. let i = 59;
  113. let countDown = setInterval(function () {
  114. _me.setState({
  115. mCodeText: '剩余' + i + '秒'
  116. });
  117. i--;
  118. if (i == 0) {
  119. clearInterval(countDown);
  120. _me.setState({
  121. mCodeText: '获取验证码'
  122. });
  123. };
  124. }, 1000);
  125. };
  126. }.bind(this)
  127. }).always(function () {
  128. this.setState({
  129. loading: false
  130. });
  131. }.bind(this));
  132. },
  133. checkConfirm(rule, value, callback) {
  134. const form = this.props.form;
  135. if (value && value.length < 6) {
  136. callback('密码长度必须大于或者等于6位!');
  137. };
  138. if (value && this.state.passwordDirty) {
  139. form.validateFields(['confirm'], { force: true });
  140. }
  141. callback();
  142. },
  143. reloadVCode() {
  144. this.setState({ vCodeUrl: globalConfig.context + '/open/getVCode?t=' + Math.random() })
  145. },
  146. closeModal() {
  147. this.setState({ showDesc: false });
  148. },
  149. render() {
  150. const { getFieldDecorator } = this.props.form;
  151. const formItemLayout = {
  152. labelCol: { span: 6 },
  153. wrapperCol: { span: 14 },
  154. };
  155. const tailFormItemLayout = {
  156. wrapperCol: {
  157. span: 14,
  158. offset: 6,
  159. },
  160. };
  161. return (
  162. <div className="account-content clearfix">
  163. <Spin spinning={this.state.loading} >
  164. <Form className="account-left" horizontal onSubmit={this.handleSubmit}>
  165. <FormItem
  166. {...formItemLayout}
  167. label="密码"
  168. extra={<span><Icon type="exclamation-circle" /> 建议字母、数字和符号两种以上组合,6-20个字符</span>}
  169. hasFeedback
  170. >
  171. {getFieldDecorator('password', {
  172. rules: [{
  173. required: true, message: '请输入密码!',
  174. }, {
  175. validator: this.checkConfirm,
  176. }],
  177. })(
  178. <Input type="password" onBlur={this.handlePasswordBlur} />
  179. )}
  180. </FormItem>
  181. <FormItem
  182. {...formItemLayout}
  183. label="确认密码"
  184. extra={<span><Icon type="exclamation-circle" /> 请再次输入密码</span>}
  185. hasFeedback
  186. >
  187. {getFieldDecorator('confirm', {
  188. rules: [{
  189. required: true, message: '请再次输入密码!',
  190. }, {
  191. validator: this.checkPassowrd,
  192. }],
  193. })(
  194. <Input type="password" />
  195. )}
  196. </FormItem>
  197. <FormItem
  198. {...formItemLayout}
  199. label="手机号码"
  200. extra={<span><Icon type="exclamation-circle" /> 请输入正确的手机号码</span>}
  201. hasFeedback
  202. >
  203. {getFieldDecorator('phone', {
  204. rules: [{ required: true, message: '请输入手机号码!' },
  205. {
  206. validator: this.checkPhone,
  207. }],
  208. })(
  209. <Input size="large" />
  210. )}
  211. </FormItem>
  212. <FormItem
  213. {...formItemLayout}
  214. label="验证码"
  215. extra={<span className="redFont"><Icon type="exclamation-circle" /> 看不清?点击图片更换验证码</span>}
  216. >
  217. <Row gutter={8}>
  218. <Col span={16}>
  219. {getFieldDecorator('captcha', {
  220. rules: [{ required: true, message: '请输入图片中的验证码' }],
  221. })(
  222. <Input size="large" />
  223. )}
  224. </Col>
  225. <Col span={8}>
  226. <div className="acc-getVcode">
  227. <img id="VCode" src={this.state.vCodeUrl} alt="点击刷新验证码" onClick={this.reloadVCode} />
  228. </div>
  229. </Col>
  230. </Row>
  231. </FormItem>
  232. <FormItem
  233. {...formItemLayout}
  234. label="手机验证码"
  235. extra={<span><Icon type="exclamation-circle" /> 点击获取后我们将发送验证码到上面手机号</span>}
  236. >
  237. <Row gutter={8}>
  238. <Col span={16}>
  239. {getFieldDecorator('phonecaptcha', {
  240. rules: [{ required: true, message: '请输入手机获取到的验证码' }],
  241. })(
  242. <Input size="large" />
  243. )}
  244. </Col>
  245. <Col span={8}>
  246. <Button size="large" onClick={this.getMCode} disabled={this.state.getCodeButton}>{this.state.mCodeText}</Button>
  247. </Col>
  248. </Row>
  249. </FormItem>
  250. <FormItem {...tailFormItemLayout} style={{ marginBottom: 8 }}>
  251. {getFieldDecorator('agreement', {
  252. valuePropName: 'checked',
  253. })(
  254. <Checkbox>同意 <a onClick={() => { this.setState({ showDesc: true }); }}> 阿凡提会员服务协议条款</a></Checkbox>
  255. )}
  256. </FormItem>
  257. <FormItem {...tailFormItemLayout}>
  258. <Button type="primary" htmlType="submit" size="large">提 交</Button>
  259. </FormItem>
  260. </Form>
  261. <div className="account-right">
  262. <p className="haveID title">已有账号 <Icon type="right" /> <a href="./login.html">直接登录</a></p>
  263. <div className="relateID" style={{ 'display': 'none' }}>
  264. <p className="title">关联账号</p>
  265. <p><Button className="relateqq"><img src={qq} alt="" /> QQ账号登录</Button></p>
  266. <p><Button className="relateweibo"><img src={weibo} alt="" />微博账号登录</Button></p>
  267. <p><Button className="relateweixin"><img src={weixin} alt="" />微信账号登录</Button></p>
  268. </div>
  269. <div className="about">
  270. <p className="title">关于阿凡提通行证</p>
  271. <p className="about-content">
  272. 阿凡提通行证推出的统一账号管理系统,注册阿凡提通行证的用户可以使用同一通行证账号及密码登录阿凡提网及其他关联互联网平台。
  273. </p>
  274. </div>
  275. </div>
  276. </Spin>
  277. <Modal showDesc={this.state.showDesc} closeModal={this.closeModal} />
  278. </div>
  279. );
  280. },
  281. }));
  282. export default LoginContent;