mine.js 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. "use strict";
  2. const common_vendor = require("../../common/vendor.js");
  3. const utils_auth = require("../../utils/auth.js");
  4. const utils_api = require("../../utils/api.js");
  5. const _sfc_main = {
  6. __name: "mine",
  7. setup(__props) {
  8. const isLoggedIn = common_vendor.ref(false);
  9. common_vendor.ref(false);
  10. const userInfo = common_vendor.ref({
  11. nickname: "",
  12. avatar: "",
  13. phone: ""
  14. });
  15. const points = common_vendor.ref(0);
  16. common_vendor.onMounted(() => {
  17. loadUserInfo();
  18. });
  19. common_vendor.onShow(() => {
  20. loadUserInfo();
  21. });
  22. const loadUserInfo = async () => {
  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. await loadUserPoints();
  32. }
  33. };
  34. const loadUserPoints = async () => {
  35. try {
  36. const res = await utils_api.getUserPointsApi();
  37. if (res.code === 200 && res.data) {
  38. points.value = res.data.totalPoints || 0;
  39. console.log("[个人中心] 用户积分:", points.value);
  40. }
  41. } catch (e) {
  42. console.error("获取积分失败:", e);
  43. points.value = 0;
  44. }
  45. };
  46. const handleUserCardClick = () => {
  47. if (!isLoggedIn.value) {
  48. handleLogin();
  49. }
  50. };
  51. const handleLogin = async () => {
  52. console.log("[我的] 开始登录流程");
  53. common_vendor.index.navigateTo({
  54. url: "/pages/login/login"
  55. });
  56. };
  57. const handleLogout = () => {
  58. common_vendor.index.showModal({
  59. title: "提示",
  60. content: "确定要退出登录吗?",
  61. success: (res) => {
  62. if (res.confirm) {
  63. utils_auth.logout();
  64. isLoggedIn.value = false;
  65. userInfo.value = { nickname: "", avatar: "", phone: "" };
  66. common_vendor.index.showToast({ title: "已退出登录", icon: "none" });
  67. }
  68. }
  69. });
  70. };
  71. const handleRecharge = () => {
  72. if (!utils_auth.checkLogin()) {
  73. return;
  74. }
  75. common_vendor.index.showToast({ title: "充值功能开发中", icon: "none" });
  76. };
  77. const handleHistory = () => {
  78. if (!utils_auth.checkLogin()) {
  79. return;
  80. }
  81. common_vendor.index.navigateTo({
  82. url: "/pages/points/points"
  83. });
  84. };
  85. const handleTransactionRecord = () => {
  86. if (!utils_auth.checkLogin()) {
  87. return;
  88. }
  89. common_vendor.index.navigateTo({
  90. url: "/pages/transaction/transaction"
  91. });
  92. };
  93. return (_ctx, _cache) => {
  94. return common_vendor.e({
  95. a: isLoggedIn.value && userInfo.value.avatar ? userInfo.value.avatar : "/static/images/head.png",
  96. b: common_vendor.t(isLoggedIn.value ? userInfo.value.nickname || "微信用户" : "登录/注册"),
  97. c: common_vendor.o(handleUserCardClick),
  98. d: common_vendor.t(isLoggedIn.value ? points.value : 0),
  99. e: common_vendor.o(handleRecharge),
  100. f: common_vendor.o(handleHistory),
  101. g: common_vendor.o(handleTransactionRecord),
  102. h: isLoggedIn.value
  103. }, isLoggedIn.value ? {
  104. i: common_vendor.o(handleLogout)
  105. } : {});
  106. };
  107. }
  108. };
  109. const MiniProgramPage = /* @__PURE__ */ common_vendor._export_sfc(_sfc_main, [["__file", "D:/program/gupiao-wx/src/pages/mine/mine.vue"]]);
  110. wx.createPage(MiniProgramPage);