mine.js 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  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 userInfo = common_vendor.ref({
  10. nickname: "",
  11. avatar: ""
  12. });
  13. common_vendor.onShow(() => {
  14. loadUserInfo();
  15. common_vendor.index.setNavigationBarTitle({ title: "量化交易大师" });
  16. });
  17. const loadUserInfo = async () => {
  18. isLoggedIn.value = utils_auth.isLoggedIn();
  19. console.log("[个人中心] 登录状态:", isLoggedIn.value);
  20. if (isLoggedIn.value) {
  21. const storedInfo = utils_auth.getUserInfo();
  22. if (storedInfo) {
  23. userInfo.value = storedInfo;
  24. console.log("[个人中心] 加载用户信息:", userInfo.value);
  25. }
  26. }
  27. };
  28. const handleUserCardClick = () => {
  29. if (!isLoggedIn.value) {
  30. handleLogin();
  31. }
  32. };
  33. const handleLogin = async () => {
  34. console.log("[我的] 开始登录流程");
  35. common_vendor.index.navigateTo({
  36. url: "/pages/login/login"
  37. });
  38. };
  39. const handleLogout = () => {
  40. common_vendor.index.showModal({
  41. title: "提示",
  42. content: "确定要退出登录吗?",
  43. success: (res) => {
  44. if (res.confirm) {
  45. utils_auth.logout();
  46. isLoggedIn.value = false;
  47. userInfo.value = { nickname: "", avatar: "" };
  48. common_vendor.index.showToast({ title: "已退出登录", icon: "none" });
  49. }
  50. }
  51. });
  52. };
  53. const handleSubscriptionRecord = () => {
  54. if (!utils_auth.checkLogin()) {
  55. return;
  56. }
  57. common_vendor.index.navigateTo({
  58. url: "/pages/transaction/transaction"
  59. });
  60. };
  61. return (_ctx, _cache) => {
  62. return common_vendor.e({
  63. a: isLoggedIn.value && userInfo.value.avatar ? userInfo.value.avatar : "/static/images/head.png",
  64. b: common_vendor.t(isLoggedIn.value ? userInfo.value.nickname || "微信用户" : "登录/注册"),
  65. c: common_vendor.o(handleUserCardClick),
  66. d: common_vendor.o(handleSubscriptionRecord),
  67. e: isLoggedIn.value
  68. }, isLoggedIn.value ? {
  69. f: common_vendor.o(handleLogout)
  70. } : {});
  71. };
  72. }
  73. };
  74. const MiniProgramPage = /* @__PURE__ */ common_vendor._export_sfc(_sfc_main, [["__file", "D:/program/gupiao-wx/src/pages/mine/mine.vue"]]);
  75. wx.createPage(MiniProgramPage);