mine.js 2.6 KB

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