ForgetPassWord.vue 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271
  1. <template>
  2. <div>
  3. <!-- <GoBack>忘记密码</GoBack> -->
  4. <div class="forget_password_page">
  5. <!-- <div class="step_box">
  6. <div v-for="step in steps" :key="step.number" class="step_item"
  7. :class="{ 'process': step.number == currentStep, 'finish': step.number < currentStep }"
  8. >
  9. <div class="step_header">
  10. <div class="step_number">
  11. <i class="iconfont icon_xiala" v-if="step.number < currentStep" />
  12. <span v-else>{{ step.number }}</span>
  13. </div>
  14. <div class="step_line"></div>
  15. </div>
  16. <div class="step_label">{{ step.label }}</div>
  17. </div>
  18. </div> -->
  19. <div v-show="currentStep == 1" class="login_info_input">
  20. <el-form :model="validForm" :rules="validFormrules" ref="validFormRef">
  21. <el-form-item prop="cellPhoneNumber">
  22. <el-input v-model="validForm.cellPhoneNumber" placeholder="请输入手机号码" clearable prefix-icon="iconfont icon_shoujihao" />
  23. </el-form-item>
  24. <el-form-item prop="validateCode">
  25. <el-input v-model="validForm.validateCode" placeholder="请输入验证码" prefix-icon="iconfont icon_yanzhengma">
  26. <template slot="suffix">
  27. <span class="get_code" @click="GetCode">{{ codeText }}</span>
  28. </template>
  29. </el-input>
  30. </el-form-item>
  31. </el-form>
  32. </div>
  33. <div v-show="currentStep == 2" class="login_info_input">
  34. <el-form :model="setPassWordForm" :rules="setPassWordFormrules" ref="setPassWordFormRef">
  35. <el-form-item prop="newPassWord">
  36. <el-input v-model="setPassWordForm.newPassWord" type="password" placeholder="请输入新密码" clearable show-password prefix-icon="iconfont icon_mima" />
  37. </el-form-item>
  38. <el-form-item prop="validateNewPassWord">
  39. <el-input v-model="setPassWordForm.validateNewPassWord" type="password" placeholder="再次输入新密码" show-password clearable prefix-icon="iconfont icon_mima" />
  40. </el-form-item>
  41. </el-form>
  42. </div>
  43. <div class="login_info_button">
  44. <el-button :loading="loading" @click="NextStep()">{{currentStep == 2 ? '确认' : '下一步'}}</el-button>
  45. </div>
  46. </div>
  47. </div>
  48. </template>
  49. <script>
  50. // import GoBack from "./GoBack";
  51. export default {
  52. // components: { GoBack },
  53. data() {
  54. return {
  55. steps: [
  56. { number: 1, label: '验证信息' },
  57. { number: 2, label: '设置密码' },
  58. { number: 3, label: '修改完成' }
  59. ],
  60. currentStep: 1, // 1-验证短信, 2-重置密码
  61. validForm: {
  62. cellPhoneNumber: '',
  63. validateCode: ''
  64. },
  65. validFormrules: {
  66. cellPhoneNumber: [
  67. {required: true, message: '请输入手机号码', trigger: ['blur', 'change']}
  68. ],
  69. validateCode: [
  70. {required: true, message: '请输入验证码', trigger: ['blur', 'change']}
  71. ]
  72. },
  73. codeText: '获取验证码',
  74. count: 60, // 倒数秒数
  75. isCount: false, // 是否倒计时
  76. loading: false,
  77. setPassWordForm: {
  78. newPassWord: '',
  79. validateNewPassWord: '',
  80. },
  81. setPassWordFormrules: {
  82. newPassWord: [
  83. {required: true, message: '请输入密码', trigger: ['blur', 'change']},
  84. {min: 6, message: '长度最少为6位', trigger: 'blur'}
  85. ],
  86. validateNewPassWord: [
  87. {required: true, message: '请输入确认密码', trigger: ['blur', 'change']},
  88. {
  89. validator: (rule, value, callback) => {
  90. if (this.setPassWordForm.newPassWord && value !== this.setPassWordForm.newPassWord) {
  91. callback(new Error('两次输入的密码不一致'));
  92. } else {
  93. callback();
  94. }
  95. },
  96. trigger: 'blur'
  97. }
  98. ]
  99. }
  100. }
  101. },
  102. methods: {
  103. // 获取验证码
  104. GetCode() {
  105. if(!this.validForm.cellPhoneNumber) {
  106. this.$refs.validFormRef.validateField('cellPhoneNumber')
  107. return
  108. }
  109. if(this.isCount) return
  110. this.$api.user.getPhoneValidCode({
  111. phoneNumber: this.validForm.cellPhoneNumber
  112. }).then(res => {
  113. if(res.code == 200) {
  114. this.isCount = true
  115. this.codeText = `${this.count} 秒`
  116. const timer = setInterval(() => {
  117. this.count--;
  118. this.codeText = `${this.count} 秒`;
  119. if (this.count <= 0) {
  120. clearInterval(timer);
  121. this.isCount = false;
  122. this.count = 60;
  123. this.codeText = '重新获取'
  124. }
  125. }, 1000);
  126. }else {
  127. this.$message.error(res.msg)
  128. }
  129. })
  130. },
  131. NextStep() {
  132. if(this.currentStep == 1) {
  133. this.$refs.validFormRef.validate((valid) => {
  134. if (valid) {
  135. try {
  136. this.loading = true
  137. this.$api.user.validCode({
  138. phone: this.validForm.cellPhoneNumber,
  139. verificationCode: this.validForm.validateCode,
  140. }).then(res => {
  141. if(res.code === 200) {
  142. this.currentStep = 2;
  143. } else {
  144. this.$message.error(res.msg)
  145. }
  146. })
  147. this.loading = false
  148. } catch {
  149. this.loading = false
  150. }
  151. } else {
  152. return false;
  153. }
  154. });
  155. } else if(this.currentStep == 2) {
  156. this.$refs.setPassWordFormRef.validate(valid => {
  157. if(valid) {
  158. try {
  159. this.loading = true
  160. this.$api.user.setPassWord({
  161. phone: this.validForm.cellPhoneNumber,
  162. password: this.setPassWordForm.newPassWord
  163. }).then(res => {
  164. if(res.code == 200) {
  165. this.$message.success(res.msg)
  166. this.$emit('GoLogin')
  167. } else {
  168. this.$message.error(res.msg)
  169. }
  170. })
  171. this.loading = false
  172. } catch {
  173. this.loading = false
  174. }
  175. } else {
  176. return false;
  177. }
  178. });
  179. }
  180. }
  181. }
  182. }
  183. </script>
  184. <style lang="scss" scoped>
  185. .forget_password_page {
  186. display: flex;
  187. flex-direction: column;
  188. justify-content: space-between;
  189. .step_box {
  190. display: flex;
  191. width: 90%;
  192. margin: 0 auto;
  193. .step_item {
  194. &:not(:last-child) {
  195. flex: 1;
  196. }
  197. min-width: 0;
  198. .step_header {
  199. display: flex;
  200. align-items: center;
  201. margin-bottom: 20px;
  202. .step_number {
  203. width: 24px;
  204. height: 24px;
  205. line-height: 24px;
  206. margin: 0 10px;
  207. border: 2px solid #909399;
  208. text-align: center;
  209. border-radius: 50%;
  210. font-weight: 500;
  211. color: #909399;
  212. }
  213. .step_line {
  214. flex: 1;
  215. height: 2px;
  216. background: #DCDFE6;
  217. }
  218. }
  219. .step_label {
  220. color: #909399;
  221. font-weight: 500;
  222. }
  223. &.process {
  224. .step_header .step_number {
  225. background: #2E64FA;
  226. border-color: #2E64FA;
  227. color: #fff;
  228. }
  229. .step_line {
  230. background: #2E64FA;
  231. }
  232. .step_label {
  233. color: #2E64FA;
  234. }
  235. }
  236. &.finish {
  237. .step_header .step_number {
  238. background: #15BC83;
  239. border-color: #15BC83;
  240. color: #fff;
  241. }
  242. .step_line {
  243. background: #15BC83;
  244. }
  245. .step_label {
  246. color: #15BC83;
  247. }
  248. }
  249. }
  250. .step_item:last-of-type {
  251. .step_header .step_line {
  252. display: none;
  253. }
  254. }
  255. }
  256. .get_code {
  257. color: #2E64FA;
  258. cursor: pointer;
  259. }
  260. .login_info_button {
  261. margin-top: 19px;
  262. .el-button {
  263. width: 100%;
  264. }
  265. }
  266. }
  267. </style>