setPhone.js 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. "use strict";
  2. const common_vendor = require("../../common/vendor.js");
  3. const store_user = require("../../store/user.js");
  4. const api_login = require("../../api/login.js");
  5. const utils_is = require("../../utils/is.js");
  6. const utils_utils = require("../../utils/utils.js");
  7. const _sfc_main = {
  8. __name: "setPhone",
  9. setup(__props) {
  10. store_user.useUserStore();
  11. const phone = common_vendor.ref("");
  12. const code = common_vendor.ref("");
  13. const countdown = common_vendor.ref(0);
  14. let countdownTimer = null;
  15. const canGetCode = common_vendor.computed(() => {
  16. return utils_is.isPhone(phone.value);
  17. });
  18. const canSubmit = common_vendor.computed(() => {
  19. return utils_is.isPhone(phone.value) && code.value.length >= 4;
  20. });
  21. const handleGetCode = async () => {
  22. if (countdown.value > 0 || !canGetCode.value) {
  23. return;
  24. }
  25. try {
  26. const res = await api_login.LoginSendCode({
  27. phone: phone.value
  28. });
  29. common_vendor.index.showToast({
  30. title: "验证码已发送",
  31. icon: "success"
  32. });
  33. countdown.value = 60;
  34. countdownTimer = setInterval(() => {
  35. countdown.value--;
  36. if (countdown.value <= 0) {
  37. clearInterval(countdownTimer);
  38. countdownTimer = null;
  39. }
  40. }, 1e3);
  41. } catch (error) {
  42. common_vendor.index.__f__("error", "at pages/personal/setPhone.vue:89", "发送验证码失败:", error);
  43. common_vendor.index.showToast({
  44. title: (error == null ? void 0 : error.msg) || "发送验证码失败",
  45. icon: "none"
  46. });
  47. }
  48. };
  49. const handleSubmit = async () => {
  50. if (!canSubmit.value) {
  51. return;
  52. }
  53. try {
  54. common_vendor.index.showToast({
  55. title: "修改成功",
  56. icon: "success"
  57. });
  58. setTimeout(() => {
  59. utils_utils.go(-1);
  60. }, 1500);
  61. } catch (error) {
  62. common_vendor.index.__f__("error", "at pages/personal/setPhone.vue:121", "修改手机号失败:", error);
  63. common_vendor.index.showToast({
  64. title: (error == null ? void 0 : error.msg) || "修改失败,请重试",
  65. icon: "none"
  66. });
  67. }
  68. };
  69. common_vendor.onUnmounted(() => {
  70. if (countdownTimer) {
  71. clearInterval(countdownTimer);
  72. }
  73. });
  74. return (_ctx, _cache) => {
  75. return {
  76. a: phone.value,
  77. b: common_vendor.o(($event) => phone.value = $event.detail.value),
  78. c: code.value,
  79. d: common_vendor.o(($event) => code.value = $event.detail.value),
  80. e: common_vendor.t(countdown.value > 0 ? `${countdown.value}秒` : "获取验证码"),
  81. f: countdown.value > 0 || !canGetCode.value ? 1 : "",
  82. g: common_vendor.o(handleGetCode),
  83. h: common_vendor.o(handleSubmit)
  84. };
  85. };
  86. }
  87. };
  88. const MiniProgramPage = /* @__PURE__ */ common_vendor._export_sfc(_sfc_main, [["__scopeId", "data-v-ad35e069"]]);
  89. wx.createPage(MiniProgramPage);
  90. //# sourceMappingURL=../../../.sourcemap/mp-weixin/pages/personal/setPhone.js.map