pool.js 4.7 KB

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