"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 showForgotPopup: false, forgotPhone: "", forgotCode: "", newPassword: "", confirmPassword: "", forgotCodeTimer: 0, isSendingForgotCode: false }; }, methods: { // 处理微信登录 async oneClickLogin() { common_vendor.index.__f__("log", "at pages/login/login.vue:123", "WeChat login button clicked"); common_vendor.index.getUserProfile({ desc: "用于完善用户资料", lang: "zh_CN", success: (userRes) => { common_vendor.index.__f__("log", "at pages/login/login.vue:129", 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:136", "uni.getUserProfile success:", userRes); common_vendor.index.__f__("log", "at pages/login/login.vue:137", "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:150", "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:156", "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:162", "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:169", "uni.login failed:", err); common_vendor.index.showToast({ title: "微信登录失败", icon: "none" }); } }); }, fail: (err) => { common_vendor.index.__f__("error", "at pages/login/login.vue:175", "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:206", "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:220", "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:226", "Send login code request failed:", err); common_vendor.index.showToast({ title: "发送失败", icon: "none" }); } }, async doLogin() { var _a, _b; if (!this.agreed) { common_vendor.index.showToast({ title: "请先同意协议", icon: "none" }); return; } if (this.loginType === "phone") { 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.showToast({ title: "登录成功", icon: "success" }); setTimeout(() => { common_vendor.index.switchTab({ url: "/pages/home/index" }); }, 1500); } else { common_vendor.index.showToast({ title: ((_a = res.data) == null ? void 0 : _a.message) || "登录失败", icon: "error" }); } } catch (err) { common_vendor.index.hideLoading(); common_vendor.index.showToast({ title: "登录失败", icon: "none" }); } } else if (this.loginType === "account") { if (!this.username || !this.password) { 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/UserPassLogin", method: "POST", data: { username: this.username, password: this.password }, header: { "content-type": "application/json" } }); common_vendor.index.hideLoading(); if (res.statusCode === 200 && res.data && res.data.code === 200) { common_vendor.index.showToast({ title: "登录成功", icon: "success" }); setTimeout(() => { common_vendor.index.switchTab({ url: "/pages/home/index" }); }, 1500); } else { common_vendor.index.showToast({ title: ((_b = res.data) == null ? void 0 : _b.msg) || "登录失败", icon: "error" }); } } catch (err) { common_vendor.index.hideLoading(); common_vendor.index.showToast({ title: "登录失败", icon: "none" }); } } }, toRegister() { this.showRegisterPopup = true; }, toForgot() { this.showForgotPopup = true; }, 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:345", "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:359", "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:366", "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:394", "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:406", "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:411", "Registration request failed:", err); common_vendor.index.showToast({ title: "注册失败", icon: "none" }); } }, async sendForgotCode() { var _a; if (this.isSendingForgotCode || this.forgotCodeTimer > 0) { return; } if (!this.forgotPhone) { common_vendor.index.showToast({ title: "请输入手机号", icon: "none" }); return; } this.isSendingForgotCode = 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.forgotPhone }, header: { "content-type": "application/json" } }); common_vendor.index.hideLoading(); this.isSendingForgotCode = false; if (res.statusCode === 200 && res.data) { common_vendor.index.__f__("log", "at pages/login/login.vue:441", "Send forgot code success:", res.data); common_vendor.index.showToast({ title: "验证码已发送", icon: "success" }); this.forgotCodeTimer = 60; const timerInterval = setInterval(() => { this.forgotCodeTimer--; if (this.forgotCodeTimer <= 0) { clearInterval(timerInterval); this.forgotCodeTimer = 0; } }, 1e3); } else { common_vendor.index.__f__("error", "at pages/login/login.vue:453", "Send forgot 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.isSendingForgotCode = false; common_vendor.index.__f__("error", "at pages/login/login.vue:459", "Send forgot code request failed:", err); common_vendor.index.showToast({ title: "发送失败", icon: "none" }); } }, async doResetPassword() { var _a; if (!this.forgotPhone || !this.forgotCode || !this.newPassword || !this.confirmPassword) { common_vendor.index.showToast({ title: "请填写所有信息", icon: "none" }); return; } if (this.newPassword !== this.confirmPassword) { 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/ForgetPass", method: "POST", data: { phone: this.forgotPhone, code: this.forgotCode, newPassword: this.newPassword }, 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:491", "Reset password success:", res.data); common_vendor.index.showToast({ title: "密码修改成功", icon: "success" }); this.forgotPhone = ""; this.forgotCode = ""; this.newPassword = ""; this.confirmPassword = ""; setTimeout(() => { this.showForgotPopup = false; this.loginType = "account"; }, 1500); } else { common_vendor.index.__f__("error", "at pages/login/login.vue:507", "Reset password 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:512", "Reset password 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) } : {}, { Q: $data.showForgotPopup }, $data.showForgotPopup ? { R: $data.forgotPhone, S: common_vendor.o(($event) => $data.forgotPhone = $event.detail.value), T: $data.forgotCode, U: common_vendor.o(($event) => $data.forgotCode = $event.detail.value), V: common_vendor.t($data.forgotCodeTimer > 0 ? $data.forgotCodeTimer + "s" : "获取验证码"), W: common_vendor.o((...args) => $options.sendForgotCode && $options.sendForgotCode(...args)), X: $data.forgotCodeTimer > 0 || $data.isSendingForgotCode, Y: $data.newPassword, Z: common_vendor.o(($event) => $data.newPassword = $event.detail.value), aa: $data.confirmPassword, ab: common_vendor.o(($event) => $data.confirmPassword = $event.detail.value), ac: common_vendor.o((...args) => $options.doResetPassword && $options.doResetPassword(...args)), ad: common_assets._imports_1, ae: common_vendor.o(($event) => $data.showForgotPopup = 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