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. 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 handleRecharge = () => {
  59. if (!utils_auth.checkLogin()) {
  60. return;
  61. }
  62. common_vendor.index.showToast({ title: "充值功能开发中", icon: "none" });
  63. };
  64. const handleHistory = () => {
  65. if (!utils_auth.checkLogin()) {
  66. return;
  67. }
  68. common_vendor.index.navigateTo({
  69. url: "/pages/points/points"
  70. });
  71. };
  72. const handleTransactionRecord = () => {
  73. if (!utils_auth.checkLogin()) {
  74. return;
  75. }
  76. common_vendor.index.navigateTo({
  77. url: "/pages/transaction/transaction"
  78. });
  79. };
  80. return (_ctx, _cache) => {
  81. return common_vendor.e({
  82. a: isLoggedIn.value && userInfo.value.avatar ? userInfo.value.avatar : "/static/images/head.png",
  83. b: common_vendor.t(isLoggedIn.value ? userInfo.value.nickname || "微信用户" : "登录/注册"),
  84. c: common_vendor.o(handleUserCardClick),
  85. d: common_vendor.t(isLoggedIn.value ? points.value : 0),
  86. e: common_vendor.o(handleRecharge),
  87. f: common_vendor.o(handleHistory),
  88. g: common_vendor.o(handleTransactionRecord),
  89. h: isLoggedIn.value
  90. }, isLoggedIn.value ? {
  91. i: common_vendor.o(handleLogout)
  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);