Register.vue 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504
  1. <template>
  2. <div class="contentBo">
  3. <Banner></Banner>
  4. <div class="login-img fl"><img src="../../images/loginImg.png"/></div>
  5. <div :class="['reg-container', { 'box2': !flag}]">
  6. <!-- <h3>账号注册</h3> -->
  7. <div :class="['box', { 'box2': !flag}]">
  8. <!-- <div class="progress"> -->
  9. <!-- <span class="apply">申请注册</span> -->
  10. <!-- <span class="plan"></span> -->
  11. <!-- <span :class="['plan plan_bg1',{'plan_bg2':complete}]"></span> -->
  12. <!-- <span class="finished">完成</span> -->
  13. <!-- <span :class="['finished',{'apply':complete}]">完成</span> -->
  14. <!-- </div> -->
  15. <div v-if="flag" class="title-box clearfix"> <h3 class="login-title fl">注册</h3> <h4 class="num fr" @click="toLogin">登录</h4></div>
  16. <div v-else class="title-box clearfix">
  17. <!-- 不需要返回按钮 -->
  18. <!-- <span class="back-prev fl"><i class="el-icon-back" @click="backPrev"></i></span>-->
  19. <h3 class="login-title fl">其他信息</h3> <h4 class="num fr num2">2/2</h4>
  20. </div>
  21. <form>
  22. <div class="main" v-show="flag">
  23. <!-- <p>手机号</p> -->
  24. <div class="phoneBox">
  25. <input type="tel" :class="[{ 'error': phoneErrText}]" name="" v-model="phone" maxlength="11" @input="handleTelInput"
  26. @blur="checkPhone" placeholder="请输入手机号">
  27. <span class="tips" v-show="phoneErrText">{{phoneErrText}}</span>
  28. <input type="password" style="display: none"/>
  29. </div>
  30. <div class="phoneBox">
  31. <input type="password" :class="[{ 'error': pswErrText}]" name="" v-model="psw" minlength="6" maxlength="16" readonly onfocus="this.removeAttribute('readonly')" @blur="checkPsw" placeholder="请输入密码">
  32. <span class="tips" v-show="pswErrText">{{pswErrText}}</span>
  33. </div>
  34. <!-- <p>密码</p> -->
  35. <div class="yanzm">
  36. <!-- <p>图形验证码</p> -->
  37. <input type="text" :class="[{ 'error': imgErrText}]" name="" v-model="picCode" @blur="checkImgCode" maxlength="4">
  38. <img :src='"data:image/png;base64,"+imgCode' @click="refreshCode">
  39. <span class="tips" v-show="imgErrText">{{imgErrText}}</span>
  40. </div>
  41. <div class="yanzm">
  42. <!-- <p>短信验证码</p> -->
  43. <!-- <input type="text" name="" v-model="msgCode" maxlength="6" @input="handleMsg"> -->
  44. <input type="text" :class="[{ 'error': SMSErrText}]" name="" v-model="msgCode" maxlength="6" @blur="cheeckMsgCode">
  45. <div v-if="timerFlag" type="primary" class="getMsg disabled">{{ '再次发送('+ time+')'}}</div>
  46. <div v-else class="getMsg" @click="getMsgCode">获取验证码</div>
  47. <span class="tips" v-show="SMSErrText">{{SMSErrText}}</span>
  48. </div>
  49. <!-- <span class="tips" v-show="imgCodeErr">图形验证码错误</span> -->
  50. <!-- <span class="tips" v-show="imgCodeErr">{{codeErrText}}</span> -->
  51. <div class="next" v-if="changCor">下一步</div>
  52. <div class="next nextCor" @click="toNext" v-else>下一步</div>
  53. </div>
  54. <div class="main" v-show="!flag">
  55. <!-- <p>联系邮箱</p> -->
  56. <div class="phoneBox">
  57. <input type="email" :class="[{ 'error': emailErrText}]" name="" v-model="email" @blur="checkEmail" placeholder="请输入联系邮箱" autocomplete="off">
  58. <span class="tips" v-show="emailErrText">{{emailErrText}}</span>
  59. </div>
  60. <!-- <p>机构名称</p> -->
  61. <div class="phoneBox">
  62. <input type="text" :class="[{ 'error': agencyErrText}]" name="" v-model="agencyName" maxlength="20" placeholder="请输入机构名称" autocomplete="off">
  63. <span class="tips" v-show="agencyErrText">{{agencyErrText}}</span>
  64. </div>
  65. <div class="phoneBox">
  66. <input type="text" :class="[{ 'error': contactErrText}]" name="" v-model="contact" maxlength="10" @blur="handleContInput" placeholder="请输入联系人" autocomplete="off">
  67. <span class="tips" v-show="contactErrText">{{contactErrText}}</span>
  68. </div>
  69. <!-- <p>联系人</p> -->
  70. <!-- <input type="text" name="" v-model="contact" @input="handleContInput"> -->
  71. <div class="next" v-if="submitCor">立即注册</div>
  72. <div class="next nextCor" @click="submit" v-else>立即注册</div>
  73. </div>
  74. </form>
  75. </div>
  76. </div>
  77. <copy-right-info></copy-right-info>
  78. </div>
  79. </template>
  80. <script>
  81. import api from '@api/index.js';
  82. import utils from '@api/utils.js';
  83. import '@components/register/register.less';
  84. import Banner from '@components/common/Banner.vue';
  85. import md5 from 'js-md5'
  86. import copyRightInfo from '../common/CopyRightInfo.vue';
  87. export default {
  88. name: 'Register',
  89. data() {
  90. return {
  91. phone: '',
  92. contact: '',//联系人
  93. agencyName: '',
  94. email: '',
  95. psw: '',
  96. picCode: '',//用户输入
  97. msgCode: '',
  98. imgCode: '',//流
  99. imgId: '',
  100. flag: true,//切换下一页
  101. changCor: true,
  102. submitCor: true,
  103. imgCodeErr: false,
  104. time: 180,
  105. timer: null,//按钮倒计时
  106. timerFlag: false,//倒计时标识
  107. complete: false, //注册进度条
  108. picTimer: null,//图形验证码
  109. picTime: 600,
  110. msgCodeTimer:null,//短信验证码
  111. msgCodeTime:180,
  112. codeErrText:'',
  113. phoneRg:null,
  114. phoneErrText: '', // 手机号错误提示
  115. pswErrText: '', //密码错误提示
  116. imgErrText: '', //图像码错误信息
  117. SMSErrText: '', //短信验证码错误信息
  118. emailErrText:'', //邮箱错误信息提示
  119. agencyErrText: '', //机构错误信息提示
  120. contactErrText: '' //联系人错误信息提示
  121. }
  122. },
  123. created() {
  124. //localStorage.removeItem('token');
  125. this.getPicCode();
  126. },
  127. beforeDestroy() {
  128. window.clearInterval(this.picTimer);
  129. window.clearInterval(this.msgCodeTimer);
  130. },
  131. methods: {
  132. toLogin() {
  133. this.$router.push({
  134. path: '/'
  135. });
  136. },
  137. backPrev() {
  138. this.flag = true;
  139. },
  140. CalcuMD5(password){
  141. // password = password.toUpperCase();
  142. password = md5(password);
  143. return password;
  144. },
  145. handleTelInput(e) {//手机号输入验证
  146. this.phone = e.target.value.replace(/[^\d]/g, ''); //只能输入数字
  147. let firstNum = this.phone.substring(0, 1);//第一位1
  148. if (firstNum != 1) {
  149. this.phone = "";
  150. }
  151. },
  152. handleContInput() {//联系人--提示只能输入汉字
  153. // this.contact = e.target.value.replace(/[^\u4e00-\u9fa5]/g, '');
  154. const contactReg = new RegExp(/[^\u4e00-\u9fa5]$/g);
  155. // if (!contactReg.test(this.contact)) {
  156. if (contactReg.test(this.contact)) {
  157. /*this.$message({
  158. message: '联系人只能输入中文',
  159. type: 'warning',
  160. showClose: true,
  161. });*/
  162. this.imgCodeErr = true;
  163. this.contactErrText = "联系人只能输入中文";
  164. this.contact = '';
  165. }else{
  166. this.contactErrText = "";
  167. this.imgCodeErr = false;
  168. }
  169. },
  170. handleMsg(e) {//短信验证码输入验证
  171. this.phone = e.target.value.replace(/[^\d]{6}/g, '');
  172. },
  173. getPicCode() {//获取图形验证码
  174. api.getImgCode().then((res) => {
  175. if (+res.data.code == 0) {
  176. const imgCodeInfo = res.data.data;
  177. this.imgCode = imgCodeInfo.imgByte;
  178. this.imgId = imgCodeInfo.imgId;
  179. let that = this;
  180. this.picTimer = window.setInterval(() => {
  181. if ((that.picTime--) <= 0) {
  182. this.$message({
  183. message: '图形验证码已过期',
  184. type: 'warning',
  185. showClose: true,
  186. });
  187. that.picCode = '';
  188. that.picTime = 600//图形验证码过期时间10分钟;
  189. window.clearInterval(that.picTimer);
  190. this.picTimer = null
  191. that.getPicCode();//过期刷新验证码
  192. }
  193. }, 1000);
  194. } else {
  195. console.log(res.data.msg);
  196. }
  197. }).catch((err) => {
  198. console.log(err);
  199. })
  200. },
  201. refreshCode() {//刷新图形验证码
  202. window.clearInterval(this.picTimer);
  203. this.picTime = 600//图形验证码过期时间10分钟;
  204. this.getPicCode();
  205. },
  206. checkImgCode() {//验证图片验证码
  207. if (this.picCode) {
  208. const params = {
  209. imgCode: this.picCode,
  210. imgId: this.imgId
  211. }
  212. api.vertifyImgCode(params).then((res) => {
  213. if (+res.data.code != 0) {//验证失败
  214. this.imgCodeErr = true
  215. this.imgErrText = "图形验证码错误";
  216. } else {
  217. this.imgErrText = "";
  218. this.imgCodeErr = false
  219. }
  220. }).catch((err) => {
  221. console.log(err);
  222. })
  223. }
  224. },
  225. checkPhone() {//验证手机号
  226. // const reg = new RegExp(/^((13|14|15|16|17|18|19)\d{9})$/);
  227. const reg = utils.phoneReg;
  228. if(this.phone.trim()){
  229. if (!reg.test(this.phone)) {
  230. // this.$message({
  231. // message: '手机格式不正确',
  232. // type: 'warning',
  233. // showClose: true,
  234. // });
  235. this.phoneErrText = '手机号格式有误'
  236. this.phone = "";
  237. this.phoneRg = 1;
  238. }else{
  239. this.phoneRg = null;
  240. // this.imgCodeErr = false;
  241. api.checkTel(this.phone).then((res)=>{
  242. if(+res.data.code == 0){
  243. this.phoneErrText = ''
  244. }else{
  245. this.$message({
  246. message: res.data.msg,
  247. type: 'warning',
  248. showClose: true,
  249. });
  250. this.phone = "";
  251. }
  252. })
  253. }
  254. }else{
  255. /*this.$message({
  256. message: '手机号不能为空',
  257. type: 'warning',
  258. showClose: true,
  259. });*/
  260. }
  261. },
  262. getMsgCode() {//获取短信验证码
  263. //手机号、密码、联系人、图形验证码不为空且符合规则且图形验证码正确--shenq10.26
  264. if(!this.phone.trim() && !this.phoneRg){
  265. this.imgCodeErr = true;
  266. this.phoneErrText = "手机号不能为空";
  267. /*this.$message({
  268. message: '手机号不能为空',
  269. type: 'warning',
  270. showClose: true,
  271. });*/
  272. }else if(!this.psw.trim()){
  273. this.imgCodeErr = true;
  274. this.pswErrText = "密码不能为空";
  275. }else if(!this.picCode.trim()){
  276. this.imgCodeErr = true;
  277. this.imgErrText = "图形验证码不能为空";
  278. }else{//调请求接口
  279. this.imgCodeErr = false;
  280. const params = {
  281. imgCode: this.picCode,
  282. imgId: this.imgId,
  283. mobile: this.phone
  284. }
  285. api.getMobileCode(params).then((res) => {
  286. if (+res.data.code == 0) {
  287. this.$message({
  288. message: '验证码发送成功',
  289. type: 'success',
  290. showClose: true,
  291. });
  292. //按钮倒计时
  293. this.timerFlag = true;
  294. let that = this;
  295. this.timer = window.setInterval(() => {
  296. if ((that.time--) <= 0) {
  297. that.time = 180;
  298. that.timerFlag = false;
  299. window.clearInterval(that.timer);
  300. }
  301. }, 1000)
  302. //短信验证码180s过期时间
  303. this.msgCodeTimer = window.setInterval(() => {
  304. if ((that.msgCodeTime--) <= 0) {
  305. this.$message({
  306. message: '短信验证码已过期,请重新获取',
  307. type: 'warning',
  308. showClose: true,
  309. });
  310. that.msgCode = '';
  311. that.msgCodeTime = 180;
  312. window.clearInterval(that.msgCodeTimer);
  313. that.msgCodeTimer = null;
  314. }
  315. }, 1000);
  316. } else {
  317. console.log(res.data);
  318. this.$message({
  319. message: res.data.msg,
  320. type: 'warning',
  321. showClose: true,
  322. });
  323. // return
  324. }
  325. }).catch((err) => {
  326. console.log(err);
  327. })
  328. }
  329. },
  330. checkPsw() {//校验密码
  331. const pswlReg = utils.pswReg;
  332. const psw = this.psw;
  333. if (psw) {
  334. if (psw.trim().length < 6 || psw.trim().length > 16) {
  335. this.imgCodeErr = true;
  336. this.pswErrText = "密码长度为6-16位";
  337. this.psw = "";
  338. }
  339. else if (!pswlReg.test(psw)) {
  340. this.imgCodeErr = true;
  341. this.pswErrText = "密码过于简单";
  342. this.psw = "";
  343. }else{
  344. this.pswErrText = "";
  345. this.imgCodeErr = false;
  346. console.log()
  347. }
  348. }
  349. },
  350. cheeckMsgCode(){//验证短信验证码
  351. const params = {
  352. imgCode: this.picCode,
  353. imgId: this.imgId,
  354. mobile: this.phone,
  355. smsCode: this.msgCode
  356. }
  357. if(!this.msgCode.trim()) {
  358. return
  359. }
  360. api.vertifyMobileCode(params).then((res) => {
  361. // 验证成功,切换下一页
  362. if (+res.data.code == 0) {
  363. // this.flag = false;
  364. this.imgCodeErr = false;
  365. } else {
  366. // this.$message.error('短信验证码错误');
  367. this.imgCodeErr = true;
  368. this.SMSErrText = res.data.msg;
  369. this.msgCode = "";
  370. }
  371. }).catch((err) => {
  372. console.log(err);
  373. })
  374. },
  375. toNext() {
  376. clearInterval(this.msgCodeTimer);
  377. clearInterval(this.picTimer);
  378. this.picTimer = null;
  379. this.msgCodeTimer = null;
  380. this.flag = false;
  381. },
  382. checkEmail() {
  383. const emailReg = utils.emailReg;
  384. const email = this.email;
  385. if (email.trim()) {
  386. if (!emailReg.test(email)) {
  387. // this.$message({
  388. // message: '邮箱格式不正确',
  389. // type: 'warning'
  390. // });
  391. this.imgCodeErr = true;
  392. this.emailErrText = "邮箱格式不正确";
  393. this.email = "";
  394. }else{
  395. this.emailErrText = "";
  396. this.imgCodeErr = false;
  397. }
  398. }
  399. },
  400. submit() {
  401. //清除图形验证码定时器
  402. const mdPsw = this.CalcuMD5(this.psw);
  403. const params = {
  404. code: this.picCode,
  405. email: this.email,
  406. gmtCreate: '',
  407. gmtModified: '',
  408. id: 0,
  409. imgId: this.imgId,
  410. isDeleted: '',
  411. linkman: this.contact,
  412. modifier: '',
  413. organization: this.agencyName,
  414. // password: this.psw,
  415. password: mdPsw,
  416. username: this.phone
  417. }
  418. api.regidtry(params).then((res) => {
  419. if (+res.data.code == 0) {
  420. this.$message({
  421. message: '恭喜您,注册成功!',
  422. type: 'success',
  423. showClose: true,
  424. });
  425. //注册成功,跳转登录
  426. this.$router.push({path: '/'})
  427. } else {
  428. this.submitCor = true;//注册失败,按钮变灰
  429. this.$message({
  430. message: res.data.msg,
  431. type: 'warning',
  432. showClose: true,
  433. });
  434. }
  435. }).catch((err) => {
  436. console.log(err);
  437. })
  438. },
  439. },
  440. computed: {
  441. nextButton() {
  442. const {phone, psw, contact, picCode, msgCode, email, agencyName,imgCodeErr} = this;
  443. return {
  444. phone,
  445. psw,
  446. contact,
  447. picCode,
  448. msgCode,
  449. email,
  450. agencyName,
  451. imgCodeErr
  452. }
  453. }
  454. },
  455. watch: {
  456. nextButton: {
  457. handler: function (val) {//所有数据不为空,且手机格式正确、图形验证码正确
  458. if (val.phone.trim() && val.psw.trim() && val.picCode.trim() && val.msgCode.trim()) {
  459. this.changCor = false;
  460. } else {
  461. this.changCor = true;
  462. }
  463. if (val.email.trim() && val.agencyName.trim() && val.contact.trim()) {
  464. this.submitCor = false;
  465. this.complete = true;//完成
  466. } else {
  467. this.submitCor = true
  468. }
  469. },
  470. deep: true
  471. }
  472. },
  473. filters: {},
  474. components: {
  475. Banner,
  476. copyRightInfo
  477. },
  478. }
  479. </script>