mine.js 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  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. common_vendor.index.setNavigationBarTitle({ title: "量化交易大师" });
  22. });
  23. const loadUserInfo = async () => {
  24. isLoggedIn.value = utils_auth.isLoggedIn();
  25. console.log("[个人中心] 登录状态:", isLoggedIn.value);
  26. if (isLoggedIn.value) {
  27. const storedInfo = utils_auth.getUserInfo();
  28. if (storedInfo) {
  29. userInfo.value = storedInfo;
  30. console.log("[个人中心] 加载用户信息:", userInfo.value);
  31. }
  32. await loadUserPoints();
  33. }
  34. };
  35. const loadUserPoints = async () => {
  36. try {
  37. const res = await utils_api.getUserPointsApi();
  38. if (res.code === 200 && res.data) {
  39. points.value = res.data.totalPoints || 0;
  40. console.log("[个人中心] 用户积分:", points.value);
  41. }
  42. } catch (e) {
  43. console.error("获取积分失败:", e);
  44. points.value = 0;
  45. }
  46. };
  47. const handleUserCardClick = () => {
  48. if (!isLoggedIn.value) {
  49. handleLogin();
  50. }
  51. };
  52. const handleLogin = async () => {
  53. console.log("[我的] 开始登录流程");
  54. common_vendor.index.navigateTo({
  55. url: "/pages/login/login"
  56. });
  57. };
  58. const handleLogout = () => {
  59. common_vendor.index.showModal({
  60. title: "提示",
  61. content: "确定要退出登录吗?",
  62. success: (res) => {
  63. if (res.confirm) {
  64. utils_auth.logout();
  65. isLoggedIn.value = false;
  66. userInfo.value = { nickname: "", avatar: "", phone: "" };
  67. common_vendor.index.showToast({ title: "已退出登录", icon: "none" });
  68. }
  69. }
  70. });
  71. };
  72. const handleRecharge = () => {
  73. if (!utils_auth.checkLogin()) {
  74. return;
  75. }
  76. common_vendor.index.showToast({ title: "充值功能开发中", icon: "none" });
  77. };
  78. const handleHistory = () => {
  79. if (!utils_auth.checkLogin()) {
  80. return;
  81. }
  82. common_vendor.index.navigateTo({
  83. url: "/pages/points/points"
  84. });
  85. };
  86. const handleTransactionRecord = () => {
  87. if (!utils_auth.checkLogin()) {
  88. return;
  89. }
  90. common_vendor.index.navigateTo({
  91. url: "/pages/transaction/transaction"
  92. });
  93. };
  94. return (_ctx, _cache) => {
  95. return common_vendor.e({
  96. a: isLoggedIn.value && userInfo.value.avatar ? userInfo.value.avatar : "/static/images/head.png",
  97. b: common_vendor.t(isLoggedIn.value ? userInfo.value.nickname || "微信用户" : "登录/注册"),
  98. c: common_vendor.o(handleUserCardClick),
  99. d: common_vendor.t(isLoggedIn.value ? points.value : 0),
  100. e: common_vendor.o(handleRecharge),
  101. f: common_vendor.o(handleHistory),
  102. g: common_vendor.o(handleTransactionRecord),
  103. h: isLoggedIn.value
  104. }, isLoggedIn.value ? {
  105. i: common_vendor.o(handleLogout)
  106. } : {});
  107. };
  108. }
  109. };
  110. const MiniProgramPage = /* @__PURE__ */ common_vendor._export_sfc(_sfc_main, [["__file", "D:/program/gupiao-wx/src/pages/mine/mine.vue"]]);
  111. wx.createPage(MiniProgramPage);