pool.js 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  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: "pool",
  6. setup(__props) {
  7. const isPurchased = common_vendor.ref(false);
  8. const showModal = common_vendor.ref(false);
  9. const selectedPlan = common_vendor.ref("daily");
  10. const selectedDate = common_vendor.ref("2025年11月20日");
  11. const isLoggedIn = common_vendor.ref(false);
  12. const checkLogin = () => {
  13. isLoggedIn.value = utils_auth.isLoggedIn();
  14. console.log("超短池 - 登录状态:", isLoggedIn.value);
  15. return isLoggedIn.value;
  16. };
  17. const checkPurchaseStatus = () => {
  18. try {
  19. const purchaseInfo = common_vendor.index.getStorageSync("pool_purchase");
  20. if (purchaseInfo) {
  21. const now = Date.now();
  22. const expireTime = purchaseInfo.expireTime;
  23. if (now < expireTime) {
  24. isPurchased.value = true;
  25. } else {
  26. common_vendor.index.removeStorageSync("pool_purchase");
  27. isPurchased.value = false;
  28. }
  29. } else {
  30. isPurchased.value = false;
  31. }
  32. } catch (e) {
  33. console.error("检查购买状态失败:", e);
  34. isPurchased.value = false;
  35. }
  36. };
  37. const showPurchaseModal = () => {
  38. console.log("点击立即解锁");
  39. if (!checkLogin()) {
  40. console.log("未登录,跳转登录页");
  41. common_vendor.index.showModal({
  42. title: "提示",
  43. content: "解锁超短池需要先登录,是否前往登录?",
  44. success: (res) => {
  45. if (res.confirm) {
  46. common_vendor.index.navigateTo({
  47. url: "/pages/login/login"
  48. });
  49. }
  50. }
  51. });
  52. return;
  53. }
  54. console.log("已登录,显示购买弹窗");
  55. showModal.value = true;
  56. };
  57. const closePurchaseModal = () => {
  58. showModal.value = false;
  59. };
  60. const handlePurchase = () => {
  61. if (!selectedPlan.value) {
  62. common_vendor.index.showToast({
  63. title: "请选择订阅方案",
  64. icon: "none"
  65. });
  66. return;
  67. }
  68. const now = Date.now();
  69. let expireTime = now;
  70. if (selectedPlan.value === "daily") {
  71. const today = /* @__PURE__ */ new Date();
  72. today.setHours(23, 59, 59, 999);
  73. expireTime = today.getTime();
  74. } else if (selectedPlan.value === "weekly") {
  75. expireTime = now + 7 * 24 * 60 * 60 * 1e3;
  76. }
  77. const purchaseInfo = {
  78. plan: selectedPlan.value,
  79. purchaseTime: now,
  80. expireTime
  81. };
  82. common_vendor.index.setStorageSync("pool_purchase", purchaseInfo);
  83. isPurchased.value = true;
  84. closePurchaseModal();
  85. common_vendor.index.showToast({
  86. title: "解锁成功",
  87. icon: "success"
  88. });
  89. };
  90. const onHistorySearch = () => {
  91. common_vendor.index.showToast({
  92. title: "历史查询功能开发中",
  93. icon: "none"
  94. });
  95. };
  96. common_vendor.onLoad(() => {
  97. checkLogin();
  98. checkPurchaseStatus();
  99. });
  100. common_vendor.onShow(() => {
  101. checkLogin();
  102. checkPurchaseStatus();
  103. });
  104. return (_ctx, _cache) => {
  105. return common_vendor.e({
  106. a: !isPurchased.value
  107. }, !isPurchased.value ? {
  108. b: common_vendor.o(showPurchaseModal)
  109. } : {}, {
  110. c: selectedDate.value,
  111. d: common_vendor.o(($event) => selectedDate.value = $event.detail.value),
  112. e: common_vendor.o(onHistorySearch),
  113. f: showModal.value
  114. }, showModal.value ? {
  115. g: common_vendor.o(closePurchaseModal),
  116. h: selectedPlan.value === "daily" ? 1 : "",
  117. i: common_vendor.o(($event) => selectedPlan.value = "daily"),
  118. j: selectedPlan.value === "weekly" ? 1 : "",
  119. k: common_vendor.o(($event) => selectedPlan.value = "weekly"),
  120. l: common_vendor.o(handlePurchase),
  121. m: common_vendor.o(() => {
  122. }),
  123. n: common_vendor.o(closePurchaseModal)
  124. } : {});
  125. };
  126. }
  127. };
  128. const MiniProgramPage = /* @__PURE__ */ common_vendor._export_sfc(_sfc_main, [["__file", "D:/program/gupiao-wx/src/pages/pool/pool.vue"]]);
  129. wx.createPage(MiniProgramPage);