FindPassword.vue 17 KB

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