pool.js 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  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 checkLogin = () => {
  15. isLoggedIn.value = utils_auth.isLoggedIn();
  16. console.log("[超短池] 登录状态:", isLoggedIn.value);
  17. return isLoggedIn.value;
  18. };
  19. const checkPurchaseStatus = () => {
  20. try {
  21. const purchaseInfo = common_vendor.index.getStorageSync("pool_purchase");
  22. if (purchaseInfo) {
  23. const now = Date.now();
  24. const expireTime = purchaseInfo.expireTime;
  25. if (now < expireTime) {
  26. isPurchased.value = true;
  27. } else {
  28. common_vendor.index.removeStorageSync("pool_purchase");
  29. isPurchased.value = false;
  30. }
  31. } else {
  32. isPurchased.value = false;
  33. }
  34. } catch (e) {
  35. console.error("检查购买状态失败:", e);
  36. isPurchased.value = false;
  37. }
  38. };
  39. const showPurchaseModal = () => {
  40. console.log("点击立即解锁");
  41. if (!checkLogin()) {
  42. console.log("未登录,显示手机号授权弹窗");
  43. showPhoneAuth.value = true;
  44. return;
  45. }
  46. console.log("已登录,显示购买弹窗");
  47. showModal.value = true;
  48. };
  49. const onGetPhoneNumber = async (e) => {
  50. console.log("[超短池] 获取手机号回调:", e.detail);
  51. if (e.detail.errMsg === "getPhoneNumber:ok") {
  52. const phoneCode = e.detail.code;
  53. console.log("[超短池] phoneCode:", phoneCode);
  54. common_vendor.index.showLoading({
  55. title: "登录中...",
  56. mask: true
  57. });
  58. try {
  59. const loginRes = await common_vendor.index.login();
  60. console.log("[超短池] uni.login完整响应:", loginRes);
  61. console.log("[超短池] 微信登录code:", loginRes.code);
  62. if (!loginRes.code) {
  63. throw new Error("获取微信登录code失败");
  64. }
  65. const result = await utils_auth.wxAuthLogin(loginRes.code, phoneCode);
  66. common_vendor.index.hideLoading();
  67. if (result) {
  68. showPhoneAuth.value = false;
  69. checkLogin();
  70. showModal.value = true;
  71. }
  72. } catch (error) {
  73. common_vendor.index.hideLoading();
  74. console.error("[超短池] 登录失败:", error);
  75. }
  76. } else {
  77. showPhoneAuth.value = false;
  78. common_vendor.index.showToast({
  79. title: "需要授权手机号才能完成登录",
  80. icon: "none",
  81. duration: 2e3
  82. });
  83. }
  84. };
  85. const closePhoneAuth = () => {
  86. showPhoneAuth.value = false;
  87. };
  88. const closePurchaseModal = () => {
  89. showModal.value = false;
  90. };
  91. const handlePurchase = () => {
  92. if (!selectedPlan.value) {
  93. common_vendor.index.showToast({
  94. title: "请选择订阅方案",
  95. icon: "none"
  96. });
  97. return;
  98. }
  99. const now = Date.now();
  100. let expireTime = now;
  101. if (selectedPlan.value === "daily") {
  102. const today = /* @__PURE__ */ new Date();
  103. today.setHours(23, 59, 59, 999);
  104. expireTime = today.getTime();
  105. } else if (selectedPlan.value === "weekly") {
  106. expireTime = now + 7 * 24 * 60 * 60 * 1e3;
  107. }
  108. const purchaseInfo = {
  109. plan: selectedPlan.value,
  110. purchaseTime: now,
  111. expireTime
  112. };
  113. common_vendor.index.setStorageSync("pool_purchase", purchaseInfo);
  114. isPurchased.value = true;
  115. closePurchaseModal();
  116. common_vendor.index.showToast({
  117. title: "解锁成功",
  118. icon: "success"
  119. });
  120. };
  121. const onHistorySearch = () => {
  122. common_vendor.index.showToast({
  123. title: "历史查询功能开发中",
  124. icon: "none"
  125. });
  126. };
  127. common_vendor.onLoad(() => {
  128. checkLogin();
  129. checkPurchaseStatus();
  130. });
  131. common_vendor.onShow(() => {
  132. checkLogin();
  133. checkPurchaseStatus();
  134. });
  135. return (_ctx, _cache) => {
  136. return common_vendor.e({
  137. a: !isPurchased.value
  138. }, !isPurchased.value ? {
  139. b: common_vendor.o(showPurchaseModal)
  140. } : {}, {
  141. c: selectedDate.value,
  142. d: common_vendor.o(($event) => selectedDate.value = $event.detail.value),
  143. e: common_vendor.o(onHistorySearch),
  144. f: showPhoneAuth.value
  145. }, showPhoneAuth.value ? {
  146. g: common_vendor.o(onGetPhoneNumber),
  147. h: common_vendor.o(() => {
  148. }),
  149. i: common_vendor.o(closePhoneAuth)
  150. } : {}, {
  151. j: showModal.value
  152. }, showModal.value ? {
  153. k: common_vendor.o(closePurchaseModal),
  154. l: selectedPlan.value === "daily" ? 1 : "",
  155. m: common_vendor.o(($event) => selectedPlan.value = "daily"),
  156. n: selectedPlan.value === "weekly" ? 1 : "",
  157. o: common_vendor.o(($event) => selectedPlan.value = "weekly"),
  158. p: common_vendor.o(handlePurchase),
  159. q: common_vendor.o(() => {
  160. }),
  161. r: common_vendor.o(closePurchaseModal)
  162. } : {});
  163. };
  164. }
  165. };
  166. const MiniProgramPage = /* @__PURE__ */ common_vendor._export_sfc(_sfc_main, [["__file", "D:/program/gupiao-wx/src/pages/pool/pool.vue"]]);
  167. wx.createPage(MiniProgramPage);