RetrievePassword.vue 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202
  1. <template>
  2. <div class="register absolute">
  3. <div class="shading">
  4. <div class="pictrue acea-row row-center-wrapper">
  5. <img src="@assets/images/logo2.png" />
  6. </div>
  7. </div>
  8. <div class="whiteBg">
  9. <div class="title">找回密码</div>
  10. <div class="list">
  11. <div class="item">
  12. <div>
  13. <svg class="icon" aria-hidden="true">
  14. <use xlink:href="#icon-phone_"></use>
  15. </svg>
  16. <input type="text" placeholder="输入手机号码" v-model="account" />
  17. </div>
  18. </div>
  19. <div class="item">
  20. <div class="align-left">
  21. <svg class="icon" aria-hidden="true">
  22. <use xlink:href="#icon-code_1"></use>
  23. </svg>
  24. <input
  25. type="text"
  26. placeholder="填写验证码"
  27. class="codeIput"
  28. v-model="captcha"
  29. />
  30. <button
  31. class="code"
  32. :disabled="disabled"
  33. :class="disabled === true ? 'on' : ''"
  34. @click="code"
  35. >
  36. {{ text }}
  37. </button>
  38. </div>
  39. </div>
  40. <div class="item">
  41. <div>
  42. <svg class="icon" aria-hidden="true">
  43. <use xlink:href="#icon-code_"></use>
  44. </svg>
  45. <input
  46. type="password"
  47. placeholder="填写您的登录密码"
  48. v-model="password"
  49. />
  50. </div>
  51. </div>
  52. <div class="item" v-if="isShowCode">
  53. <div class="align-left">
  54. <svg class="icon" aria-hidden="true">
  55. <use xlink:href="#icon-code_"></use>
  56. </svg>
  57. <input
  58. type="text"
  59. placeholder="填写验证码"
  60. class="codeIput"
  61. v-model="codeVal"
  62. />
  63. <div class="code" @click="again"><img :src="codeUrl" /></div>
  64. </div>
  65. </div>
  66. </div>
  67. <div class="logon" @click="registerReset">确认</div>
  68. <div class="tip">
  69. <span @click="$router.push({ name: 'Login' })" class="font-color-red"
  70. >立即登录</span
  71. >
  72. </div>
  73. </div>
  74. <!-- <div class="bottom"></div> -->
  75. </div>
  76. </template>
  77. <script>
  78. import sendVerifyCode from "@mixins/SendVerifyCode";
  79. import { registerVerify, registerReset, getCodeApi } from "@api/user";
  80. import { validatorDefaultCatch } from "@utils/dialog";
  81. import attrs, { required, alpha_num, chs_phone } from "@utils/validate";
  82. import { VUE_APP_API_URL } from "@utils";
  83. export default {
  84. name: "RetrievePassword",
  85. data: function() {
  86. return {
  87. account: "",
  88. password: "",
  89. captcha: "",
  90. keyCode: "",
  91. codeUrl: "",
  92. codeVal: "",
  93. isShowCode: false
  94. };
  95. },
  96. mixins: [sendVerifyCode],
  97. mounted: function() {
  98. this.getCode();
  99. },
  100. methods: {
  101. again() {
  102. this.codeUrl =
  103. VUE_APP_API_URL + "/captcha?" + this.keyCode + Date.parse(new Date());
  104. console.log(this.codeUrl);
  105. },
  106. getCode() {
  107. getCodeApi()
  108. .then(res => {
  109. this.keyCode = res.data.key;
  110. })
  111. .catch(res => {
  112. this.$dialog.error(res.msg);
  113. });
  114. },
  115. async registerReset() {
  116. var that = this;
  117. const { account, captcha, password, codeVal } = that;
  118. try {
  119. await that
  120. .$validator({
  121. account: [
  122. required(required.message("手机号码")),
  123. chs_phone(chs_phone.message())
  124. ],
  125. captcha: [
  126. required(required.message("验证码")),
  127. alpha_num(alpha_num.message("验证码"))
  128. ],
  129. password: [
  130. required(required.message("密码")),
  131. attrs.range([6, 16], attrs.range.message("密码")),
  132. alpha_num(alpha_num.message("密码"))
  133. ],
  134. codeVal: this.isShowCode
  135. ? [
  136. required(required.message("验证码")),
  137. attrs.length(4, attrs.length.message("验证码")),
  138. alpha_num(alpha_num.message("验证码"))
  139. ]
  140. : []
  141. })
  142. .validate({ account, captcha, password, codeVal });
  143. } catch (e) {
  144. return validatorDefaultCatch(e);
  145. }
  146. registerReset({
  147. account: that.account,
  148. captcha: that.captcha,
  149. password: that.password,
  150. code: that.codeVal
  151. })
  152. .then(res => {
  153. that.$dialog.success(res.msg).then(() => {
  154. that.$router.push({ name: "Login" });
  155. });
  156. })
  157. .catch(res => {
  158. that.$dialog.error(res.msg);
  159. });
  160. },
  161. async code() {
  162. var that = this;
  163. const { account } = that;
  164. try {
  165. await that
  166. .$validator({
  167. account: [
  168. required(required.message("手机号码")),
  169. chs_phone(chs_phone.message())
  170. ]
  171. })
  172. .validate({ account });
  173. } catch (e) {
  174. return validatorDefaultCatch(e);
  175. }
  176. registerVerify({
  177. phone: that.account,
  178. key: that.keyCode,
  179. code: that.codeVal
  180. })
  181. .then(res => {
  182. that.$dialog.success(res.msg);
  183. that.sendCode();
  184. })
  185. .catch(res => {
  186. if (res.data.status === 402) {
  187. that.codeUrl = `${VUE_APP_API_URL}/sms_captcha?key=${that.keyCode}`;
  188. that.isShowCode = true;
  189. }
  190. that.$dialog.error(res.msg);
  191. });
  192. }
  193. }
  194. };
  195. </script>
  196. <style scoped>
  197. .code img {
  198. width: 100%;
  199. height: 100%;
  200. }
  201. </style>