Login.js 37 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157
  1. import React, { Component } from 'react';
  2. import { connect } from 'dva';
  3. import { Form, Input, Modal, Button, message } from 'antd';
  4. import SlideVerify from "@/components/SlideVerify"
  5. import styles from './Login.less';
  6. import global from '@/global.less';
  7. import {
  8. failTip,
  9. sucTip,
  10. setLocalStorageTime,
  11. sldSvgIcon,
  12. saveSettleData,
  13. sldCheckMobile,
  14. getSldImgSet,sldComLanguage,mobile_reg
  15. } from '@/utils/utils';
  16. import router from 'umi/router';
  17. const FormItem = Form.Item;
  18. let admin_login_logo = require('../../assets/login/logo.png');
  19. let main_seller_center_logo_local = admin_login_logo;
  20. let com_img_login_info = getSldImgSet('com_img_login_info');
  21. if (com_img_login_info != '') {
  22. admin_login_logo = com_img_login_info.filter(item => item.name == 'main_seller_center_logo')[0].imageUrl || main_seller_center_logo_local;
  23. //admin_login_logo = com_img_info
  24. }
  25. const default_login_img = {
  26. admin_login_bg: require('../../assets/supplier_login_bg.jpg'),//登录背景
  27. admin_login_left_bg: require('../../assets/sld_login_left.png'),//登录左侧图片
  28. main_seller_center_logo: admin_login_logo,//登录页logo
  29. vendor_login_head_portrait: require('../../assets/touxiang@2x.png'),//操作成功头像
  30. };
  31. @connect(({ login, common }) => ({
  32. login, common,
  33. }))
  34. @Form.create()
  35. export default class LoginPage extends Component {
  36. state = {
  37. countDownC: false, //短信验证码防抖动
  38. countDownM: 0, //短信验证码倒计时
  39. type: 'account',
  40. autoLogin: true,
  41. login_img: {},
  42. error_info: '', //登录错误提示信息
  43. is_show_err: false,
  44. register_error_info: '', //注册错误提示信息
  45. is_show_registe_err: false,
  46. register_captcha: '',//注册——图形验证码
  47. login_captcha: '',//登录——图形验证码
  48. visibleModal: false,
  49. visibleModalVerify: false,// 人机验证弹窗
  50. modal_type: 'register', //区分忘记密码和立即注册弹框
  51. visibleModalSuccess: false,
  52. //商家账号
  53. is_show_account_err:false,
  54. account_error_info:'',
  55. //手机号
  56. is_show_phone_err:false,
  57. phone_error_info:'',
  58. //验证码
  59. is_show_code_err:false,
  60. code_error_info:'',
  61. //短信验证码
  62. is_show_phonecode_err:false,
  63. phonecode_error_info:'',
  64. //邮箱
  65. is_show_email_err:false,
  66. email_error_info:'',
  67. //密码
  68. is_show_pwd_err:false,
  69. pwd_error_info:'',
  70. //确认密码
  71. is_show_comfirepwd_err:false,
  72. comfirepwd_error_info:'',
  73. // 提交注册按钮加载loading
  74. loading: false,
  75. // 登录按钮加载loading
  76. loginLoading: false
  77. };
  78. register_captcha = '';//注册——图形验证码key
  79. login_captcha = '';//登录——图形验证码key
  80. componentDidMount() {
  81. localStorage.clear();
  82. this.get_init_img();
  83. this.get_login_out_img();
  84. this.getCaptcha('register_captcha');
  85. this.getCaptcha('login_captcha');
  86. }
  87. //获取图形验证码
  88. getCaptcha = (type) => {
  89. const { dispatch } = this.props;
  90. dispatch({
  91. type: 'common/get_captcha',
  92. callback: (res) => {
  93. if (res.state == 200) {
  94. this[type] = res.data.key;
  95. this.setState({ [type]: 'data:image/png;base64,' + res.data.captcha });
  96. }
  97. },
  98. });
  99. };
  100. //获取登陆页面logo
  101. get_login_out_img = () => {
  102. const { dispatch } = this.props;
  103. let { login_img } = this.state;
  104. dispatch({
  105. type: 'login/get_login_out_img',
  106. callback: (res) => {
  107. if (res.state == 200) {
  108. login_img = { ...default_login_img };
  109. res.data.map(item => {
  110. if (item.imageUrl) {
  111. login_img[item.name] = item.imageUrl;
  112. }
  113. });
  114. localStorage.setItem('com_img_login_info', JSON.stringify(res.data));
  115. this.setState({ login_img });
  116. }
  117. },
  118. });
  119. }
  120. //获取登陆后左上角logo
  121. get_init_img = () => {
  122. const { dispatch } = this.props;
  123. dispatch({
  124. type: 'login/get_login_img',
  125. callback: (res) => {
  126. if (res.state == 200) {
  127. localStorage.setItem('com_img_info', JSON.stringify(res.data));
  128. }
  129. },
  130. });
  131. };
  132. //登录操作
  133. handleSubmits = () => {
  134. this.props.form.validateFieldsAndScroll(['username', 'password', 'verifyCode'], (err, values) => {
  135. Object.keys(values).forEach(key => {
  136. values[key] = values[key] ? values[key].replace(/\s/g, '') : ''
  137. })
  138. const { username, password, verifyCode } = values;
  139. if (!username) {
  140. return failTip(`${sldComLanguage('用户名不能为空')}`);
  141. }
  142. if (!password) {
  143. return failTip(`${sldComLanguage('密码不能为空')}`);
  144. }
  145. if (!verifyCode) {
  146. return failTip(`${sldComLanguage('验证码不能为空')}`);
  147. }
  148. //用户登录
  149. values.verifyKey = this.login_captcha;
  150. const { dispatch } = this.props;
  151. this.setState({loginLoading: true})
  152. dispatch({
  153. type: 'login/login',
  154. payload: { ...values },
  155. callback: (res) => {
  156. if (res.state == 200 || res.state == 267) {
  157. localStorage.setItem('sld_token', res.data.access_token);
  158. localStorage.setItem('sld_refresh_token', res.data.refresh_token);
  159. {
  160. setLocalStorageTime();
  161. }
  162. localStorage.setItem('user_info', JSON.stringify({ user_name: res.data.vendorName, vendorMobile: res.data.vendorMobile }));
  163. if (res.state == 267) {
  164. //登录的时候初始化入驻状态
  165. if (res.data.applyState == 0) {
  166. //未入驻
  167. saveSettleData('state', '');
  168. saveSettleData('cur_step', 0);
  169. router.push('/apply/settled_protocol');
  170. } else {
  171. saveSettleData('cur_step', 3);
  172. router.push('/apply/open_up');
  173. }
  174. } else {
  175. // dispatch({ type: 'global/get_site_list_data' });
  176. }
  177. } else {
  178. failTip(res.msg);
  179. this.getCaptcha('login_captcha');
  180. }
  181. this.setState({loginLoading: false})
  182. },
  183. });
  184. });
  185. };
  186. showDefault = (type) => {
  187. let { login_img } = this.state;
  188. login_img[type] = default_login_img[type];
  189. this.setState({ login_img });
  190. };
  191. handleUserRegisterAgreement = () => {
  192. window.open("/agreement/detail?type=1", '_blank');
  193. };
  194. handleUserPrivacyPolicy = () => {
  195. window.open("/agreement/detail?type=2", '_blank');
  196. };
  197. handleForgetPwd = () => {
  198. this.setState({
  199. title: `${sldComLanguage('找回密码')}`,
  200. visibleModal: true,
  201. modal_type: 'forgetPwd',
  202. });
  203. };
  204. handleRegister = () => {
  205. this.getCaptcha('register_captcha');
  206. this.setState({
  207. title: `${sldComLanguage('商家账号注册')}`,
  208. visibleModal: true,
  209. modal_type: 'register',
  210. });
  211. };
  212. //验证商家账户
  213. checkVendorName = (rule, value, callback) => {
  214. if(!value){
  215. callback('');
  216. this.setState({
  217. is_show_account_err: true,
  218. account_error_info: `${sldComLanguage('请输入商家账号')}`,
  219. });
  220. return;
  221. }
  222. if (value.length < 6 || value.length > 20) {
  223. callback('');
  224. this.setState({
  225. is_show_account_err: true,
  226. account_error_info: `${sldComLanguage('请输入6-20位的字母、数字或符号的商家账号')}`,
  227. });
  228. }
  229. // else if (!(/^[0-9a-zA-Z]+$/.test(value))) {
  230. // callback('');
  231. // this.setState({
  232. // is_show_account_err: true,
  233. // account_error_info: `${sldComLanguage('商户账号只能输入数字和字母')}`,
  234. // });
  235. // } else if (/^[0-9]+$/.test(value)) {
  236. // callback('');
  237. // this.setState({
  238. // is_show_account_err: true,
  239. // account_error_info: `${sldComLanguage('商户账号不能输入纯数字')}`,
  240. // });
  241. // } else if (/^[a-zA-Z]+$/.test(value)) {
  242. // callback('');
  243. // this.setState({
  244. // is_show_account_err: true,
  245. // account_error_info: `${sldComLanguage('商户账号不能输入纯字母')}`,
  246. // });
  247. // }
  248. else {
  249. callback();
  250. this.setState({
  251. is_show_account_err: false,
  252. account_error_info: `${sldComLanguage('')}`,
  253. });
  254. }
  255. };
  256. //验证图像验证码
  257. checkImgCode = (rule, value, callback) => {
  258. if(!value){
  259. callback('');
  260. this.setState({
  261. is_show_code_err: true,
  262. code_error_info: `${sldComLanguage('请输入图形验证码')}`,
  263. });
  264. return;
  265. }
  266. if (value.length < 4 || !(/^[0-9a-zA-Z]+$/.test(value))) {
  267. callback('');
  268. this.setState({
  269. is_show_code_err: true,
  270. code_error_info: `${sldComLanguage('请输入正确的图形验证码')}`,
  271. });
  272. }else {
  273. callback();
  274. this.setState({
  275. is_show_code_err: false,
  276. code_error_info: `${sldComLanguage('')}`,
  277. });
  278. }
  279. };
  280. //验证短信验证码
  281. checkSmsCode = (rule, value, callback) => {
  282. if(!value){
  283. callback('');
  284. this.setState({
  285. is_show_phonecode_err: true,
  286. phonecode_error_info: `${sldComLanguage('请输入短信验证码')}`,
  287. });
  288. return;
  289. }
  290. if (value.length < 6 || !(/^[0-9]+$/.test(value))) {
  291. callback('');
  292. this.setState({
  293. is_show_phonecode_err: true,
  294. phonecode_error_info: `${sldComLanguage('请输入正确的短信验证码')}`,
  295. });
  296. }else {
  297. callback();
  298. this.setState({
  299. is_show_phonecode_err: false,
  300. phonecode_error_info: `${sldComLanguage('')}`,
  301. });
  302. }
  303. };
  304. checkPassword = (rule, value, callback) => {
  305. if(!value){
  306. callback('');
  307. this.setState({
  308. is_show_pwd_err: true,
  309. pwd_error_info: `${sldComLanguage('请输入密码')}`,
  310. });
  311. return
  312. }
  313. if (value.length < 6 || value.length > 20) {
  314. callback('');
  315. this.setState({
  316. is_show_pwd_err: true,
  317. pwd_error_info: `${sldComLanguage('请输入6~20位密码')}`,
  318. });
  319. } else {
  320. if (/[\u4E00-\u9FA5]/g.test(value)) {
  321. callback('');
  322. this.setState({
  323. is_show_pwd_err: true,
  324. pwd_error_info: `${sldComLanguage('密码不可以有中文')}`,
  325. });
  326. }else if(!(/^\S*$/.test(value))){
  327. callback('');
  328. this.setState({
  329. is_show_pwd_err: true,
  330. pwd_error_info: `${sldComLanguage('密码中不可以有空格')}`,
  331. });
  332. }
  333. callback();
  334. this.setState({
  335. is_show_pwd_err: false,
  336. pwd_error_info: `${sldComLanguage('')}`,
  337. });
  338. }
  339. };
  340. //确认密码
  341. checkConfirmPassword = (rule, value, callback) => {
  342. if(!value){
  343. callback('');
  344. this.setState({
  345. is_show_comfirepwd_err: true,
  346. comfirepwd_error_info: `${sldComLanguage('请输入确认密码')}`,
  347. });
  348. return
  349. }
  350. if (value.length < 6 || value.length > 20) {
  351. callback('');
  352. this.setState({
  353. is_show_comfirepwd_err: true,
  354. comfirepwd_error_info: `${sldComLanguage('请输入6~20位密码')}`,
  355. });
  356. } else {
  357. if (/[\u4E00-\u9FA5]/g.test(value)) {
  358. callback('');
  359. this.setState({
  360. is_show_comfirepwd_err: true,
  361. comfirepwd_error_info: `${sldComLanguage('密码不可以有中文')}`,
  362. });
  363. }else if(!(/^\S*$/.test(value))){
  364. callback('');
  365. this.setState({
  366. is_show_comfirepwd_err: true,
  367. comfirepwd_error_info: `${sldComLanguage('密码中不可以有空格')}`,
  368. });
  369. }
  370. callback();
  371. this.setState({
  372. is_show_comfirepwd_err: false,
  373. comfirepwd_error_info: `${sldComLanguage('')}`,
  374. });
  375. }
  376. };
  377. //验证手机
  378. checkMobile = (rule, value, callback) => {
  379. if(!value){
  380. callback('');
  381. this.setState({
  382. is_show_phone_err: true,
  383. phone_error_info: `${sldComLanguage('请输入手机号')}`,
  384. });
  385. return
  386. }
  387. if (!mobile_reg.test(value)) {
  388. callback('');
  389. this.setState({
  390. is_show_phone_err: true,
  391. phone_error_info: `${sldComLanguage('请输入正确的手机号')}`,
  392. });
  393. } else {
  394. callback();
  395. this.setState({
  396. is_show_phone_err: false,
  397. phone_error_info: `${sldComLanguage('')}`,
  398. });
  399. }
  400. };
  401. //验证邮箱
  402. checkEmail = (rule, value, callback) => {
  403. let emailReg = /^(\w-*\.*)+@(\w-?)+(\.\w{2,})+$/;
  404. if (value&&value.length != undefined && value.length > 100) {
  405. callback('');
  406. this.setState({
  407. is_show_email_err: true,
  408. email_error_info: `${sldComLanguage('最多输入100位')}`,
  409. });
  410. }
  411. if (value && !emailReg.test(value)) {
  412. callback('');
  413. this.setState({
  414. is_show_email_err: true,
  415. email_error_info: `${sldComLanguage('请输入正确的邮箱')}`,
  416. });
  417. } else {
  418. callback();
  419. this.setState({
  420. is_show_email_err: false,
  421. email_error_info: `${sldComLanguage('')}`,
  422. });
  423. }
  424. };
  425. handleCancelModal = () => {
  426. this.setState({
  427. visibleModal: false,
  428. visibleModalSuccess: false,
  429. //商家账号
  430. is_show_account_err:false,
  431. account_error_info:'',
  432. //手机号
  433. is_show_phone_err:false,
  434. phone_error_info:'',
  435. //验证码
  436. is_show_code_err:false,
  437. code_error_info:'',
  438. //短信验证码
  439. is_show_phonecode_err:false,
  440. phonecode_error_info:'',
  441. //邮箱
  442. is_show_email_err:false,
  443. email_error_info:'',
  444. //密码
  445. is_show_pwd_err:false,
  446. pwd_error_info:'',
  447. //确认密码
  448. is_show_comfirepwd_err:false,
  449. comfirepwd_error_info:'',
  450. });
  451. this.props.form.resetFields();
  452. };
  453. handleOkModal = (e) => {
  454. e.preventDefault();
  455. const { modal_type } = this.state;
  456. if (modal_type == 'register') {
  457. this.handleOkModalRegister();
  458. } else {
  459. this.handleOkModalForget();
  460. }
  461. };
  462. handleOkModalRegister = () => {
  463. let _this = this;
  464. this.props.form.validateFieldsAndScroll(['vendorName', 'vendorPassword', 'vendorEmail', 'confirmPassword', 'vendorMobile', 'verifyCode', 'smsCode'], (err, values) => {
  465. if(!err){
  466. if (values.vendorPassword != values.confirmPassword) {
  467. this.setState({
  468. pwd_error_info: `${sldComLanguage('密码和确认密码不一致')}`,
  469. is_show_pwd_err: true,
  470. });
  471. return false;
  472. }
  473. this.setState({loading: true});
  474. values.verifyKey = this.register_captcha;
  475. const { dispatch } = this.props;
  476. dispatch({
  477. type: 'login/register',
  478. payload: values,
  479. callback: res => {
  480. if (res.state == 267) {
  481. {
  482. setLocalStorageTime();
  483. }
  484. localStorage.setItem('sld_token', res.data.access_token);
  485. localStorage.setItem('sld_refresh_token', res.data.refresh_token);
  486. localStorage.setItem('user_info', JSON.stringify({ user_name: res.data.vendorName, vendorMobile: res.data.vendorMobile }));
  487. saveSettleData('state', '');
  488. saveSettleData('cur_step', 0);
  489. this.setState({
  490. visibleModal: false,
  491. visibleModalSuccess: true,
  492. }, () => {
  493. //自动请求更新验证码
  494. _this.getCaptcha('register_captcha');
  495. });
  496. } else {
  497. //自动请求更新验证码
  498. this.getCaptcha('register_captcha');
  499. if(res.msg == '短信验证码不正确'){
  500. this.setState({
  501. is_show_phonecode_err: true,
  502. phonecode_error_info: res.msg,
  503. });
  504. }
  505. else if(res.msg == '图形验证码不正确'){
  506. this.setState({
  507. is_show_code_err: true,
  508. code_error_info: res.msg,
  509. });
  510. }
  511. else if(res.msg == '该手机号已注册'){
  512. this.setState({
  513. is_show_phone_err: true,
  514. phone_error_info: res.msg,
  515. });
  516. }
  517. else{
  518. this.setState({
  519. is_show_registe_err: true,
  520. register_error_info: res.msg,
  521. });
  522. }
  523. }
  524. this.setState({loading: false});
  525. },
  526. });
  527. }else{
  528. }
  529. });
  530. };
  531. handleOkModalForget = () => {
  532. this.props.form.validateFieldsAndScroll(['vendorPassword', 'confirmPassword', 'vendorName', 'vendorMobile', 'smsCode'], (err, values) => {
  533. if (!err) {
  534. if (values.vendorPassword != values.confirmPassword) {
  535. this.setState({
  536. pwd_error_info: `${sldComLanguage('新密码和确认密码不一致')}`,
  537. is_show_pwd_err: true,
  538. });
  539. return false;
  540. }
  541. const { dispatch } = this.props;
  542. let param = {};
  543. param.mobile = values.vendorMobile;
  544. param.smsCode = values.smsCode;
  545. param.newPwd = values.vendorPassword;
  546. param.vendorName = values.vendorName;
  547. param.confirmPwd = values.confirmPassword;
  548. dispatch({
  549. type: 'login/lookForPwd',
  550. payload: param,
  551. callback: res => {
  552. if (res.state == 200) {
  553. sucTip(`${sldComLanguage('恭喜你!成功找回密码')}`);
  554. this.handleCancelModal();
  555. // this.setState({
  556. // visibleModal: false,
  557. // });
  558. } else {
  559. if(res.msg == '对不起,该手机号未注册' || res.msg == '该手机号已被其他账号绑定,请重新填写'){
  560. this.setState({
  561. is_show_phone_err: true,
  562. phone_error_info: res.msg,
  563. });
  564. }
  565. else if(res.msg == '短信验证码不正确'){
  566. this.setState({
  567. is_show_phonecode_err: true,
  568. phonecode_error_info: res.msg,
  569. });
  570. }
  571. else if(res.msg == '新密码与确认密码不一致'){
  572. this.setState({
  573. is_show_pwd_err: true,
  574. pwd_error_info: res.msg,
  575. });
  576. }
  577. else{
  578. this.setState({
  579. is_show_registe_err: true,
  580. register_error_info: res.msg,
  581. });
  582. }
  583. }
  584. },
  585. });
  586. }
  587. });
  588. };
  589. handleSuccessBtn = () => {
  590. let { modal_type } = this.state;
  591. if (modal_type == 'register') {
  592. //去入驻
  593. router.replace('/apply/settled_protocol');
  594. } else {
  595. //去登陆
  596. router.replace('/user/login');
  597. }
  598. };
  599. handleChangeRegister = () => {
  600. this.setState({
  601. is_show_registe_err: false,
  602. });
  603. };
  604. //倒计时
  605. countDown = () => {
  606. let { countDownM } = this.state;
  607. countDownM = countDownM - 1;
  608. let _this = this;
  609. this.setState({
  610. countDownM,
  611. }, () => {
  612. if (countDownM == 0) {
  613. clearTimeout(_this.timeOutId);
  614. } else {
  615. _this.timeOutId = setTimeout(() => _this.countDown(), 1000);
  616. }
  617. });
  618. };
  619. // 获取验证码操作
  620. getSmsCodeAction = ({ mobile, type, captcha }) => {
  621. const { dispatch } = this.props;
  622. let _this = this;
  623. let param = {};
  624. param.mobile = mobile;
  625. param.type = type;
  626. if (type == 'register') {
  627. param.verifyCode = captcha;
  628. param.verifyKey = this.register_captcha;
  629. }
  630. this.setState({
  631. countDownC: true,
  632. })
  633. dispatch({
  634. type: 'common/get_sms_code',
  635. payload: param,
  636. callback: (res) => {
  637. if (res.state == 200) {
  638. this.setState({
  639. countDownM: 60,
  640. countDownC: false,
  641. is_show_phonecode_err: false,
  642. phonecode_error_info: '',
  643. }, () => {
  644. _this.countDown();
  645. });
  646. } else {
  647. this.setState({
  648. countDownC: false,
  649. is_show_phonecode_err: true,
  650. phonecode_error_info: res.msg,
  651. });
  652. }
  653. },
  654. });
  655. }
  656. //获取短信验证码前的校验
  657. getSmsCode(type) {
  658. if (this.state.countDownC) {
  659. return;
  660. } else if (this.state.countDownM) {
  661. return;
  662. }
  663. let mobile = this.props.form.getFieldValue('vendorMobile');
  664. let captcha = this.props.form.getFieldValue('verifyCode');//图形验证码
  665. if (mobile == undefined || (mobile != undefined && !mobile)) {
  666. this.setState({
  667. is_show_phone_err: true,
  668. phone_error_info: `${sldComLanguage('请输入手机号')}`,
  669. });
  670. } else if (!sldCheckMobile(mobile)) {
  671. this.setState({
  672. is_show_phone_err: true,
  673. phone_error_info: `${sldComLanguage('请输入正确的手机号')}`,
  674. });
  675. } else if (type == 'register' && (captcha == undefined || (captcha != undefined && !captcha))) {
  676. this.setState({
  677. is_show_code_err: true,
  678. code_error_info: `${sldComLanguage('请输入图形验证码')}`,
  679. });
  680. } else if (type === 'retrieve'){
  681. this.setState({visibleModalVerify: true})
  682. } else {
  683. this.getSmsCodeAction({ mobile, type, captcha })
  684. }
  685. }
  686. handleCancelVeriyModal = () => {
  687. this.setState({visibleModalVerify: false})
  688. }
  689. verifySuccess = () => {
  690. message.success(sldComLanguage('验证成功'));
  691. const mobile = this.props.form.getFieldValue('vendorMobile');
  692. const captcha = this.props.form.getFieldValue('verifyCode');
  693. this.setState({visibleModalVerify: false})
  694. this.getSmsCodeAction({ mobile, type: 'retrieve', captcha })
  695. }
  696. render() {
  697. const { getFieldDecorator } = this.props.form;
  698. const {
  699. login_img,
  700. error_info,
  701. modal_type,
  702. is_show_err,
  703. register_captcha,
  704. login_captcha,
  705. title,
  706. visibleModal,
  707. visibleModalSuccess,
  708. visibleModalVerify,
  709. register_error_info,
  710. is_show_registe_err,
  711. countDownM,
  712. loading,
  713. loginLoading
  714. } = this.state;
  715. return (
  716. <div className={styles.full_screen}
  717. style={{
  718. backgroundImage: window.location.href.indexOf('user') != -1 ? 'url(' + login_img.admin_login_bg + ')' : 'none',
  719. backgroundSize: '100% 100%',
  720. }}>
  721. <div className={styles.left_bg}>
  722. <img
  723. src={login_img.admin_login_left_bg}
  724. onError={() => this.showDefault('admin_login_left_bg')}
  725. />
  726. <div className={`${global.flex_row_center_center} ${styles.login_logo_wrap}`}>
  727. <img className={styles.login_logo} src={default_login_img.main_seller_center_logo} onError={(e) => {
  728. e.target.onerror = null;
  729. e.target.src = main_seller_center_logo_local;
  730. }}/>
  731. </div>
  732. <p className={styles.main_title}>{sldComLanguage('欢迎登录商家中心后台')}</p>
  733. <div className={styles.right_bg}>
  734. <div className={styles.formlogin}>
  735. <Form layout="horizontal" onSubmit={(e) => this.handleSubmits(e)}>
  736. <FormItem
  737. >
  738. {getFieldDecorator('username')(
  739. <Input
  740. maxLength={50}
  741. placeholder={sldComLanguage('请输入用户名')}
  742. prefix={<img src={require('../../assets/sld_login_username.png')}
  743. style={{ color: 'rgba(0,0,0,.25)' }}/>}
  744. onPressEnter={() => this.props.form.submit(this.handleSubmits)}
  745. />,
  746. )}
  747. </FormItem>
  748. <FormItem
  749. style={{ marginTop: 20 }}
  750. >
  751. {getFieldDecorator('password')(
  752. <Input
  753. maxLength={50}
  754. type="password"
  755. placeholder={sldComLanguage('请输入密码')}
  756. prefix={<img src={require('../../assets/sld_login_pwd.png')}/>}
  757. onPressEnter={() => this.props.form.submit(this.handleSubmits)}
  758. />,
  759. )}
  760. </FormItem>
  761. <FormItem
  762. style={{ marginTop: 20 }}
  763. >
  764. {getFieldDecorator('verifyCode')(
  765. <Input
  766. maxLength={4}
  767. placeholder={sldComLanguage('请输入验证码')}
  768. prefix={<img src={require('../../assets/sld_login_img_code.png')}
  769. style={{ color: 'rgba(0,0,0,.25)' }}/>}
  770. suffix={<img src={login_captcha} onClick={() => this.getCaptcha('login_captcha')}
  771. className={styles.verification_code}/>}
  772. onPressEnter={() => this.props.form.submit(this.handleSubmits)}
  773. />,
  774. )}
  775. </FormItem>
  776. <div className={`${styles.sld_login_btn_wrap} ${global.flex_column_start_start}`}>
  777. <Button
  778. className={`${styles.sld_login_btn} ${global.flex_row_center_center}`}
  779. type="primary"
  780. loading={loginLoading}
  781. onClick={() => this.props.form.submit(this.handleSubmits)}
  782. >
  783. {sldComLanguage('立即登录')}
  784. </Button>
  785. {/* <div className={`${styles.sld_login_btn} ${global.flex_row_center_center}`}
  786. onClick={() => this.props.form.submit(this.handleSubmits)}>
  787. {sldComLanguage('立即登录')}
  788. </div> */}
  789. <div className={`${global.flex_row_between_center} ${styles.operate}`}>
  790. <a onClick={this.handleForgetPwd}>{sldComLanguage('忘记密码')}</a>
  791. <a onClick={this.handleRegister}>{sldComLanguage('立即注册')}</a>
  792. </div>
  793. <div className={`${global.flex_row_between_center} ${styles.operate}`}>
  794. <a onClick={this.handleUserRegisterAgreement}>{sldComLanguage('<<用户注册协议>>')}</a>
  795. <a onClick={this.handleUserPrivacyPolicy}>{sldComLanguage('<<隐私政策>>')}</a>
  796. </div>
  797. </div>
  798. </Form>
  799. </div>
  800. </div>
  801. </div>
  802. {/* 注册、找回密码弹出框 */}
  803. <Modal
  804. title={title}
  805. visible={visibleModal}
  806. maskClosable={false}
  807. footer={false}
  808. onCancel={this.handleCancelModal}
  809. width={450}
  810. >
  811. <div className={styles.form_login_modal}>
  812. <Form onSubmit={(e) => this.handleOkModal(e)}>
  813. {modal_type == 'register' &&
  814. <FormItem
  815. style={{ textAlign: 'center' }}
  816. >
  817. {getFieldDecorator('vendorName', {
  818. rules: [
  819. {
  820. validator: this.checkVendorName,
  821. },
  822. ],
  823. })(
  824. <Input
  825. maxLength={20}
  826. onChange={this.handleChangeRegister}
  827. placeholder={sldComLanguage('请输入6~20位字母组合')}
  828. allowClear
  829. prefix={<p className={styles.user_name}><span className={styles.must}>*</span>{sldComLanguage('商家账号')}</p>}
  830. />,
  831. )}
  832. </FormItem>
  833. }
  834. {modal_type == 'register' && this.state.is_show_account_err &&
  835. <div className={styles.register_error}>
  836. {sldSvgIcon('#ef1216', 16, 16, 'cuowutishi')}
  837. {this.state.account_error_info}~
  838. </div>
  839. }
  840. <FormItem
  841. style={{ marginTop: 20, textAlign: 'center' }}
  842. >
  843. {getFieldDecorator('vendorMobile', {
  844. rules: [
  845. {
  846. validator: this.checkMobile,
  847. },
  848. ],
  849. })(
  850. <Input
  851. maxLength={11}
  852. onChange={this.handleChangeRegister}
  853. placeholder={sldComLanguage('请输入手机号')}
  854. allowClear
  855. prefix={<p className={styles.user_name}><span className={styles.must}>*</span>{sldComLanguage('手机号')}</p>}
  856. />,
  857. )}
  858. </FormItem>
  859. {this.state.is_show_phone_err &&
  860. <div className={styles.register_error}>
  861. {sldSvgIcon('#ef1216', 16, 16, 'cuowutishi')}
  862. {this.state.phone_error_info}~
  863. </div>
  864. }
  865. {modal_type == 'register' &&
  866. <FormItem
  867. style={{ marginTop: 20, textAlign: 'center' }}
  868. >
  869. {getFieldDecorator('verifyCode', {
  870. rules: [
  871. {
  872. validator: this.checkImgCode,
  873. },
  874. ],
  875. })(
  876. <Input
  877. maxLength={4}
  878. onChange={this.handleChangeRegister}
  879. placeholder={sldComLanguage('请输入验证码')}
  880. prefix={<p className={styles.user_name}><span className={styles.must}>*</span>{sldComLanguage('验证码')}</p>}
  881. suffix={<img src={register_captcha} onClick={() => this.getCaptcha('register_captcha')}
  882. className={styles.verification_code}/>}
  883. />,
  884. )}
  885. </FormItem>
  886. }
  887. {this.state.is_show_code_err &&
  888. <div className={styles.register_error}>
  889. {sldSvgIcon('#ef1216', 16, 16, 'cuowutishi')}
  890. {this.state.code_error_info}~
  891. </div>
  892. }
  893. <FormItem
  894. style={{ marginTop: 20, textAlign: 'center' }}
  895. >
  896. {getFieldDecorator('smsCode', {
  897. rules: [
  898. {
  899. validator: this.checkSmsCode,
  900. },
  901. ],
  902. })(
  903. <Input
  904. maxLength={6}
  905. onChange={this.handleChangeRegister}
  906. placeholder={sldComLanguage('请输入短信验证码')}
  907. prefix={<p className={styles.user_name}><span className={styles.must}>*</span>{sldComLanguage('短信验证码')}</p>}
  908. suffix={<div className={`${global.flex_row_between_center} ${styles.get_sms_code_wrap}`}><span
  909. className={`${styles.v_split}`}>|</span><span className={styles.sms_code}
  910. style={{ opacity: countDownM > 0 ? 0.3 : 1 }}
  911. onClick={() => this.getSmsCode(modal_type == 'register' ? 'register' : 'retrieve')}>{countDownM ? `${countDownM}${sldComLanguage('s后重新获取')}` : `${sldComLanguage('获取验证码')}`}</span>
  912. </div>}
  913. />,
  914. )}
  915. </FormItem>
  916. {this.state.is_show_phonecode_err &&
  917. <div className={styles.register_error}>
  918. {sldSvgIcon('#ef1216', 16, 16, 'cuowutishi')}
  919. {this.state.phonecode_error_info}~
  920. </div>
  921. }
  922. {modal_type == 'register' &&
  923. <FormItem
  924. style={{ marginTop: 20, textAlign: 'center' }}
  925. >
  926. {getFieldDecorator('vendorEmail', {
  927. rules: [
  928. {
  929. validator: this.checkEmail,
  930. },
  931. ],
  932. })(
  933. <Input
  934. maxLength={100}
  935. onChange={this.handleChangeRegister}
  936. placeholder={sldComLanguage('请输入邮箱')}
  937. allowClear
  938. prefix={<p className={styles.user_name}>{sldComLanguage('邮箱')}</p>}
  939. />,
  940. )}
  941. </FormItem>
  942. }
  943. {this.state.is_show_email_err &&
  944. <div className={styles.register_error}>
  945. {sldSvgIcon('#ef1216', 16, 16, 'cuowutishi')}
  946. {this.state.email_error_info}~
  947. </div>
  948. }
  949. {modal_type == 'forgetPwd' &&
  950. <FormItem
  951. style={{marginTop: 20, textAlign: 'center'}}
  952. >
  953. {getFieldDecorator('vendorName', {
  954. rules: [
  955. {
  956. validator: this.checkVendorName,
  957. },
  958. ],
  959. })(
  960. <Input
  961. maxLength={20}
  962. onChange={this.handleChangeRegister}
  963. placeholder={sldComLanguage('请输入商家账号')}
  964. prefix={<p className={styles.user_name}><span
  965. className={styles.must}>*</span>{sldComLanguage('商家账号')}
  966. </p>}
  967. />,
  968. )}
  969. </FormItem>}
  970. {modal_type == 'forgetPwd' && this.state.is_show_account_err &&
  971. <div className={styles.register_error}>
  972. {sldSvgIcon('#ef1216', 16, 16, 'cuowutishi')}
  973. {this.state.account_error_info}~
  974. </div>
  975. }
  976. <FormItem
  977. style={{ marginTop: 20, textAlign: 'center' }}
  978. >
  979. {getFieldDecorator('vendorPassword', {
  980. rules: [
  981. {
  982. validator: this.checkPassword,
  983. },
  984. ],
  985. })(
  986. <Input.Password
  987. maxLength={20}
  988. onChange={this.handleChangeRegister}
  989. placeholder={sldComLanguage('请设置6~20位字母、数字或符号组成的密码')}
  990. prefix={<p className={styles.user_name}><span
  991. className={styles.must}>*</span>{modal_type == 'register' ? `${sldComLanguage('设置密码')}` : `${sldComLanguage('新密码')}`}</p>}
  992. />,
  993. )}
  994. </FormItem>
  995. {this.state.is_show_pwd_err &&
  996. <div className={styles.register_error}>
  997. {sldSvgIcon('#ef1216', 16, 16, 'cuowutishi')}
  998. {this.state.pwd_error_info}~
  999. </div>
  1000. }
  1001. <FormItem
  1002. style={{ marginTop: 20, textAlign: 'center' }}
  1003. >
  1004. {getFieldDecorator('confirmPassword', {
  1005. rules: [
  1006. {
  1007. required: true,
  1008. whitespace: true,
  1009. message: ' ',
  1010. },
  1011. {
  1012. validator: this.checkConfirmPassword,
  1013. },
  1014. ],
  1015. })(
  1016. <Input.Password
  1017. maxLength={20}
  1018. onChange={this.handleChangeRegister}
  1019. placeholder={sldComLanguage('请再次输入密码')}
  1020. prefix={<p className={styles.user_name}><span className={styles.must}>*</span>{sldComLanguage('确认密码')}</p>}
  1021. />,
  1022. )}
  1023. </FormItem>
  1024. {this.state.is_show_comfirepwd_err &&
  1025. <div className={styles.register_error}>
  1026. {sldSvgIcon('#ef1216', 16, 16, 'cuowutishi')}
  1027. {this.state.comfirepwd_error_info}~
  1028. </div>
  1029. }
  1030. {is_show_registe_err &&
  1031. <div className={styles.register_error}>
  1032. {sldSvgIcon('#ef1216', 16, 16, 'cuowutishi')}
  1033. {register_error_info}~
  1034. </div>
  1035. }
  1036. <FormItem
  1037. style={{ textAlign: 'center' }}
  1038. >
  1039. <Button loading={loading} htmlType="submit" size={'small'} style={{ height: 40 }}
  1040. className={styles.registerBtn}>{modal_type == 'register' ? `${sldComLanguage('提交注册')}` : `${sldComLanguage('找回密码')}`}</Button>
  1041. </FormItem>
  1042. </Form>
  1043. </div>
  1044. </Modal>
  1045. {/* 操作成功提示框 */}
  1046. <Modal
  1047. title={title}
  1048. visible={visibleModalSuccess}
  1049. footer={false}
  1050. onCancel={this.handleCancelModal}
  1051. width={450}
  1052. >
  1053. <div className={styles.success_wrap}>
  1054. <div className={`${styles.head_wrap} ${global.flex_column_center_center}`}>
  1055. {sldSvgIcon('rgba(255, 74, 33, .2)', 65, 65, 'ziyuan113')}
  1056. <p style={{ fontSize: 16, marginTop: 10 }}>{sldComLanguage('注册成功')}</p>
  1057. </div>
  1058. <Button className={styles.success_btn}
  1059. onClick={this.handleSuccessBtn}>{sldComLanguage('点击入驻')}</Button>
  1060. </div>
  1061. </Modal>
  1062. { /* 人机验证 */ }
  1063. <Modal
  1064. className={styles.verifyModal}
  1065. title={'滑动验证'}
  1066. visible={visibleModalVerify}
  1067. footer={false}
  1068. onCancel={this.handleCancelVeriyModal}
  1069. width={500}
  1070. >
  1071. {visibleModalVerify && <SlideVerify w={450} h={220} onSuccess={this.verifySuccess}/> }
  1072. </Modal>
  1073. </div>
  1074. );
  1075. }
  1076. }