mine.js 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. "use strict";
  2. const common_vendor = require("../../common/vendor.js");
  3. const utils_auth = require("../../utils/auth.js");
  4. require("../../utils/api.js");
  5. const _sfc_main = {
  6. __name: "mine",
  7. setup(__props) {
  8. const isLoggedIn = common_vendor.ref(false);
  9. const showPhoneAuth = common_vendor.ref(false);
  10. const userInfo = common_vendor.ref({
  11. nickname: "",
  12. avatar: "",
  13. phone: ""
  14. });
  15. const points = common_vendor.ref(900);
  16. common_vendor.onMounted(() => {
  17. loadUserInfo();
  18. });
  19. common_vendor.onShow(() => {
  20. loadUserInfo();
  21. });
  22. const loadUserInfo = () => {
  23. isLoggedIn.value = utils_auth.isLoggedIn();
  24. console.log("[个人中心] 登录状态:", isLoggedIn.value);
  25. if (isLoggedIn.value) {
  26. const storedInfo = utils_auth.getUserInfo();
  27. if (storedInfo) {
  28. userInfo.value = storedInfo;
  29. console.log("[个人中心] 加载用户信息:", userInfo.value);
  30. }
  31. }
  32. };
  33. const handleUserCardClick = () => {
  34. if (!isLoggedIn.value) {
  35. handleLogin();
  36. }
  37. };
  38. const handleLogin = async () => {
  39. console.log("[我的] 开始登录流程");
  40. common_vendor.index.showLoading({
  41. title: "登录中...",
  42. mask: true
  43. });
  44. try {
  45. const loginRes = await common_vendor.index.login();
  46. console.log("[我的] uni.login完整响应:", loginRes);
  47. if (!loginRes.code) {
  48. throw new Error("获取微信登录code失败");
  49. }
  50. common_vendor.index.hideLoading();
  51. showPhoneAuth.value = true;
  52. common_vendor.index.showModal({
  53. title: "授权提示",
  54. content: "需要授权手机号才能完成登录",
  55. showCancel: false,
  56. success: () => {
  57. }
  58. });
  59. } catch (error) {
  60. common_vendor.index.hideLoading();
  61. console.error("[我的] 登录失败:", error);
  62. common_vendor.index.showToast({
  63. title: "登录失败,请重试",
  64. icon: "none"
  65. });
  66. }
  67. };
  68. const handleLogout = () => {
  69. common_vendor.index.showModal({
  70. title: "提示",
  71. content: "确定要退出登录吗?",
  72. success: (res) => {
  73. if (res.confirm) {
  74. utils_auth.logout();
  75. isLoggedIn.value = false;
  76. userInfo.value = { nickname: "", avatar: "", phone: "" };
  77. common_vendor.index.showToast({ title: "已退出登录", icon: "none" });
  78. }
  79. }
  80. });
  81. };
  82. const handleViewPoints = () => {
  83. if (!utils_auth.checkLogin()) {
  84. return;
  85. }
  86. common_vendor.index.showToast({ title: `当前积分: ${points.value}`, icon: "none" });
  87. };
  88. const handleRecharge = () => {
  89. if (!utils_auth.checkLogin()) {
  90. return;
  91. }
  92. common_vendor.index.showToast({ title: "充值功能开发中", icon: "none" });
  93. };
  94. const handleHistory = () => {
  95. if (!utils_auth.checkLogin()) {
  96. return;
  97. }
  98. common_vendor.index.showToast({ title: "积分记录功能开发中", icon: "none" });
  99. };
  100. const handleTransactionRecord = () => {
  101. if (!utils_auth.checkLogin()) {
  102. return;
  103. }
  104. common_vendor.index.navigateTo({
  105. url: "/pages/transaction/transaction"
  106. });
  107. };
  108. return (_ctx, _cache) => {
  109. return common_vendor.e({
  110. a: isLoggedIn.value && userInfo.value.avatar ? userInfo.value.avatar : "/static/images/head.png",
  111. b: common_vendor.t(isLoggedIn.value ? userInfo.value.nickname || "微信用户" : "登录/注册"),
  112. c: common_vendor.o(handleUserCardClick),
  113. d: common_vendor.t(isLoggedIn.value ? points.value : 0),
  114. e: common_vendor.o(handleViewPoints),
  115. f: common_vendor.o(handleRecharge),
  116. g: common_vendor.o(handleHistory),
  117. h: common_vendor.o(handleTransactionRecord),
  118. i: isLoggedIn.value
  119. }, isLoggedIn.value ? {
  120. j: common_vendor.o(handleLogout)
  121. } : {});
  122. };
  123. }
  124. };
  125. const MiniProgramPage = /* @__PURE__ */ common_vendor._export_sfc(_sfc_main, [["__file", "D:/program/gupiao-wx/src/pages/mine/mine.vue"]]);
  126. wx.createPage(MiniProgramPage);