pool.js 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  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 startMonth = common_vendor.ref("2025-01");
  11. const endMonth = common_vendor.ref("2025-11");
  12. const isLoggedIn = common_vendor.ref(false);
  13. const formatMonth = (monthStr) => {
  14. if (!monthStr)
  15. return "请选择";
  16. const [year, month] = monthStr.split("-");
  17. return `${year}年${month}月`;
  18. };
  19. const checkLogin = () => {
  20. isLoggedIn.value = utils_auth.isLoggedIn();
  21. return isLoggedIn.value;
  22. };
  23. const checkPurchaseStatus = () => {
  24. if (!checkLogin()) {
  25. isPurchased.value = false;
  26. return;
  27. }
  28. try {
  29. const purchaseInfo = common_vendor.index.getStorageSync("pool_purchase");
  30. if (purchaseInfo) {
  31. const now = Date.now();
  32. const expireTime = purchaseInfo.expireTime;
  33. if (now < expireTime) {
  34. isPurchased.value = true;
  35. } else {
  36. common_vendor.index.removeStorageSync("pool_purchase");
  37. isPurchased.value = false;
  38. }
  39. } else {
  40. isPurchased.value = false;
  41. }
  42. } catch (e) {
  43. console.error("检查购买状态失败:", e);
  44. isPurchased.value = false;
  45. }
  46. };
  47. const showPurchaseModal = () => {
  48. if (!checkLogin()) {
  49. common_vendor.index.showModal({
  50. title: "登录提示",
  51. content: "此功能需要登录后使用,是否前往登录?",
  52. confirmText: "去登录",
  53. cancelText: "取消",
  54. success: (res) => {
  55. if (res.confirm) {
  56. common_vendor.index.navigateTo({
  57. url: "/pages/login/login"
  58. });
  59. }
  60. }
  61. });
  62. return;
  63. }
  64. showModal.value = true;
  65. };
  66. const closePurchaseModal = () => {
  67. showModal.value = false;
  68. };
  69. const handlePurchase = () => {
  70. const now = Date.now();
  71. const today = /* @__PURE__ */ new Date();
  72. today.setHours(23, 59, 59, 999);
  73. const expireTime = today.getTime();
  74. const purchaseInfo = {
  75. plan: "reward",
  76. purchaseTime: now,
  77. expireTime
  78. };
  79. common_vendor.index.setStorageSync("pool_purchase", purchaseInfo);
  80. isPurchased.value = true;
  81. closePurchaseModal();
  82. common_vendor.index.showToast({
  83. title: "解锁成功",
  84. icon: "success"
  85. });
  86. };
  87. const onStartMonthChange = (e) => {
  88. startMonth.value = e.detail.value;
  89. };
  90. const onEndMonthChange = (e) => {
  91. endMonth.value = e.detail.value;
  92. };
  93. const onHistorySearch = () => {
  94. if (!startMonth.value || !endMonth.value) {
  95. common_vendor.index.showToast({
  96. title: "请选择开始和结束月份",
  97. icon: "none"
  98. });
  99. return;
  100. }
  101. if (startMonth.value > endMonth.value) {
  102. common_vendor.index.showToast({
  103. title: "开始月份不能晚于结束月份",
  104. icon: "none"
  105. });
  106. return;
  107. }
  108. common_vendor.index.showToast({
  109. title: `查询${formatMonth(startMonth.value)}至${formatMonth(endMonth.value)}`,
  110. icon: "none",
  111. duration: 2e3
  112. });
  113. };
  114. common_vendor.onLoad(() => {
  115. const loginStatus = checkLogin();
  116. console.log("[超短池] 登录状态:", loginStatus);
  117. checkPurchaseStatus();
  118. });
  119. common_vendor.onShow(() => {
  120. const loginStatus = checkLogin();
  121. console.log("[超短池] 登录状态:", loginStatus);
  122. checkPurchaseStatus();
  123. common_vendor.index.setNavigationBarTitle({ title: "量化交易大师" });
  124. });
  125. return (_ctx, _cache) => {
  126. return common_vendor.e({
  127. a: !isPurchased.value
  128. }, !isPurchased.value ? {
  129. b: common_vendor.o(showPurchaseModal)
  130. } : {}, {
  131. c: common_vendor.t(formatMonth(startMonth.value)),
  132. d: startMonth.value,
  133. e: common_vendor.o(onStartMonthChange),
  134. f: common_vendor.t(formatMonth(endMonth.value)),
  135. g: endMonth.value,
  136. h: common_vendor.o(onEndMonthChange),
  137. i: common_vendor.o(onHistorySearch),
  138. j: showModal.value
  139. }, showModal.value ? {
  140. k: common_vendor.o(closePurchaseModal),
  141. l: common_vendor.o(handlePurchase),
  142. m: common_vendor.o(() => {
  143. }),
  144. n: common_vendor.o(closePurchaseModal)
  145. } : {});
  146. };
  147. }
  148. };
  149. const MiniProgramPage = /* @__PURE__ */ common_vendor._export_sfc(_sfc_main, [["__file", "D:/program/gupiao-wx/src/pages/pool/pool.vue"]]);
  150. wx.createPage(MiniProgramPage);