mine.js 3.1 KB

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