pool.js 5.9 KB

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