forgot.js 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. "use strict";
  2. const common_vendor = require("../../common/vendor.js");
  3. const _sfc_main = {
  4. data() {
  5. return {
  6. account: "",
  7. code: "",
  8. newPassword: "",
  9. showPassword: false,
  10. countdown: 0,
  11. timer: null
  12. };
  13. },
  14. computed: {
  15. canSubmit() {
  16. return this.account && this.code && this.newPassword;
  17. }
  18. },
  19. methods: {
  20. async getVerificationCode() {
  21. if (!this.account) {
  22. common_vendor.index.showToast({
  23. title: "请输入手机号或邮箱",
  24. icon: "none"
  25. });
  26. return;
  27. }
  28. try {
  29. await this.$api.auth.getResetCode({
  30. account: this.account
  31. });
  32. common_vendor.index.showToast({
  33. title: "验证码已发送",
  34. icon: "none"
  35. });
  36. this.startCountdown();
  37. } catch (error) {
  38. common_vendor.index.showToast({
  39. title: error.message || "获取验证码失败",
  40. icon: "none"
  41. });
  42. }
  43. },
  44. startCountdown() {
  45. this.countdown = 60;
  46. this.timer = setInterval(() => {
  47. if (this.countdown <= 0) {
  48. clearInterval(this.timer);
  49. return;
  50. }
  51. this.countdown--;
  52. }, 1e3);
  53. },
  54. async handleResetPassword() {
  55. try {
  56. await this.$api.auth.resetPassword({
  57. account: this.account,
  58. code: this.code,
  59. newPassword: this.newPassword
  60. });
  61. common_vendor.index.showToast({
  62. title: "密码重置成功",
  63. icon: "success"
  64. });
  65. this.goToLogin();
  66. } catch (error) {
  67. common_vendor.index.showToast({
  68. title: error.message || "重置密码失败",
  69. icon: "none"
  70. });
  71. }
  72. },
  73. goToLogin() {
  74. common_vendor.index.navigateTo({
  75. url: "/pages/auth/login"
  76. });
  77. }
  78. },
  79. beforeDestroy() {
  80. if (this.timer) {
  81. clearInterval(this.timer);
  82. }
  83. }
  84. };
  85. function _sfc_render(_ctx, _cache, $props, $setup, $data, $options) {
  86. return {
  87. a: $data.account,
  88. b: common_vendor.o(($event) => $data.account = $event.detail.value),
  89. c: $data.code,
  90. d: common_vendor.o(($event) => $data.code = $event.detail.value),
  91. e: common_vendor.t($data.countdown > 0 ? `${$data.countdown}s后重试` : "获取验证码"),
  92. f: $data.countdown > 0,
  93. g: common_vendor.o((...args) => $options.getVerificationCode && $options.getVerificationCode(...args)),
  94. h: $data.showPassword ? "text" : "password",
  95. i: $data.newPassword,
  96. j: common_vendor.o(($event) => $data.newPassword = $event.detail.value),
  97. k: common_vendor.t($data.showPassword ? "隐藏" : "显示"),
  98. l: common_vendor.o(($event) => $data.showPassword = !$data.showPassword),
  99. m: !$options.canSubmit,
  100. n: common_vendor.o((...args) => $options.handleResetPassword && $options.handleResetPassword(...args)),
  101. o: common_vendor.o((...args) => $options.goToLogin && $options.goToLogin(...args))
  102. };
  103. }
  104. const MiniProgramPage = /* @__PURE__ */ common_vendor._export_sfc(_sfc_main, [["render", _sfc_render], ["__scopeId", "data-v-2ee2a2a5"]]);
  105. wx.createPage(MiniProgramPage);
  106. //# sourceMappingURL=../../../.sourcemap/mp-weixin/pages/auth/forgot.js.map