"use strict"; const common_vendor = require("../../common/vendor.js"); const common_assets = require("../../common/assets.js"); const _sfc_main = { data() { return { loginType: "phone", // 'phone' or 'account' phone: "", code: "", username: "", password: "", agreed: false, showRegisterPopup: false, regPhone: "", regCode: "", regUsername: "", regPassword: "", regCodeTimer: 0, // Countdown timer for registration code isSendingRegCode: false, // Flag to prevent multiple requests loginCodeTimer: 0, // Countdown timer for login code isSendingLoginCode: false // Flag to prevent multiple requests }; }, methods: { // 处理微信登录 async oneClickLogin() { common_vendor.index.__f__("log", "at pages/login/login.vue:92", "WeChat login button clicked"); common_vendor.index.getUserProfile({ desc: "用于完善用户资料", lang: "zh_CN", success: (userRes) => { common_vendor.index.__f__("log", "at pages/login/login.vue:98", userRes); common_vendor.index.showLoading({ title: "登录中...", mask: true }); common_vendor.index.login({ provider: "weixin", success: (wx_res) => { common_vendor.index.__f__("log", "at pages/login/login.vue:105", "uni.getUserProfile success:", userRes); common_vendor.index.__f__("log", "at pages/login/login.vue:106", "uni.login success, got code:", wx_res.code); common_vendor.index.request({ url: "http://localhost:3333/WeChart/login", method: "POST", data: { code: wx_res.code, weChatLoginDto: userRes.userInfo }, header: { "content-type": "application/json" }, success: (res) => { var _a; common_vendor.index.hideLoading(); if (res.statusCode === 200 && res.data) { common_vendor.index.__f__("log", "at pages/login/login.vue:119", "Backend login success:", res.data); common_vendor.index.showToast({ title: "登录成功", icon: "success" }); setTimeout(() => { common_vendor.index.switchTab({ url: "/pages/home/index" }); }, 1500); } else { common_vendor.index.__f__("error", "at pages/login/login.vue:125", "Backend login failed:", res); common_vendor.index.showToast({ title: ((_a = res.data) == null ? void 0 : _a.message) || "登录失败", icon: "none" }); } }, fail: (err) => { common_vendor.index.hideLoading(); common_vendor.index.__f__("error", "at pages/login/login.vue:131", "Backend request failed:", err); common_vendor.index.showToast({ title: "微信登录失败", icon: "none" }); } }); }, fail: (err) => { common_vendor.index.hideLoading(); common_vendor.index.__f__("error", "at pages/login/login.vue:138", "uni.login failed:", err); common_vendor.index.showToast({ title: "微信登录失败", icon: "none" }); } }); }, fail: (err) => { common_vendor.index.__f__("error", "at pages/login/login.vue:144", "uni.getUserProfile failed:", err); common_vendor.index.showToast({ title: "获取用户信息失败", icon: "none" }); } }); }, async sendCode() { var _a; if (this.isSendingLoginCode || this.loginCodeTimer > 0) { return; } if (!this.phone) { common_vendor.index.showToast({ title: "请输入手机号", icon: "none" }); return; } this.isSendingLoginCode = true; common_vendor.index.showLoading({ title: "发送中...", mask: true }); try { const res = await common_vendor.index.request({ url: "http://localhost:3333/user/code", method: "POST", data: { phone: this.phone }, header: { "content-type": "application/json" } }); common_vendor.index.hideLoading(); this.isSendingLoginCode = false; if (res.statusCode === 200 && res.data) { common_vendor.index.__f__("log", "at pages/login/login.vue:175", "Send login code success:", res.data); common_vendor.index.showToast({ title: "验证码已发送", icon: "success" }); this.loginCodeTimer = 60; const timerInterval = setInterval(() => { this.loginCodeTimer--; if (this.loginCodeTimer <= 0) { clearInterval(timerInterval); this.loginCodeTimer = 0; } }, 1e3); } else { common_vendor.index.__f__("error", "at pages/login/login.vue:189", "Send login code failed:", res); common_vendor.index.showToast({ title: ((_a = res.data) == null ? void 0 : _a.message) || "发送失败", icon: "none" }); } } catch (err) { common_vendor.index.hideLoading(); this.isSendingLoginCode = false; common_vendor.index.__f__("error", "at pages/login/login.vue:195", "Send login code request failed:", err); common_vendor.index.showToast({ title: "发送失败", icon: "none" }); } }, async doLogin() { var _a; if (!this.agreed) { common_vendor.index.showToast({ title: "请先同意协议", icon: "none" }); return; } if (!this.phone || !this.code) { common_vendor.index.showToast({ title: "请填写手机号和验证码", icon: "none" }); return; } common_vendor.index.showLoading({ title: "登录中...", mask: true }); try { const res = await common_vendor.index.request({ url: "http://localhost:3333/user/login", method: "POST", data: { phone: this.phone, code: this.code }, header: { "content-type": "application/json" } }); common_vendor.index.hideLoading(); if (res.statusCode === 200 && res.data) { common_vendor.index.__f__("log", "at pages/login/login.vue:225", "Login success:", res.data); common_vendor.index.showToast({ title: "登录成功", icon: "success" }); setTimeout(() => { common_vendor.index.switchTab({ url: "/pages/home/index" }); }, 1500); } else { common_vendor.index.__f__("error", "at pages/login/login.vue:232", "Login failed:", res.data); common_vendor.index.showToast({ title: ((_a = res.data) == null ? void 0 : _a.message) || "登录失败", icon: "error" }); } } catch (err) { common_vendor.index.hideLoading(); common_vendor.index.__f__("error", "at pages/login/login.vue:237", "Login request failed:", err); common_vendor.index.showToast({ title: "登录失败", icon: "none" }); } }, toRegister() { this.showRegisterPopup = true; }, toForgot() { common_vendor.index.showToast({ title: "跳转找回密码", icon: "none" }); }, openAgreement() { common_vendor.index.navigateTo({ url: "/pages/agreement/agreement" }); }, openPrivacy() { common_vendor.index.navigateTo({ url: "/pages/privacy/privacy" }); }, qqLogin() { common_vendor.index.showToast({ title: "QQ登录", icon: "none" }); }, async sendRegCode() { var _a; if (this.isSendingRegCode || this.regCodeTimer > 0) { return; } if (!this.regPhone) { common_vendor.index.showToast({ title: "请输入手机号", icon: "none" }); return; } this.isSendingRegCode = true; common_vendor.index.showLoading({ title: "发送中...", mask: true }); try { const res = await common_vendor.index.request({ url: "http://localhost:3333/user/code", method: "POST", data: { phone: this.regPhone // 发送手机号参数 }, header: { "content-type": "application/json" } }); common_vendor.index.hideLoading(); this.isSendingRegCode = false; if (res.statusCode === 200 && res.data) { common_vendor.index.__f__("log", "at pages/login/login.vue:288", "Send registration code success:", res.data); common_vendor.index.showToast({ title: "验证码已发送", icon: "success" }); this.regCodeTimer = 60; const timerInterval = setInterval(() => { this.regCodeTimer--; if (this.regCodeTimer <= 0) { clearInterval(timerInterval); this.regCodeTimer = 0; } }, 1e3); } else { common_vendor.index.__f__("error", "at pages/login/login.vue:302", "Send registration code failed:", res); common_vendor.index.showToast({ title: ((_a = res.data) == null ? void 0 : _a.message) || "发送失败", icon: "none" }); } } catch (err) { common_vendor.index.hideLoading(); this.isSendingRegCode = false; common_vendor.index.__f__("error", "at pages/login/login.vue:309", "Send registration code request failed:", err); common_vendor.index.showToast({ title: "发送失败", icon: "none" }); } }, async doRegister() { var _a; if (!this.regPhone || !this.regCode || !this.regUsername || !this.regPassword) { common_vendor.index.showToast({ title: "请填写所有注册信息", icon: "none" }); return; } common_vendor.index.showLoading({ title: "注册中...", mask: true }); try { const res = await common_vendor.index.request({ url: "http://localhost:3333/user/register", method: "POST", data: { phone: this.regPhone, code: this.regCode, username: this.regUsername, password: this.regPassword }, header: { "content-type": "application/json" } }); common_vendor.index.hideLoading(); if (res.statusCode === 200 && res.data) { common_vendor.index.__f__("log", "at pages/login/login.vue:337", "Registration success:", res.data); common_vendor.index.showToast({ title: "注册成功", icon: "success" }); this.regPhone = ""; this.regCode = ""; this.regUsername = ""; this.regPassword = ""; setTimeout(() => { this.showRegisterPopup = false; }, 1500); } else { common_vendor.index.__f__("error", "at pages/login/login.vue:349", "Registration failed:", res); common_vendor.index.showToast({ title: ((_a = res.data) == null ? void 0 : _a.message) || "注册失败", icon: "none" }); } } catch (err) { common_vendor.index.hideLoading(); common_vendor.index.__f__("error", "at pages/login/login.vue:354", "Registration request failed:", err); common_vendor.index.showToast({ title: "注册失败", icon: "none" }); } } } }; function _sfc_render(_ctx, _cache, $props, $setup, $data, $options) { return common_vendor.e({ a: common_vendor.n($data.loginType === "phone" ? "active" : ""), b: common_vendor.o(($event) => $data.loginType = "phone"), c: common_vendor.n($data.loginType === "account" ? "active" : ""), d: common_vendor.o(($event) => $data.loginType = "account"), e: $data.loginType === "phone" }, $data.loginType === "phone" ? { f: $data.phone, g: common_vendor.o(($event) => $data.phone = $event.detail.value), h: $data.code, i: common_vendor.o(($event) => $data.code = $event.detail.value), j: common_vendor.t($data.loginCodeTimer > 0 ? $data.loginCodeTimer + "s" : "获取验证码"), k: common_vendor.o((...args) => $options.sendCode && $options.sendCode(...args)), l: $data.loginCodeTimer > 0 || $data.isSendingLoginCode } : { m: $data.username, n: common_vendor.o(($event) => $data.username = $event.detail.value), o: $data.password, p: common_vendor.o(($event) => $data.password = $event.detail.value), q: common_vendor.o((...args) => $options.toRegister && $options.toRegister(...args)), r: common_vendor.o((...args) => $options.toForgot && $options.toForgot(...args)) }, { s: !$data.agreed, t: common_vendor.o((...args) => $options.doLogin && $options.doLogin(...args)), v: $data.agreed, w: common_vendor.o(($event) => $data.agreed = !$data.agreed), x: common_vendor.o((...args) => $options.openAgreement && $options.openAgreement(...args)), y: common_vendor.o((...args) => $options.openPrivacy && $options.openPrivacy(...args)), z: common_assets._imports_0$1, A: common_vendor.o((...args) => $options.oneClickLogin && $options.oneClickLogin(...args)), B: $data.showRegisterPopup }, $data.showRegisterPopup ? { C: $data.regPhone, D: common_vendor.o(($event) => $data.regPhone = $event.detail.value), E: $data.regCode, F: common_vendor.o(($event) => $data.regCode = $event.detail.value), G: common_vendor.t($data.regCodeTimer > 0 ? $data.regCodeTimer + "s" : "获取验证码"), H: common_vendor.o((...args) => $options.sendRegCode && $options.sendRegCode(...args)), I: $data.regCodeTimer > 0 || $data.isSendingRegCode, J: $data.regUsername, K: common_vendor.o(($event) => $data.regUsername = $event.detail.value), L: $data.regPassword, M: common_vendor.o(($event) => $data.regPassword = $event.detail.value), N: common_vendor.o((...args) => $options.doRegister && $options.doRegister(...args)), O: common_assets._imports_1, P: common_vendor.o(($event) => $data.showRegisterPopup = false) } : {}); } const MiniProgramPage = /* @__PURE__ */ common_vendor._export_sfc(_sfc_main, [["render", _sfc_render]]); wx.createPage(MiniProgramPage); //# sourceMappingURL=../../../.sourcemap/mp-weixin/pages/login/login.js.map