123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162 |
- "use strict";
- const common_vendor = require("../../common/vendor.js");
- const _sfc_main = {
- data() {
- return {
- loginType: "code",
- phone: "",
- verifyCode: "",
- account: "",
- password: "",
- showPassword: false,
- counting: false,
- countdown: 60,
- isAgreed: false,
- showServiceAgreement: false,
- showPrivacyPolicy: false
- };
- },
- computed: {
- isFormValid() {
- if (!this.isAgreed)
- return false;
- if (this.loginType === "code") {
- return this.phone.length === 11 && this.verifyCode.length === 6;
- } else {
- return this.account.length > 0 && this.password.length >= 6;
- }
- }
- },
- methods: {
- handleAgreementChange(e) {
- this.isAgreed = e.detail.value.length > 0;
- },
- async sendVerifyCode() {
- if (this.counting)
- return;
- if (this.phone.length !== 11) {
- common_vendor.index.showToast({ title: "请输入正确的手机号", icon: "none" });
- return;
- }
- try {
- const res = await common_vendor.index.request({
- url: "http://localhost:9527/api/getCode",
- method: "POST",
- data: {
- phone: this.phone
- },
- header: {
- "content-type": "application/json"
- }
- });
- common_vendor.index.__f__("log", "at pages/login/verify-code.vue:122", res.statusCode);
- if (res.statusCode === 200) {
- common_vendor.index.__f__("log", "at pages/login/verify-code.vue:124", "验证码接口返回:", res);
- common_vendor.index.showToast({
- title: "验证码已发送",
- icon: "success"
- });
- this.counting = true;
- this.countdown = 60;
- this.startCountdown();
- } else {
- throw new Error(res.data.msg || "获取验证码失败");
- }
- } catch (error) {
- common_vendor.index.__f__("error", "at pages/login/verify-code.vue:137", "获取验证码失败:", error);
- common_vendor.index.showToast({
- title: error.message || "获取验证码失败,请重试",
- icon: "none"
- });
- }
- },
- startCountdown() {
- const timer = setInterval(() => {
- if (this.countdown > 0) {
- this.countdown--;
- } else {
- this.counting = false;
- clearInterval(timer);
- }
- }, 1e3);
- },
- async handleLogin() {
- if (!this.isFormValid)
- return;
- if (!this.isAgreed) {
- common_vendor.index.showToast({ title: "请先同意服务协议和隐私政策", icon: "none" });
- return;
- }
- const res = await common_vendor.index.request({
- url: "http://localhost:9527/api/login",
- method: "POST",
- data: {
- phone: this.phone,
- password: this.password,
- code: this.verifyCode
- },
- header: {
- "content-type": "application/json"
- }
- });
- common_vendor.index.__f__("log", "at pages/login/verify-code.vue:173", res.data);
- if (res.data.code === 200) {
- common_vendor.index.setStorageSync("token", res.data.data.token);
- common_vendor.index.switchTab({
- url: "/pages/discover/index"
- // 替换为实际页面路径
- });
- } else {
- common_vendor.index.showToast({
- title: "登录失败",
- icon: "none"
- });
- }
- },
- closePopup() {
- this.showServiceAgreement = false;
- this.showPrivacyPolicy = false;
- },
- goToWechatLogin() {
- common_vendor.index.navigateTo({
- url: "/pages/login/index"
- });
- }
- }
- };
- function _sfc_render(_ctx, _cache, $props, $setup, $data, $options) {
- return common_vendor.e({
- a: common_vendor.n($data.loginType === "code" ? "active" : ""),
- b: common_vendor.o(($event) => $data.loginType = "code"),
- c: common_vendor.n($data.loginType === "password" ? "active" : ""),
- d: common_vendor.o(($event) => $data.loginType = "password"),
- e: $data.loginType === "code"
- }, $data.loginType === "code" ? {
- f: $data.phone,
- g: common_vendor.o(($event) => $data.phone = $event.detail.value),
- h: $data.verifyCode,
- i: common_vendor.o(($event) => $data.verifyCode = $event.detail.value),
- j: common_vendor.t($data.counting ? `${$data.countdown}s后重发` : "获取验证码"),
- k: $data.counting ? 1 : "",
- l: common_vendor.o((...args) => $options.sendVerifyCode && $options.sendVerifyCode(...args))
- } : {
- m: $data.account,
- n: common_vendor.o(($event) => $data.account = $event.detail.value),
- o: $data.showPassword ? "text" : "password",
- p: $data.password,
- q: common_vendor.o(($event) => $data.password = $event.detail.value),
- r: common_vendor.n($data.showPassword ? "icon-eye-open" : "icon-eye-close"),
- s: common_vendor.o(($event) => $data.showPassword = !$data.showPassword)
- }, {
- t: common_vendor.o((...args) => $options.goToWechatLogin && $options.goToWechatLogin(...args)),
- v: !$options.isFormValid,
- w: common_vendor.o((...args) => $options.handleLogin && $options.handleLogin(...args)),
- x: $data.isAgreed,
- y: common_vendor.o(($event) => $data.showServiceAgreement = true),
- z: common_vendor.o(($event) => $data.showPrivacyPolicy = true),
- A: common_vendor.o((...args) => $options.handleAgreementChange && $options.handleAgreementChange(...args))
- });
- }
- const MiniProgramPage = /* @__PURE__ */ common_vendor._export_sfc(_sfc_main, [["render", _sfc_render]]);
- wx.createPage(MiniProgramPage);
- //# sourceMappingURL=../../../.sourcemap/mp-weixin/pages/login/verify-code.js.map
|