pool.js 5.4 KB

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