FindPassword.vue 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457
  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="" 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. });
  152. that.picCode = '';
  153. that.picTime = 600//图形验证码过期时间10分钟;
  154. window.clearInterval(that.picTimer);
  155. that.getPicCode();//过期刷新验证码
  156. }
  157. }, 1000);
  158. } else {
  159. this.$message({
  160. message: res.data.msg,
  161. type: 'warning'
  162. });
  163. }
  164. }).catch((err) => {
  165. console.log(err);
  166. })
  167. },
  168. refreshCode() {//刷新图形验证码
  169. window.clearInterval(this.picTimer);
  170. this.picTime = 600;//图形验证码过期时间10分钟;
  171. this.getPicCode();
  172. },
  173. checkImgCode() {//验证图片验证码
  174. if (this.picCode.trim()) {//定义参数
  175. const params = {
  176. imgCode: this.picCode,
  177. imgId: this.imgId
  178. }
  179. api.vertifyImgCode(params).then((res) => {
  180. if (+res.data.code != 0) {//验证失败
  181. this.imgCodeErr = true
  182. this.imgErrText = "图形验证码错误";
  183. } else {
  184. this.imgCodeErr = false
  185. /*window.clearInterval(this.picTimer);
  186. this.picTime = 600*/
  187. this.imgErrText = "";
  188. }
  189. }).catch((err) => {
  190. console.log(err);
  191. })
  192. }
  193. },
  194. checkPhone() {//验证手机号
  195. // const reg = new RegExp(/^((13|14|15|16|17|18|19)\d{9})$/);
  196. const reg = utils.phoneReg;
  197. if(this.phone.trim()){
  198. if (!reg.test(this.phone)) {
  199. /*this.$message({
  200. message: '手机格式不正确',
  201. type: 'warning'
  202. });*/
  203. this.imgCodeErr = true;
  204. this.phoneErrText = "手机格式有误";
  205. this.phone = "";
  206. }else{//验证手机号是否注册
  207. this.imgCodeErr = false;
  208. api.checkForgetTel(this.phone).then((res)=>{
  209. if(+res.data.code == 0){
  210. this.phoneErrText = ''
  211. }else{
  212. this.phoneErrText = ''
  213. this.$message({
  214. message: res.data.msg,
  215. type: 'warning'
  216. });
  217. this.phone = "";
  218. }
  219. })
  220. }
  221. }
  222. },
  223. getMsgCode() {//获取短信验证码
  224. if(!this.phone){
  225. /*this.$message({
  226. message: '手机号不能为空',
  227. type: 'warning'
  228. });*/
  229. this.imgCodeErr = true;
  230. this.phoneErrText = "手机号不能为空";
  231. }else if(!this.picCode){
  232. this.imgCodeErr = true
  233. this.imgErrText = "图形验证码不能为空";
  234. }else{
  235. //调请求接口
  236. if(!this.imgCodeErr){
  237. this.imgCodeErr = false;
  238. const params = {
  239. imgCode: this.picCode,
  240. imgId: this.imgId,
  241. mobile: this.phone
  242. }
  243. api.forgetPswGetMobileCode(params).then((res) => {
  244. if (+res.data.code == 0) {
  245. this.$message({
  246. message: '验证码发送成功',
  247. type: 'success'
  248. });
  249. //按钮倒计时
  250. this.timerFlag = true;
  251. let that = this;
  252. this.timer = window.setInterval(() => {
  253. if ((that.time--) <= 0) {
  254. that.time = 60;
  255. that.timerFlag = false;
  256. window.clearInterval(that.timer);
  257. }
  258. }, 1000)
  259. //短信验证码180s过期时间
  260. this.msgCodeTimer = window.setInterval(() => {
  261. if ((that.msgCodeTime--) <= 0) {
  262. this.$message({
  263. message: '短信验证码已过期,请重新获取',
  264. type: 'warning'
  265. });
  266. that.msgCode = '';
  267. that.msgCodeTime = 180;
  268. window.clearInterval(that.msgCodeTimer);
  269. }
  270. }, 1000);
  271. } else {
  272. console.log(res.data);
  273. this.$message({
  274. message: res.data.msg,
  275. type: 'warning'
  276. });
  277. // return
  278. }
  279. }).catch((err) => {
  280. console.log(err);
  281. })
  282. }
  283. }
  284. },
  285. checkPsw() {//校验密码
  286. // const pswlReg = /^(?![0-9]+$)(?![a-zA-Z]+$)/;
  287. const pswlReg = utils.pswReg;
  288. const psw = this.newPsw;
  289. console.log('assssssss', psw)
  290. if (psw) {
  291. if (psw.trim().length < 6 || psw.trim().length > 16) {
  292. this.imgCodeErr = true;
  293. this.newPswErrText = "密码长度为6-16位";
  294. this.psw = "";
  295. }
  296. else if (!pswlReg.test(psw)) {
  297. this.imgCodeErr = true;
  298. this.newPswErrText = "密码过于简单";
  299. this.psw = "";
  300. }else{
  301. this.newPswErrText = ''
  302. this.imgCodeErr = false;
  303. }
  304. }
  305. },
  306. checkMsgCode(){
  307. const params = {
  308. imgCode: this.picCode,
  309. imgId: this.imgId,
  310. mobile: this.phone,
  311. smsCode: this.msgCode
  312. }
  313. api.vertifyMobileCode(params).then((res) => {
  314. // 验证成功,切换下一页
  315. if (+res.data.code == 0) {
  316. // this.flag = 2;//切换下一页
  317. // this.newPawComplete = true;
  318. this.imgCodeErr = false;
  319. } else {
  320. // this.$message.error('短信验证码错误');
  321. this.imgCodeErr = true;
  322. this.SMSErrText = "短信验证码错误";
  323. this.msgCode = "";
  324. }
  325. }).catch((err) => {
  326. console.log(err);
  327. })
  328. },
  329. toNext(flag) {//点下一步验证短信验证码
  330. //掉验证接口
  331. if (flag == 1) {//验证第一页数据
  332. const params = {
  333. imgCode: this.picCode,
  334. imgId: this.imgId,
  335. mobile: this.phone,
  336. smsCode: this.msgCode
  337. }
  338. api.vertifyMobileCode(params).then((res) => {
  339. // 验证成功,切换下一页
  340. if (+res.data.code == 0) {
  341. this.flag = 2;//切换下一页
  342. this.newPawComplete = true;
  343. this.imgCodeErr = false;
  344. } else {
  345. // this.$message.error('短信验证码错误');
  346. this.imgCodeErr = true;
  347. this.SMSErrText = "短信验证码错误";
  348. this.msgCode = "";
  349. }
  350. }).catch((err) => {
  351. console.log(err);
  352. })
  353. }
  354. if (flag == 2) {//验证两次输入是否一致
  355. if (this.newPsw && this.newPswAgain) {
  356. if (this.newPsw.trim() == this.newPswAgain.trim()) {
  357. const mdPsw = this.CalcuMD5(this.newPsw);
  358. //调接口
  359. const params = {
  360. password: mdPsw,
  361. username: this.phone,
  362. diffPassword:this.modifiPsw
  363. }
  364. api.resetPsw(params).then((res) => {
  365. if (+res.data.code == 0) {
  366. this.flag = 3;
  367. this.complete = true;
  368. //修改成功清除定时器
  369. // window.clearInterval(this.picTimer);
  370. }else {
  371. this.$message({
  372. message: res.data.msg,
  373. type: 'warning'
  374. });
  375. this.newPsw = "";
  376. this.newPswAgain = "";
  377. }
  378. }).catch((err) => {
  379. console.log(err);
  380. })
  381. } else {
  382. this.$message({
  383. message: '两次密码不一致',
  384. type: 'warning'
  385. });
  386. }
  387. }
  388. }
  389. if (flag == 3) {
  390. this.$router.push({path: '/'})
  391. }
  392. },
  393. },
  394. computed: {
  395. nextButton() {
  396. const {phone, picCode, msgCode, flag, newPsw, newPswAgain,imgCodeErr} = this;
  397. return {
  398. phone,
  399. picCode,
  400. msgCode,
  401. flag,
  402. newPsw,
  403. newPswAgain,
  404. imgCodeErr
  405. }
  406. }
  407. },
  408. watch: {
  409. nextButton: {
  410. handler: function (val) {//所有数据不为空,且手机格式正确、图形验证码正确
  411. if (val.flag == 3) {
  412. this.nextText = "去登录";
  413. }
  414. if (val.phone.trim() && val.picCode.trim() && val.msgCode.trim() && !val.imgCodeErr && val.flag == 1) {
  415. // if (val.phone.trim() && val.picCode.trim() && val.msgCode.trim() && val.flag == 1) {
  416. this.changCor = false;
  417. } else {
  418. this.changCor = true;
  419. }
  420. if (val.newPsw.trim() && val.newPswAgain.trim()) {
  421. this.changCor = false;
  422. } else {
  423. // this.changCor = true;
  424. }
  425. },
  426. deep: true
  427. }
  428. },
  429. components: {
  430. Banner,
  431. copyRightInfo
  432. },
  433. }
  434. </script>