reset.vue 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. <style lang="less">
  2. @import "./reset.less";
  3. </style>
  4. <template>
  5. <div class="main">
  6. <navbar :user="user"></navbar>
  7. <div style="margin: 50px auto;">
  8. <el-form :model="regForm" status-icon :rules="rules" label-width="80px" ref="regForm" class="reset">
  9. <el-form-item label="手机号" prop="phone" class="pr">
  10. <div class="reset-phone">
  11. <el-input prop="phone" type="text" v-model="regForm.phone" placeholder="输入手机号码"></el-input>
  12. </div>
  13. <div class="reset-code">
  14. <el-button @click="getCode(regForm)" class="code-btn ml10" type="primary" v-if="show">发送</el-button>
  15. <el-button class="code-btn" type="primary" disabled v-else>{{count}} s</el-button>
  16. </div>
  17. </el-form-item>
  18. <el-form-item label="验证码" prop="code" class="pr">
  19. <el-input prop="code" v-model="regForm.code" placeholder="验证码" auto-complete="off"></el-input>
  20. </el-form-item>
  21. <el-form-item label="新密码" prop="pass" class="pr">
  22. <el-input prop="pass" type="password" v-model="regForm.pass" placeholder="登入密码" auto-complete="off"></el-input>
  23. </el-form-item>
  24. <el-form-item label="确认密码" prop="rePass" class="pr">
  25. <el-input prop="rePass" type="password" v-model="regForm.rePass" placeholder="确认密码" auto-complete="off"></el-input>
  26. </el-form-item>
  27. <el-form-item class="">
  28. <el-button type="primary" class="submit-btn" @click="submitForm('regForm')">重置密码</el-button>
  29. <el-button type="primary" class="submit-btn" @click="goLogin">回到登入</el-button>
  30. </el-form-item>
  31. </el-form>
  32. </div>
  33. </div>
  34. </template>
  35. <script>
  36. import {httpServer} from "@/components/httpServer/httpServer.js";
  37. import navbar from "@/components/nav/navbar.vue";
  38. import data from "@/components/data/data.js";
  39. export default {
  40. data() {
  41. return {
  42. show: true,
  43. count: 0,
  44. regForm: {
  45. phone: "",
  46. code: "",
  47. pass: "",
  48. rePass: ""
  49. },
  50. user:{},
  51. rules: data.rulesData( this.validatePass )
  52. };
  53. },
  54. components:{navbar},
  55. methods: {
  56. validatePass(rule, value, callback) {
  57. if (value == this.regForm.pass) {
  58. callback();
  59. } else {
  60. callback(new Error("两次密码不服"));
  61. }
  62. },
  63. goLogin(){
  64. this.$router.push('/');
  65. },
  66. getCode() {
  67. if (this.checkPhone() == false) {
  68. return false;
  69. } else {
  70. let {phone} = this.regForm;
  71. let type = "resetPass"
  72. const loadingInstance = this.$loading({
  73. lock: true,
  74. text: '短信发送中,请耐心等待...',
  75. spinner: 'el-icon-loading',
  76. background: 'rgba(240, 242, 245, 0.8)',
  77. customClass: 'gray-bg-loading' // 自定义类名,避免全局污染
  78. })
  79. httpServer("Auth.getCode", {phone,type}).then(res => {
  80. loadingInstance.close()
  81. if( res.code == 200){
  82. this.$message.successMsg("发送成功", 2);
  83. this.show = false
  84. const TIME_COUNT = 60; //更改倒计时时间
  85. if (!this.timer) {
  86. this.count = TIME_COUNT;
  87. this.timer = setInterval(() => {
  88. if (this.count > 0 && this.count <= TIME_COUNT) {
  89. this.count--;
  90. } else {
  91. this.show = true;
  92. clearInterval(this.timer); // 清除定时器
  93. this.timer = null;
  94. }
  95. }, 1000)
  96. }
  97. }
  98. })
  99. }
  100. },
  101. checkPhone() {
  102. let phone = this.regForm.phone;
  103. if (!/^1[3456789]\d{9}$/.test(phone)) {
  104. this.$message.error("请填写正确的手机号");
  105. return false;
  106. }
  107. return true
  108. },
  109. submitForm(formName) {
  110. let that = this;
  111. this.$refs[formName].validate(valid => {
  112. if (!valid) {
  113. return false;
  114. }
  115. let {phone,code,pass} = this.regForm;
  116. let param = {phone,code, pass: this.$md5(pass)};
  117. httpServer("Auth.resetPass", param).then(res => {
  118. if( res.code == 200){
  119. this.$msgbox({
  120. title: "重置密码",
  121. message: "密码重置成功",
  122. showCancelButton: false,
  123. confirmButtonText: "回到登入页面",
  124. beforeClose: (action, instance, done) => {
  125. that.$router.push('/');
  126. done();
  127. }
  128. })
  129. }
  130. });
  131. })
  132. }
  133. }
  134. };
  135. </script>