mine.js 3.1 KB

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