mine.js 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  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. }
  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 handleOrderRecord = () => {
  74. if (!utils_auth.checkLogin()) {
  75. return;
  76. }
  77. common_vendor.index.navigateTo({
  78. url: "/pages/order/order"
  79. });
  80. };
  81. const handleShortPoolManage = () => {
  82. if (!isAdmin.value) {
  83. common_vendor.index.showToast({ title: "无权限访问", icon: "none" });
  84. return;
  85. }
  86. common_vendor.index.navigateTo({
  87. url: "/pages/admin/shortPool"
  88. });
  89. };
  90. return (_ctx, _cache) => {
  91. return common_vendor.e({
  92. a: isLoggedIn.value && userInfo.value.avatar ? common_vendor.unref(utils_api.getImageUrl)(userInfo.value.avatar) : "/static/images/head.png",
  93. b: common_vendor.t(isLoggedIn.value ? userInfo.value.nickname || "微信用户" : "登录/注册"),
  94. c: common_vendor.o(handleUserCardClick),
  95. d: common_vendor.o(handleSubscriptionRecord),
  96. e: common_vendor.o(handleOrderRecord),
  97. f: isAdmin.value
  98. }, isAdmin.value ? {
  99. g: common_vendor.o(handleShortPoolManage)
  100. } : {}, {
  101. h: isLoggedIn.value
  102. }, isLoggedIn.value ? {
  103. i: common_vendor.o(handleLogout)
  104. } : {});
  105. };
  106. }
  107. };
  108. const MiniProgramPage = /* @__PURE__ */ common_vendor._export_sfc(_sfc_main, [["__file", "D:/program/gupiao-wx/src/pages/mine/mine.vue"]]);
  109. wx.createPage(MiniProgramPage);