changePhone.js 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. "use strict";
  2. const common_vendor = require("../../common/vendor.js");
  3. const _sfc_main = {
  4. data() {
  5. return {
  6. newPhone: "",
  7. code: "",
  8. countdown: 0,
  9. timer: null
  10. };
  11. },
  12. methods: {
  13. sendCode() {
  14. if (!/^1[3-9]\d{9}$/.test(this.newPhone)) {
  15. common_vendor.index.showToast({ title: "请输入正确手机号", icon: "none" });
  16. return;
  17. }
  18. common_vendor.index.request({
  19. url: "http://localhost:9527/api/sendCode",
  20. method: "POST",
  21. data: { phone: this.newPhone }
  22. });
  23. common_vendor.index.showToast({ title: "验证码已发送", icon: "success" });
  24. this.countdown = 60;
  25. this.timer = setInterval(() => {
  26. this.countdown--;
  27. if (this.countdown <= 0)
  28. clearInterval(this.timer);
  29. }, 1e3);
  30. },
  31. submit() {
  32. if (!/^1[3-9]\d{9}$/.test(this.newPhone)) {
  33. common_vendor.index.showToast({ title: "请输入正确手机号", icon: "none" });
  34. return;
  35. }
  36. if (!/^\d{6}$/.test(this.code)) {
  37. common_vendor.index.showToast({ title: "请输入6位验证码", icon: "none" });
  38. return;
  39. }
  40. common_vendor.index.request({
  41. url: "http://localhost:9527/api/updatePhone",
  42. method: "POST",
  43. data: {
  44. uid: common_vendor.index.getStorageSync("uid"),
  45. phone: this.newPhone,
  46. code: this.code
  47. },
  48. success: (res) => {
  49. if (res.statusCode === 200 && res.data.code === 200) {
  50. common_vendor.index.showToast({ title: "更换成功", icon: "success" });
  51. setTimeout(() => common_vendor.index.navigateBack(), 1e3);
  52. } else {
  53. common_vendor.index.showToast({ title: res.data.message || "更换失败", icon: "none" });
  54. }
  55. }
  56. });
  57. }
  58. },
  59. onUnload() {
  60. if (this.timer)
  61. clearInterval(this.timer);
  62. }
  63. };
  64. function _sfc_render(_ctx, _cache, $props, $setup, $data, $options) {
  65. return {
  66. a: $data.newPhone,
  67. b: common_vendor.o(($event) => $data.newPhone = $event.detail.value),
  68. c: $data.code,
  69. d: common_vendor.o(($event) => $data.code = $event.detail.value),
  70. e: common_vendor.t($data.countdown > 0 ? $data.countdown + "s" : "获取验证码"),
  71. f: $data.countdown > 0,
  72. g: common_vendor.o((...args) => $options.sendCode && $options.sendCode(...args)),
  73. h: common_vendor.o((...args) => $options.submit && $options.submit(...args))
  74. };
  75. }
  76. const MiniProgramPage = /* @__PURE__ */ common_vendor._export_sfc(_sfc_main, [["render", _sfc_render], ["__scopeId", "data-v-a44ae884"]]);
  77. wx.createPage(MiniProgramPage);
  78. //# sourceMappingURL=../../../.sourcemap/mp-weixin/pages/mine/changePhone.js.map