"use strict"; const common_vendor = require("../../common/vendor.js"); const api_user = require("../../api/user.js"); const utils_userCache = require("../../utils/userCache.js"); if (!Array) { const _easycom_uni_easyinput2 = common_vendor.resolveComponent("uni-easyinput"); _easycom_uni_easyinput2(); } const _easycom_uni_easyinput = () => "../../uni_modules/uni-easyinput/components/uni-easyinput/uni-easyinput.js"; if (!Math) { _easycom_uni_easyinput(); } const _sfc_main = { __name: "login", setup(__props) { const phoneNumber = common_vendor.ref(""); const verifyCode = common_vendor.ref(""); const countdown = common_vendor.ref(0); const isLoading = common_vendor.ref(false); let timer = null; const showUserAgreementPopup = common_vendor.ref(false); const showPrivacyPolicyPopup = common_vendor.ref(false); const getVerifyCode = async () => { if (countdown.value > 0) return; if (!phoneNumber.value || phoneNumber.value.length !== 11) { common_vendor.index.showToast({ title: "请输入正确的手机号", icon: "none" }); return; } try { const res = await api_user.sendVerifyCode(phoneNumber.value); common_vendor.index.__f__("log", "at pages/login/login.vue:298", "验证码发送成功:", res); countdown.value = 60; timer = setInterval(() => { countdown.value--; if (countdown.value <= 0) { clearInterval(timer); } }, 1e3); common_vendor.index.showToast({ title: "验证码已发送", icon: "success" }); } catch (error) { common_vendor.index.__f__("error", "at pages/login/login.vue:314", "发送验证码失败:", error); } }; const handleLogin = async () => { if (isLoading.value) return; if (!phoneNumber.value || phoneNumber.value.length !== 11) { common_vendor.index.showToast({ title: "请输入正确的手机号", icon: "none" }); return; } if (!verifyCode.value || verifyCode.value.length !== 6) { common_vendor.index.showToast({ title: "请输入验证码", icon: "none" }); return; } isLoading.value = true; try { const res = await api_user.loginByPhone(phoneNumber.value, verifyCode.value); common_vendor.index.__f__("log", "at pages/login/login.vue:342", "登录成功:", res); const { userInfo, token } = res.data || res; const saveSuccess = utils_userCache.saveUserInfo(userInfo, token); if (saveSuccess) { common_vendor.index.showToast({ title: "登录成功", icon: "success" }); setTimeout(() => { common_vendor.index.reLaunch({ url: "/pages/index/index" }); }, 1500); } else { common_vendor.index.showToast({ title: "保存登录信息失败", icon: "none" }); } } catch (error) { common_vendor.index.__f__("error", "at pages/login/login.vue:367", "登录失败:", error); } finally { isLoading.value = false; } }; const wechatLogin = () => { common_vendor.index.getUserProfile({ desc: "用于完善用户资料", success: (res) => { common_vendor.index.__f__("log", "at pages/login/login.vue:379", "微信授权成功:", res.userInfo); common_vendor.index.showToast({ title: "微信授权成功", icon: "success" }); }, fail: (err) => { common_vendor.index.__f__("log", "at pages/login/login.vue:387", "微信授权失败:", err); } }); }; const showUserAgreement = () => { showUserAgreementPopup.value = true; }; const closeUserAgreement = () => { showUserAgreementPopup.value = false; }; const showPrivacyPolicy = () => { showPrivacyPolicyPopup.value = true; }; const closePrivacyPolicy = () => { showPrivacyPolicyPopup.value = false; }; common_vendor.onUnmounted(() => { if (timer) { clearInterval(timer); } }); return (_ctx, _cache) => { return common_vendor.e({ a: common_vendor.o(($event) => phoneNumber.value = $event, "e1"), b: common_vendor.p({ placeholder: "请输入手机号", type: "number", maxlength: "11", clearable: false, modelValue: phoneNumber.value }), c: common_vendor.o(($event) => verifyCode.value = $event, "57"), d: common_vendor.p({ placeholder: "验证码", type: "number", maxlength: "6", clearable: false, modelValue: verifyCode.value }), e: common_vendor.t(countdown.value > 0 ? `${countdown.value}s` : "获取验证码"), f: countdown.value > 0 ? 1 : "", g: common_vendor.o(getVerifyCode, "ad"), h: common_vendor.o(handleLogin, "76"), i: isLoading.value, j: common_vendor.o(showUserAgreement, "62"), k: common_vendor.o(showPrivacyPolicy, "24"), l: common_vendor.o(wechatLogin, "c2"), m: showUserAgreementPopup.value }, showUserAgreementPopup.value ? { n: common_vendor.o(closeUserAgreement, "07"), o: common_vendor.o(closeUserAgreement, "0f"), p: common_vendor.o(() => { }, "80"), q: common_vendor.o(closeUserAgreement, "07") } : {}, { r: showPrivacyPolicyPopup.value }, showPrivacyPolicyPopup.value ? { s: common_vendor.o(closePrivacyPolicy, "ba"), t: common_vendor.o(closePrivacyPolicy, "6e"), v: common_vendor.o(() => { }, "28"), w: common_vendor.o(closePrivacyPolicy, "72") } : {}); }; } }; const MiniProgramPage = /* @__PURE__ */ common_vendor._export_sfc(_sfc_main, [["__scopeId", "data-v-e4e4508d"]]); wx.createPage(MiniProgramPage); //# sourceMappingURL=../../../.sourcemap/mp-weixin/pages/login/login.js.map