mine.js 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  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. if (isLoggedIn.value) {
  22. const storedInfo = utils_auth.getUserInfo();
  23. if (storedInfo) {
  24. userInfo.value = storedInfo;
  25. isAdmin.value = storedInfo.status === 2;
  26. }
  27. const latestInfo = await utils_auth.refreshUserInfo();
  28. if (latestInfo) {
  29. userInfo.value = latestInfo;
  30. isAdmin.value = latestInfo.status === 2;
  31. }
  32. } else {
  33. isAdmin.value = false;
  34. }
  35. };
  36. const handleUserCardClick = () => {
  37. if (!isLoggedIn.value) {
  38. handleLogin();
  39. } else {
  40. common_vendor.index.navigateTo({
  41. url: "/pages/profile/edit"
  42. });
  43. }
  44. };
  45. const handleLogin = async () => {
  46. console.log("[我的] 开始登录流程");
  47. common_vendor.index.navigateTo({
  48. url: "/pages/login/login"
  49. });
  50. };
  51. const handleLogout = () => {
  52. common_vendor.index.showModal({
  53. title: "提示",
  54. content: "确定要退出登录吗?",
  55. success: (res) => {
  56. if (res.confirm) {
  57. utils_auth.logout();
  58. isLoggedIn.value = false;
  59. userInfo.value = { nickname: "", avatar: "" };
  60. common_vendor.index.showToast({ title: "已退出登录", icon: "none" });
  61. }
  62. }
  63. });
  64. };
  65. const handleSubscriptionRecord = () => {
  66. if (!utils_auth.checkLogin()) {
  67. return;
  68. }
  69. common_vendor.index.navigateTo({
  70. url: "/pages/transaction/transaction"
  71. });
  72. };
  73. const handleShortPoolManage = () => {
  74. if (!isAdmin.value) {
  75. common_vendor.index.showToast({ title: "无权限访问", icon: "none" });
  76. return;
  77. }
  78. common_vendor.index.navigateTo({
  79. url: "/pages/admin/shortPool"
  80. });
  81. };
  82. return (_ctx, _cache) => {
  83. return common_vendor.e({
  84. a: isLoggedIn.value && userInfo.value.avatar ? userInfo.value.avatar : "/static/images/head.png",
  85. b: common_vendor.t(isLoggedIn.value ? userInfo.value.nickname || "微信用户" : "登录/注册"),
  86. c: common_vendor.o(handleUserCardClick),
  87. d: common_vendor.o(handleSubscriptionRecord),
  88. e: isAdmin.value
  89. }, isAdmin.value ? {
  90. f: common_vendor.o(handleShortPoolManage)
  91. } : {}, {
  92. g: isLoggedIn.value
  93. }, isLoggedIn.value ? {
  94. h: common_vendor.o(handleLogout)
  95. } : {});
  96. };
  97. }
  98. };
  99. const MiniProgramPage = /* @__PURE__ */ common_vendor._export_sfc(_sfc_main, [["__file", "D:/program/gupiao-wx/src/pages/mine/mine.vue"]]);
  100. wx.createPage(MiniProgramPage);