Register.vue 17 KB

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