Keine Beschreibung

index.vue 8.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247
  1. <template>
  2. <div class="login-container">
  3. <div class="logo-wrapper">
  4. <div class="logo-img"></div>
  5. </div>
  6. <div class="form-wrapper">
  7. <div class="form-contain login-form">
  8. <h3 class="title">找回密码</h3>
  9. <div class="step-wrapper">
  10. <el-steps :active="stepVal" finish-status="success" align-center>
  11. <el-step title="输入手机号"></el-step>
  12. <el-step title="重置密码"></el-step>
  13. </el-steps>
  14. </div>
  15. <div class="step-contain">
  16. <el-form v-show="stepFisrt" :model="ruleForm" :rules="rules" ref="ruleForm" class="demo-ruleForm">
  17. <el-form-item prop="phoneNum">
  18. <el-input v-model="ruleForm.phoneNum" placeholder="请输入您的手机号码"></el-input>
  19. </el-form-item>
  20. <el-form-item prop="msgVC">
  21. <el-input v-model="ruleForm.msgVC" placeholder="请输入短信验证码" class="code-btn" style="width:100%">
  22. <el-button slot="append" type="primary" :disabled="phoneCodeBol" @click="clickMsgVcLogin">
  23. <span v-if="sendMsgDisabled">{{seconds + '秒后获取'}}</span>
  24. <span v-if="!sendMsgDisabled">获取验证码</span>
  25. </el-button>
  26. </el-input>
  27. </el-form-item>
  28. <el-form-item>
  29. <el-button class="log-btn" type="primary" :disabled="isDisabl" @click="nextStep('ruleForm')">下一步</el-button>
  30. </el-form-item>
  31. <el-form-item class="el-form-find">
  32. <el-button type="text" @click="goLogin">又想起来了</el-button>
  33. </el-form-item>
  34. </el-form>
  35. <el-form v-show="stepSecond" :model="ruleForm2" :rules="rules2" ref="ruleForm2" class="demo-ruleForm">
  36. <el-form-item prop="pass">
  37. <el-input type="password" v-model="ruleForm2.pass" placeholder="请设置您的新密码" auto-complete="off"></el-input>
  38. </el-form-item>
  39. <el-form-item prop="checkPass">
  40. <el-input type="password" v-model="ruleForm2.checkPass" placeholder="请再次输入密码确认" auto-complete="off"></el-input>
  41. </el-form-item>
  42. <el-form-item>
  43. <el-button class="log-btn" type="primary" :disabled="isDisabl" @click.native.prevent="resetPwd('ruleForm2')">重置密码</el-button>
  44. </el-form-item>
  45. </el-form>
  46. </div>
  47. </div>
  48. </div>
  49. </div>
  50. </template>
  51. <script>
  52. import { isReg, getResetMsgPhone, resetPwdByTel } from '@/api/login'
  53. import '@/styles/loginform.scss'
  54. export default {
  55. data() {
  56. var validPhone = (rule, value, callback) => {
  57. const reg = /^1[3|4|5|7|8][0-9]\d{8}$/
  58. if (!value) {
  59. callback(new Error('请输入你的手机号码'))
  60. } else if (!reg.test(value)) {
  61. callback(new Error('请输入正确的手机号码'))
  62. } else {
  63. callback()
  64. }
  65. }
  66. var validatePass = (rule, value, callback) => {
  67. if (value === '') {
  68. callback(new Error('请设置您的新密码'))
  69. } else if (value.length < 6 || value.length > 24) {
  70. callback(new Error('密码由6-24个字符组成,区分大小写'))
  71. } else {
  72. if (this.ruleForm2.checkPass !== '') {
  73. this.$refs.ruleForm2.validateField('checkPass')
  74. }
  75. callback()
  76. }
  77. }
  78. var validatePass2 = (rule, value, callback) => {
  79. if (value === '') {
  80. callback(new Error('请再次输入密码确认'))
  81. } else if (value !== this.ruleForm2.pass) {
  82. callback(new Error('两次输入密码不一致,请重新输入!'))
  83. } else {
  84. callback()
  85. }
  86. }
  87. return {
  88. phoneCodeBol: false,
  89. sendMsgDisabled: false,
  90. seconds: 60,
  91. platId: '',
  92. resetStepNum: '',
  93. resetCode: '',
  94. stepVal: 0,
  95. stepFisrt: true,
  96. stepSecond: false,
  97. isDisabl: false,
  98. ruleForm: {
  99. phoneNum: '',
  100. msgVC: ''
  101. },
  102. rules: {
  103. phoneNum: [
  104. { required: true, validator: validPhone, trigger: 'blur' }
  105. ],
  106. msgVC: [
  107. { required: true, message: '请输入短信验证码', trigger: 'blur' }
  108. ]
  109. },
  110. ruleForm2: {
  111. pass: '',
  112. checkPass: ''
  113. },
  114. rules2: {
  115. pass: [
  116. { validator: validatePass, trigger: 'blur' }
  117. ],
  118. checkPass: [
  119. { validator: validatePass2, trigger: 'blur' }
  120. ]
  121. }
  122. }
  123. },
  124. methods: {
  125. nextStep(formName) {
  126. this.$refs[formName].validate((valid) => {
  127. if (valid) {
  128. this.stepFisrt = false
  129. this.stepSecond = true
  130. this.stepVal = 1
  131. } else {
  132. return false
  133. }
  134. })
  135. },
  136. userRegisterOk() {
  137. const me = this
  138. const account = this.ruleForm.phoneNum
  139. isReg({ account }).then(res => {
  140. if (res.success) {
  141. if (res.data === true) {
  142. me.sendMsgDisabled = false
  143. me.phoneCodeBol = false
  144. me.$message({
  145. message: '该账号不存在,请检查后重试',
  146. type: 'warning'
  147. })
  148. } else {
  149. me.getResetMsgPhone()
  150. me.sendMsgDisabled = true
  151. me.phoneCodeBol = true
  152. const interval = window.setInterval(function() {
  153. if ((me.seconds--) <= 0) {
  154. me.seconds = 60
  155. me.sendMsgDisabled = false
  156. me.phoneCodeBol = false
  157. window.clearInterval(interval)
  158. }
  159. }, 1000)
  160. }
  161. }
  162. })
  163. },
  164. getResetMsgPhone() {
  165. const me = this
  166. const account = this.ruleForm.phoneNum
  167. const checkExists = true
  168. getResetMsgPhone({ account, checkExists }).then((res) => {
  169. if (!res.success) {
  170. if (res.code === -60000) {
  171. me.sendMsgDisabled = false
  172. me.phoneCodeBol = false
  173. me.$message({
  174. message: '该账号不存在,请检查后重试',
  175. type: 'warning'
  176. })
  177. } else {
  178. me.$message({
  179. message: res.detailMsg,
  180. type: 'warning'
  181. })
  182. }
  183. }
  184. })
  185. },
  186. clickMsgVcLogin() {
  187. const reg = /^1[3|4|5|7|8][0-9]\d{8}$/
  188. if (!this.ruleForm.phoneNum) {
  189. this.$message({
  190. message: '请输入你的手机号码',
  191. type: 'warning'
  192. })
  193. } else if (!reg.test(this.ruleForm.phoneNum)) {
  194. this.$message({
  195. message: '请输入正确的手机号码',
  196. type: 'warning'
  197. })
  198. } else {
  199. this.userRegisterOk()
  200. }
  201. },
  202. resetPwd(formName) {
  203. this.$refs[formName].validate((valid) => {
  204. if (valid) {
  205. resetPwdByTel(this.ruleForm2.pass, this.ruleForm.msgVC).then((res) => {
  206. if (res.success) {
  207. this.$alert('提示', '密码已重置,快去登录吧!', {
  208. confirmButtonText: '确定',
  209. type: 'success',
  210. center: true,
  211. callback: action => {
  212. if (action === 'confirm') {
  213. this.$router.push({ path: '/login' })
  214. }
  215. }
  216. })
  217. } else {
  218. this.$alert('提示', '密码重置失败!', {
  219. confirmButtonText: '重新找回密码',
  220. type: 'warning',
  221. center: true,
  222. callback: action => {
  223. if (action === 'confirm') {
  224. this.stepFisrt = true
  225. this.stepSecond = false
  226. this.stepVal = 0
  227. }
  228. }
  229. })
  230. return
  231. }
  232. })
  233. } else {
  234. return false
  235. }
  236. })
  237. },
  238. goLogin() {
  239. this.$router.push({ path: '/login' })
  240. }
  241. }
  242. }
  243. </script>