mine.js 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. "use strict";
  2. const common_vendor = require("../../common/vendor.js");
  3. const utils_auth = require("../../utils/auth.js");
  4. const _sfc_main = {
  5. __name: "mine",
  6. setup(__props) {
  7. const isLoggedIn = common_vendor.ref(false);
  8. const userInfo = common_vendor.ref({
  9. nickname: "",
  10. avatar: "",
  11. phone: ""
  12. });
  13. const points = common_vendor.ref(900);
  14. common_vendor.onMounted(() => {
  15. loadUserInfo();
  16. });
  17. common_vendor.onShow(() => {
  18. loadUserInfo();
  19. });
  20. const loadUserInfo = () => {
  21. isLoggedIn.value = utils_auth.isLoggedIn();
  22. if (isLoggedIn.value) {
  23. const storedInfo = utils_auth.getUserInfo();
  24. if (storedInfo) {
  25. userInfo.value = storedInfo;
  26. console.log("加载用户信息:", userInfo.value);
  27. }
  28. }
  29. };
  30. const handleEditProfile = () => {
  31. if (!utils_auth.checkLogin(() => {
  32. handleEditProfile();
  33. })) {
  34. return;
  35. }
  36. common_vendor.index.navigateTo({
  37. url: "/pages/profile/edit"
  38. });
  39. };
  40. const toggleLogin = () => {
  41. if (isLoggedIn.value) {
  42. common_vendor.index.showModal({
  43. title: "提示",
  44. content: "确定要退出登录吗?",
  45. success: (res) => {
  46. if (res.confirm) {
  47. utils_auth.logout();
  48. isLoggedIn.value = false;
  49. userInfo.value = { nickname: "", avatar: "", phone: "" };
  50. common_vendor.index.showToast({ title: "已退出登录", icon: "none" });
  51. }
  52. }
  53. });
  54. } else {
  55. common_vendor.index.navigateTo({
  56. url: "/pages/login/login"
  57. });
  58. }
  59. };
  60. const handleRecharge = () => {
  61. if (!utils_auth.checkLogin(() => {
  62. handleRecharge();
  63. })) {
  64. return;
  65. }
  66. common_vendor.index.showToast({ title: "充值功能开发中", icon: "none" });
  67. };
  68. const handleHistory = () => {
  69. if (!utils_auth.checkLogin(() => {
  70. handleHistory();
  71. })) {
  72. return;
  73. }
  74. common_vendor.index.showToast({ title: "记录功能开发中", icon: "none" });
  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.o(handleEditProfile),
  80. c: common_vendor.t(isLoggedIn.value ? userInfo.value.nickname || "微信用户" : "游客"),
  81. d: isLoggedIn.value && userInfo.value.phone
  82. }, isLoggedIn.value && userInfo.value.phone ? {
  83. e: common_vendor.t(userInfo.value.phone)
  84. } : {}, {
  85. f: common_vendor.t(isLoggedIn.value ? points.value : 0),
  86. g: common_vendor.o(handleRecharge),
  87. h: common_vendor.o(handleHistory),
  88. i: common_vendor.t(isLoggedIn.value ? "退出登录" : "登录"),
  89. j: common_vendor.o(toggleLogin)
  90. });
  91. };
  92. }
  93. };
  94. const MiniProgramPage = /* @__PURE__ */ common_vendor._export_sfc(_sfc_main, [["__file", "D:/program/gupiao-wx/src/pages/mine/mine.vue"]]);
  95. wx.createPage(MiniProgramPage);