mine.js 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  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. 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. if (isLoggedIn.value) {
  22. const storedInfo = utils_auth.getUserInfo();
  23. if (storedInfo) {
  24. userInfo.value = storedInfo;
  25. isAdmin.value = storedInfo.status === 2;
  26. console.log("[我的] 本地缓存头像:", storedInfo.avatar);
  27. }
  28. const latestInfo = await utils_auth.refreshUserInfo();
  29. if (latestInfo) {
  30. userInfo.value = latestInfo;
  31. isAdmin.value = latestInfo.status === 2;
  32. console.log("[我的] 后端返回头像:", latestInfo.avatar);
  33. console.log("[我的] 处理后头像URL:", latestInfo.avatar ? utils_api.getImageUrl(latestInfo.avatar) : "无");
  34. }
  35. } else {
  36. isAdmin.value = false;
  37. }
  38. };
  39. const handleUserCardClick = () => {
  40. if (!isLoggedIn.value) {
  41. handleLogin();
  42. } else {
  43. common_vendor.index.navigateTo({
  44. url: "/pages/profile/edit"
  45. });
  46. }
  47. };
  48. const handleLogin = async () => {
  49. console.log("[我的] 开始登录流程");
  50. common_vendor.index.navigateTo({
  51. url: "/pages/login/login"
  52. });
  53. };
  54. const handleLogout = () => {
  55. common_vendor.index.showModal({
  56. title: "提示",
  57. content: "确定要退出登录吗?",
  58. success: (res) => {
  59. if (res.confirm) {
  60. utils_auth.logout();
  61. isLoggedIn.value = false;
  62. userInfo.value = { nickname: "", avatar: "" };
  63. common_vendor.index.showToast({ title: "已退出登录", icon: "none" });
  64. }
  65. }
  66. });
  67. };
  68. const handleOrderRecord = () => {
  69. if (!utils_auth.checkLogin()) {
  70. return;
  71. }
  72. common_vendor.index.navigateTo({
  73. url: "/pages/order/order"
  74. });
  75. };
  76. const handleContactUs = () => {
  77. if (!utils_auth.checkLogin()) {
  78. return;
  79. }
  80. common_vendor.index.navigateTo({
  81. url: "/pages/contact/contact"
  82. });
  83. };
  84. const handleShortPoolManage = () => {
  85. if (!isAdmin.value) {
  86. common_vendor.index.showToast({ title: "无权限访问", icon: "none" });
  87. return;
  88. }
  89. common_vendor.index.navigateTo({
  90. url: "/pages/admin/shortPool"
  91. });
  92. };
  93. return (_ctx, _cache) => {
  94. return common_vendor.e({
  95. a: isLoggedIn.value && userInfo.value.avatar ? common_vendor.unref(utils_api.getImageUrl)(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.o(handleOrderRecord),
  99. e: common_vendor.o(handleContactUs),
  100. f: isAdmin.value
  101. }, isAdmin.value ? {
  102. g: common_vendor.o(handleShortPoolManage)
  103. } : {}, {
  104. h: isLoggedIn.value
  105. }, isLoggedIn.value ? {
  106. i: common_vendor.o(handleLogout)
  107. } : {});
  108. };
  109. }
  110. };
  111. const MiniProgramPage = /* @__PURE__ */ common_vendor._export_sfc(_sfc_main, [["__file", "D:/program/gupiao/gupiao-wx/src/pages/mine/mine.vue"]]);
  112. wx.createPage(MiniProgramPage);