pool.js 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  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. if (!Math) {
  6. (PerformanceCard + HistorySearchCard + PurchaseModal)();
  7. }
  8. const PurchaseModal = () => "../../components/PurchaseModal.js";
  9. const PerformanceCard = () => "../../components/PerformanceCard.js";
  10. const HistorySearchCard = () => "../../components/HistorySearchCard.js";
  11. const _sfc_main = {
  12. __name: "pool",
  13. setup(__props) {
  14. const isPurchased = common_vendor.ref(false);
  15. const showModal = common_vendor.ref(false);
  16. const isLoggedIn = common_vendor.ref(false);
  17. const checkLogin = () => {
  18. isLoggedIn.value = utils_auth.isLoggedIn();
  19. return isLoggedIn.value;
  20. };
  21. const checkPurchaseStatus = () => {
  22. if (!checkLogin()) {
  23. isPurchased.value = false;
  24. return;
  25. }
  26. try {
  27. const purchaseInfo = common_vendor.index.getStorageSync("pool_purchase");
  28. if (purchaseInfo) {
  29. const now = Date.now();
  30. if (now < purchaseInfo.expireTime) {
  31. isPurchased.value = true;
  32. } else {
  33. common_vendor.index.removeStorageSync("pool_purchase");
  34. isPurchased.value = false;
  35. }
  36. } else {
  37. isPurchased.value = false;
  38. }
  39. } catch (e) {
  40. console.error("检查购买状态失败:", e);
  41. isPurchased.value = false;
  42. }
  43. };
  44. const showPurchaseModal = () => {
  45. if (!checkLogin()) {
  46. common_vendor.index.showModal({
  47. title: "登录提示",
  48. content: "此功能需要登录后使用,是否前往登录?",
  49. confirmText: "去登录",
  50. cancelText: "取消",
  51. success: (res) => {
  52. if (res.confirm) {
  53. common_vendor.index.navigateTo({ url: "/pages/login/login" });
  54. }
  55. }
  56. });
  57. return;
  58. }
  59. showModal.value = true;
  60. };
  61. const closePurchaseModal = () => {
  62. showModal.value = false;
  63. };
  64. const handlePurchase = () => {
  65. const now = Date.now();
  66. const today = /* @__PURE__ */ new Date();
  67. today.setHours(23, 59, 59, 999);
  68. common_vendor.index.setStorageSync("pool_purchase", {
  69. plan: "reward",
  70. purchaseTime: now,
  71. expireTime: today.getTime()
  72. });
  73. isPurchased.value = true;
  74. closePurchaseModal();
  75. common_vendor.index.showToast({ title: "解锁成功", icon: "success" });
  76. };
  77. const onHistorySearch = ({ startMonth, endMonth }) => {
  78. const formatMonth = (monthStr) => {
  79. const [year, month] = monthStr.split("-");
  80. return `${year}年${month}月`;
  81. };
  82. common_vendor.index.showToast({
  83. title: `查询${formatMonth(startMonth)}至${formatMonth(endMonth)}`,
  84. icon: "none",
  85. duration: 2e3
  86. });
  87. };
  88. common_vendor.onLoad(() => {
  89. console.log("[超短池] 登录状态:", checkLogin());
  90. checkPurchaseStatus();
  91. });
  92. common_vendor.onShow(() => {
  93. console.log("[超短池] 登录状态:", checkLogin());
  94. checkPurchaseStatus();
  95. common_vendor.index.setNavigationBarTitle({ title: "量化交易大师" });
  96. });
  97. return (_ctx, _cache) => {
  98. return common_vendor.e({
  99. a: common_vendor.p({
  100. successRate: "75%",
  101. profitRate: "+3.2%",
  102. totalTrades: 120
  103. }),
  104. b: !isPurchased.value
  105. }, !isPurchased.value ? {
  106. c: common_vendor.o(showPurchaseModal)
  107. } : {}, {
  108. d: common_vendor.o(onHistorySearch),
  109. e: common_vendor.o(closePurchaseModal),
  110. f: common_vendor.o(handlePurchase),
  111. g: common_vendor.p({
  112. visible: showModal.value,
  113. icon: "💰",
  114. title: "打赏解锁",
  115. description: "支持作者,解锁今日超短池内容",
  116. amountLabel: "打赏金额:",
  117. amount: 1
  118. })
  119. });
  120. };
  121. }
  122. };
  123. const MiniProgramPage = /* @__PURE__ */ common_vendor._export_sfc(_sfc_main, [["__file", "D:/program/gupiao-wx/src/pages/pool/pool.vue"]]);
  124. wx.createPage(MiniProgramPage);