"use strict"; const common_vendor = require("../../common/vendor.js"); const utils_auth = require("../../utils/auth.js"); require("../../utils/api.js"); const _sfc_main = { __name: "mine", setup(__props) { const isLoggedIn = common_vendor.ref(false); const showPhoneAuth = common_vendor.ref(false); const userInfo = common_vendor.ref({ nickname: "", avatar: "", phone: "" }); const points = common_vendor.ref(900); common_vendor.onMounted(() => { loadUserInfo(); }); common_vendor.onShow(() => { loadUserInfo(); }); const loadUserInfo = () => { isLoggedIn.value = utils_auth.isLoggedIn(); console.log("[个人中心] 登录状态:", isLoggedIn.value); if (isLoggedIn.value) { const storedInfo = utils_auth.getUserInfo(); if (storedInfo) { userInfo.value = storedInfo; console.log("[个人中心] 加载用户信息:", userInfo.value); } } }; const handleEditProfile = () => { if (!utils_auth.checkLogin()) { return; } common_vendor.index.navigateTo({ url: "/pages/profile/edit" }); }; const handleLogin = () => { console.log("[我的] 显示手机号授权弹窗"); showPhoneAuth.value = true; }; const onGetPhoneNumber = async (e) => { console.log("[我的] 获取手机号回调:", e.detail); if (e.detail.errMsg === "getPhoneNumber:ok") { const phoneCode = e.detail.code; console.log("[我的] phoneCode:", phoneCode); common_vendor.index.showLoading({ title: "登录中...", mask: true }); try { const loginRes = await common_vendor.index.login(); console.log("[我的] uni.login完整响应:", loginRes); console.log("[我的] 微信登录code:", loginRes.code); if (!loginRes.code) { throw new Error("获取微信登录code失败"); } const result = await utils_auth.wxAuthLogin(loginRes.code, phoneCode); common_vendor.index.hideLoading(); if (result) { showPhoneAuth.value = false; loadUserInfo(); } } catch (error) { common_vendor.index.hideLoading(); console.error("[我的] 登录失败:", error); } } else { showPhoneAuth.value = false; common_vendor.index.showToast({ title: "需要授权手机号才能完成登录", icon: "none", duration: 2e3 }); } }; const handleLogout = () => { common_vendor.index.showModal({ title: "提示", content: "确定要退出登录吗?", success: (res) => { if (res.confirm) { utils_auth.logout(); isLoggedIn.value = false; userInfo.value = { nickname: "", avatar: "", phone: "" }; common_vendor.index.showToast({ title: "已退出登录", icon: "none" }); } } }); }; const handleRecharge = () => { if (!utils_auth.checkLogin()) { return; } common_vendor.index.showToast({ title: "充值功能开发中", icon: "none" }); }; const handleHistory = () => { if (!utils_auth.checkLogin()) { return; } common_vendor.index.showToast({ title: "记录功能开发中", icon: "none" }); }; return (_ctx, _cache) => { return common_vendor.e({ a: isLoggedIn.value && userInfo.value.avatar ? userInfo.value.avatar : "/static/images/head.png", b: common_vendor.o(handleEditProfile), c: common_vendor.t(isLoggedIn.value ? userInfo.value.nickname || "微信用户" : "游客"), d: isLoggedIn.value && userInfo.value.phone }, isLoggedIn.value && userInfo.value.phone ? { e: common_vendor.t(userInfo.value.phone) } : {}, { f: common_vendor.t(isLoggedIn.value ? points.value : 0), g: common_vendor.o(handleRecharge), h: common_vendor.o(handleHistory), i: !isLoggedIn.value && !showPhoneAuth.value }, !isLoggedIn.value && !showPhoneAuth.value ? { j: common_vendor.o(handleLogin) } : !isLoggedIn.value && showPhoneAuth.value ? { l: common_vendor.o(onGetPhoneNumber) } : { m: common_vendor.o(handleLogout) }, { k: !isLoggedIn.value && showPhoneAuth.value }); }; } }; const MiniProgramPage = /* @__PURE__ */ common_vendor._export_sfc(_sfc_main, [["__file", "D:/program/gupiao-wx/src/pages/mine/mine.vue"]]); wx.createPage(MiniProgramPage);