pool.js 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  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 paymentMethod = common_vendor.ref("wechat");
  15. const userPoints = common_vendor.ref(0);
  16. const checkLogin = () => {
  17. isLoggedIn.value = utils_auth.isLoggedIn();
  18. console.log("[超短池] 登录状态:", isLoggedIn.value);
  19. return isLoggedIn.value;
  20. };
  21. const getUserPoints = () => {
  22. try {
  23. const points = common_vendor.index.getStorageSync("user_points") || 0;
  24. userPoints.value = points;
  25. } catch (e) {
  26. console.error("获取积分失败:", e);
  27. userPoints.value = 0;
  28. }
  29. };
  30. const checkPurchaseStatus = () => {
  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. getUserPoints();
  71. showModal.value = true;
  72. };
  73. const closePurchaseModal = () => {
  74. showModal.value = false;
  75. };
  76. const handlePurchase = () => {
  77. if (!selectedPlan.value) {
  78. common_vendor.index.showToast({
  79. title: "请选择订阅方案",
  80. icon: "none"
  81. });
  82. return;
  83. }
  84. if (paymentMethod.value === "points") {
  85. const requiredPoints = selectedPlan.value === "daily" ? 180 : 980;
  86. if (userPoints.value < requiredPoints) {
  87. common_vendor.index.showToast({
  88. title: "积分不足,请充值或选择微信支付",
  89. icon: "none"
  90. });
  91. return;
  92. }
  93. const newPoints = userPoints.value - requiredPoints;
  94. common_vendor.index.setStorageSync("user_points", newPoints);
  95. userPoints.value = newPoints;
  96. }
  97. const now = Date.now();
  98. let expireTime = now;
  99. if (selectedPlan.value === "daily") {
  100. const today = /* @__PURE__ */ new Date();
  101. today.setHours(23, 59, 59, 999);
  102. expireTime = today.getTime();
  103. } else if (selectedPlan.value === "weekly") {
  104. expireTime = now + 7 * 24 * 60 * 60 * 1e3;
  105. }
  106. const purchaseInfo = {
  107. plan: selectedPlan.value,
  108. purchaseTime: now,
  109. expireTime,
  110. paymentMethod: paymentMethod.value
  111. };
  112. common_vendor.index.setStorageSync("pool_purchase", purchaseInfo);
  113. isPurchased.value = true;
  114. closePurchaseModal();
  115. common_vendor.index.showToast({
  116. title: paymentMethod.value === "points" ? "积分支付成功" : "解锁成功",
  117. icon: "success"
  118. });
  119. };
  120. const onHistorySearch = () => {
  121. common_vendor.index.showToast({
  122. title: "历史查询功能开发中",
  123. icon: "none"
  124. });
  125. };
  126. common_vendor.onLoad(() => {
  127. checkLogin();
  128. checkPurchaseStatus();
  129. getUserPoints();
  130. });
  131. common_vendor.onShow(() => {
  132. checkLogin();
  133. checkPurchaseStatus();
  134. getUserPoints();
  135. });
  136. return (_ctx, _cache) => {
  137. return common_vendor.e({
  138. a: !isPurchased.value
  139. }, !isPurchased.value ? {
  140. b: common_vendor.o(showPurchaseModal)
  141. } : {}, {
  142. c: selectedDate.value,
  143. d: common_vendor.o(($event) => selectedDate.value = $event.detail.value),
  144. e: common_vendor.o(onHistorySearch),
  145. f: showPhoneAuth.value
  146. }, showPhoneAuth.value ? {
  147. g: common_vendor.o((...args) => _ctx.onGetPhoneNumber && _ctx.onGetPhoneNumber(...args)),
  148. h: common_vendor.o(() => {
  149. }),
  150. i: common_vendor.o((...args) => _ctx.closePhoneAuth && _ctx.closePhoneAuth(...args))
  151. } : {}, {
  152. j: showModal.value
  153. }, showModal.value ? common_vendor.e({
  154. k: common_vendor.o(closePurchaseModal),
  155. l: selectedPlan.value === "daily" ? 1 : "",
  156. m: common_vendor.o(($event) => selectedPlan.value = "daily"),
  157. n: selectedPlan.value === "weekly" ? 1 : "",
  158. o: common_vendor.o(($event) => selectedPlan.value = "weekly"),
  159. p: paymentMethod.value === "wechat"
  160. }, paymentMethod.value === "wechat" ? {} : {}, {
  161. q: paymentMethod.value === "wechat" ? 1 : "",
  162. r: common_vendor.o(($event) => paymentMethod.value = "wechat"),
  163. s: common_vendor.t(userPoints.value),
  164. t: common_vendor.t(selectedPlan.value === "daily" ? 180 : 980),
  165. v: paymentMethod.value === "points"
  166. }, paymentMethod.value === "points" ? {} : {}, {
  167. w: paymentMethod.value === "points" ? 1 : "",
  168. x: common_vendor.o(($event) => paymentMethod.value = "points"),
  169. y: common_vendor.t(paymentMethod.value === "points" ? "确认积分支付" : "确认支付并解锁"),
  170. z: paymentMethod.value === "points" ? 1 : "",
  171. A: common_vendor.o(handlePurchase),
  172. B: common_vendor.o(() => {
  173. }),
  174. C: common_vendor.o(closePurchaseModal)
  175. }) : {});
  176. };
  177. }
  178. };
  179. const MiniProgramPage = /* @__PURE__ */ common_vendor._export_sfc(_sfc_main, [["__file", "D:/program/gupiao-wx/src/pages/pool/pool.vue"]]);
  180. wx.createPage(MiniProgramPage);