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. 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. const loadUserInfo = () => {
  18. isLoggedIn.value = utils_auth.isLoggedIn();
  19. if (isLoggedIn.value) {
  20. const storedInfo = utils_auth.getUserInfo();
  21. if (storedInfo) {
  22. userInfo.value = storedInfo;
  23. }
  24. }
  25. };
  26. const toggleLogin = () => {
  27. if (isLoggedIn.value) {
  28. common_vendor.index.showModal({
  29. title: "提示",
  30. content: "确定要退出登录吗?",
  31. success: (res) => {
  32. if (res.confirm) {
  33. utils_auth.logout();
  34. isLoggedIn.value = false;
  35. userInfo.value = { nickname: "", avatar: "", phone: "" };
  36. common_vendor.index.showToast({ title: "已退出登录", icon: "none" });
  37. }
  38. }
  39. });
  40. } else {
  41. common_vendor.index.navigateTo({
  42. url: "/pages/login/login"
  43. });
  44. }
  45. };
  46. const handleRecharge = () => {
  47. if (!utils_auth.checkLogin(() => {
  48. handleRecharge();
  49. })) {
  50. return;
  51. }
  52. common_vendor.index.showToast({ title: "充值功能开发中", icon: "none" });
  53. };
  54. const handleHistory = () => {
  55. if (!utils_auth.checkLogin(() => {
  56. handleHistory();
  57. })) {
  58. return;
  59. }
  60. common_vendor.index.showToast({ title: "记录功能开发中", icon: "none" });
  61. };
  62. return (_ctx, _cache) => {
  63. return common_vendor.e({
  64. a: isLoggedIn.value && userInfo.value.avatar ? userInfo.value.avatar : "/static/images/tab_mine_active.png",
  65. b: common_vendor.t(isLoggedIn.value ? userInfo.value.nickname || "微信用户" : "游客"),
  66. c: isLoggedIn.value && userInfo.value.phone
  67. }, isLoggedIn.value && userInfo.value.phone ? {
  68. d: common_vendor.t(userInfo.value.phone)
  69. } : {}, {
  70. e: common_vendor.t(isLoggedIn.value ? points.value : 0),
  71. f: common_vendor.o(handleRecharge),
  72. g: common_vendor.o(handleHistory),
  73. h: common_vendor.t(isLoggedIn.value ? "退出登录" : "登录"),
  74. i: common_vendor.o(toggleLogin)
  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);