mine.js 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  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. const points = common_vendor.ref(900);
  16. common_vendor.onMounted(() => {
  17. loadUserInfo();
  18. });
  19. common_vendor.onShow(() => {
  20. loadUserInfo();
  21. });
  22. const loadUserInfo = () => {
  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 handleViewPoints = () => {
  59. if (!utils_auth.checkLogin()) {
  60. return;
  61. }
  62. common_vendor.index.showToast({ title: `当前积分: ${points.value}`, icon: "none" });
  63. };
  64. const handleRecharge = () => {
  65. if (!utils_auth.checkLogin()) {
  66. return;
  67. }
  68. common_vendor.index.showToast({ title: "充值功能开发中", icon: "none" });
  69. };
  70. const handleHistory = () => {
  71. if (!utils_auth.checkLogin()) {
  72. return;
  73. }
  74. common_vendor.index.showToast({ title: "积分记录功能开发中", icon: "none" });
  75. };
  76. const handleTransactionRecord = () => {
  77. if (!utils_auth.checkLogin()) {
  78. return;
  79. }
  80. common_vendor.index.navigateTo({
  81. url: "/pages/transaction/transaction"
  82. });
  83. };
  84. return (_ctx, _cache) => {
  85. return common_vendor.e({
  86. a: isLoggedIn.value && userInfo.value.avatar ? userInfo.value.avatar : "/static/images/head.png",
  87. b: common_vendor.t(isLoggedIn.value ? userInfo.value.nickname || "微信用户" : "登录/注册"),
  88. c: common_vendor.o(handleUserCardClick),
  89. d: common_vendor.t(isLoggedIn.value ? points.value : 0),
  90. e: common_vendor.o(handleViewPoints),
  91. f: common_vendor.o(handleRecharge),
  92. g: common_vendor.o(handleHistory),
  93. h: common_vendor.o(handleTransactionRecord),
  94. i: isLoggedIn.value
  95. }, isLoggedIn.value ? {
  96. j: common_vendor.o(handleLogout)
  97. } : {});
  98. };
  99. }
  100. };
  101. const MiniProgramPage = /* @__PURE__ */ common_vendor._export_sfc(_sfc_main, [["__file", "D:/program/gupiao-wx/src/pages/mine/mine.vue"]]);
  102. wx.createPage(MiniProgramPage);