resetPassword.vue 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197
  1. <template>
  2. <div class="page-container login-container">
  3. <el-card class="login-card">
  4. <h2 class="login-card__title login-card__item">重置密码</h2>
  5. <el-input ref="password" v-model="password" type="password" placeholder="请输入密码, 长度为6-20个字符" maxlength="20" class="login-card__item"></el-input>
  6. <el-input ref="passwordConfirm" v-model="passwordConfirm" type="password" placeholder="请再次输入密码" maxlength="20" class="login-card__item"></el-input>
  7. <el-input ref="phone" v-model="phone" oninput="value=value.replace(/[^\d]/g,'')" placeholder="请输入手机号" minlength='11' maxlength='11' class="login-card__item"></el-input>
  8. <el-input ref="identifyCode" v-model="identifyCode" placeholder="请输入验证码" maxlength="6" class="login-card__short-item"></el-input>
  9. <el-button :disabled="disabled" @click="sendMessage" class="login-card__right-button">{{buttonText}}</el-button>
  10. <el-button type="primary" class="login-card__item" @click="resetPassword" :loading="loading" round>重置密码</el-button>
  11. <div class="login-card__bottom"><router-link to="/login" class="login-card__link">记得密码?前往登录</router-link></div>
  12. </el-card>
  13. <div class="clear"></div>
  14. <router-link to="/"><img src="/image/seec-logo--horizontal.png" class="login-card__logo"/></router-link>
  15. </div>
  16. </template>
  17. <script>
  18. export default {
  19. name: 'resetPassword',
  20. layout: 'blank',
  21. data () {
  22. return {
  23. phone: '',
  24. password: '',
  25. identifyCode: '',
  26. passwordConfirm: '',
  27. buttonText: '获取验证码',
  28. disabled: false,
  29. loading: false,
  30. email: ''
  31. }
  32. },
  33. methods: {
  34. sendMessage () {
  35. if (this.phone.length < 11) {
  36. if (this.phone.length === 0) {
  37. this.$message({
  38. showClose: true,
  39. message: '请填写手机号码',
  40. type: 'error'
  41. })
  42. } else {
  43. this.$message({
  44. showClose: true,
  45. message: '手机号码格式有误',
  46. type: 'error'
  47. })
  48. }
  49. this.$refs.phone.focus()
  50. return
  51. }
  52. this.disabled = true
  53. let time = 60
  54. const myScroll = setInterval(() => {
  55. time--
  56. if (time >= 0) {
  57. this.buttonText = time + 's后可重发'
  58. } else {
  59. this.buttonText = '获取验证码'
  60. this.disabled = false // 倒计时结束能够重新点击发送的按钮
  61. clearTimeout(myScroll) // 清除定时器
  62. time = 60 // 设置循环重新开始条件
  63. }
  64. }, 1000)
  65. this.$api.post('/user/sendMessage', { phone: this.phone }).then(res => {
  66. if (res.data.code === 0) {
  67. this.$message({
  68. showClose: true,
  69. message: '发送成功',
  70. type: 'success'
  71. })
  72. } else {
  73. this.$message({
  74. showClose: true,
  75. message: res.message,
  76. type: 'error'
  77. })
  78. }
  79. })
  80. },
  81. checkValid () {
  82. if (this.password.length < 6) {
  83. if (this.password.length === 0) {
  84. this.$message({
  85. showClose: true,
  86. message: '密码不得为空',
  87. type: 'error'
  88. })
  89. } else {
  90. this.$message({
  91. showClose: true,
  92. message: '密码长度不足',
  93. type: 'error'
  94. })
  95. }
  96. this.$refs.password.focus()
  97. return false
  98. }
  99. if (this.password.length > 20) {
  100. this.$message({
  101. showClose: true,
  102. message: '密码过长',
  103. type: 'error'
  104. })
  105. this.$refs.password.focus()
  106. return false
  107. }
  108. if (this.passwordConfirm !== this.password) {
  109. this.$message({
  110. showClose: true,
  111. message: '密码前后不一致',
  112. type: 'error'
  113. })
  114. this.$refs.passwordConfirm.focus()
  115. return false
  116. }
  117. if (this.phone.length !== 11) {
  118. if (this.phone.length === 0) {
  119. this.$message({
  120. showClose: true,
  121. message: '手机号码不得为空',
  122. type: 'error'
  123. })
  124. } else {
  125. this.$message({
  126. showClose: true,
  127. message: '手机号码格式有误',
  128. type: 'error'
  129. })
  130. }
  131. this.$refs.phone.focus()
  132. return false
  133. }
  134. if (this.identifyCode.length === 0) {
  135. this.$message({
  136. showClose: true,
  137. message: '未填写验证码',
  138. type: 'error'
  139. })
  140. this.$refs.identifyCode.focus()
  141. return false
  142. }
  143. if (this.identifyCode.length !== 6) {
  144. this.$message({
  145. showClose: true,
  146. message: '验证码长度错误',
  147. type: 'error'
  148. })
  149. this.$refs.identifyCode.focus()
  150. return false
  151. }
  152. return true
  153. },
  154. resetPassword () {
  155. this.loading = true
  156. const isValid = this.checkValid()
  157. if (!isValid) {
  158. return
  159. }
  160. this.$api.$post('/user/resetPassword', {
  161. phone: this.phone,
  162. password: this.password,
  163. identifyCode: this.identifyCode
  164. }).then((res) => {
  165. if (res.code === 0) {
  166. this.$message({
  167. showClose: true,
  168. message: '重置成功,前往登录',
  169. type: 'success'
  170. })
  171. this.$router.push('/login')
  172. } else {
  173. this.$message({
  174. showClose: true,
  175. message: res.message,
  176. type: 'error'
  177. })
  178. }
  179. }
  180. )
  181. this.loading = false
  182. }
  183. }
  184. }
  185. </script>
  186. <style lang="scss" scoped>
  187. @import '~/assets/css/login.scss';
  188. </style>