strong.js 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176
  1. "use strict";
  2. const common_vendor = require("../../common/vendor.js");
  3. const utils_auth = require("../../utils/auth.js");
  4. const utils_api = require("../../utils/api.js");
  5. if (!Math) {
  6. (PerformanceCard + HistorySearchCard + PurchaseModal)();
  7. }
  8. const PurchaseModal = () => "../../components/PurchaseModal.js";
  9. const PerformanceCard = () => "../../components/PerformanceCard.js";
  10. const HistorySearchCard = () => "../../components/HistorySearchCard.js";
  11. const _sfc_main = {
  12. __name: "strong",
  13. setup(__props) {
  14. const isPurchased = common_vendor.ref(false);
  15. const showModal = common_vendor.ref(false);
  16. const stockList = common_vendor.ref([
  17. { name: "信维通信", code: "300136" },
  18. { name: "中国卫星", code: "600118" }
  19. ]);
  20. const checkPurchaseStatus = () => {
  21. if (!utils_auth.isLoggedIn()) {
  22. isPurchased.value = false;
  23. return;
  24. }
  25. try {
  26. const purchaseInfo = common_vendor.index.getStorageSync("strong_pool_purchase");
  27. if (purchaseInfo) {
  28. const now = Date.now();
  29. if (now < purchaseInfo.expireTime) {
  30. isPurchased.value = true;
  31. } else {
  32. common_vendor.index.removeStorageSync("strong_pool_purchase");
  33. isPurchased.value = false;
  34. }
  35. } else {
  36. isPurchased.value = false;
  37. }
  38. } catch (e) {
  39. console.error("检查购买状态失败:", e);
  40. isPurchased.value = false;
  41. }
  42. };
  43. const showPurchaseModal = () => {
  44. if (!utils_auth.isLoggedIn()) {
  45. common_vendor.index.showModal({
  46. title: "登录提示",
  47. content: "此功能需要登录后使用,是否前往登录?",
  48. confirmText: "去登录",
  49. cancelText: "取消",
  50. success: (res) => {
  51. if (res.confirm) {
  52. common_vendor.index.navigateTo({ url: "/pages/login/login" });
  53. }
  54. }
  55. });
  56. return;
  57. }
  58. showModal.value = true;
  59. };
  60. const closePurchaseModal = () => {
  61. showModal.value = false;
  62. };
  63. const handlePurchase = () => {
  64. const now = Date.now();
  65. const expireTime = now + 365 * 24 * 60 * 60 * 1e3;
  66. common_vendor.index.setStorageSync("strong_pool_purchase", {
  67. plan: "yearly",
  68. purchaseTime: now,
  69. expireTime
  70. });
  71. isPurchased.value = true;
  72. closePurchaseModal();
  73. common_vendor.index.showToast({ title: "解锁成功", icon: "success" });
  74. };
  75. const onHistorySearch = ({ startMonth, endMonth }) => {
  76. const formatMonth = (monthStr) => {
  77. const [year, month] = monthStr.split("-");
  78. return `${year}年${month}月`;
  79. };
  80. common_vendor.index.showToast({
  81. title: `查询${formatMonth(startMonth)}至${formatMonth(endMonth)}`,
  82. icon: "none",
  83. duration: 2e3
  84. });
  85. };
  86. const addToMyStocks = async (stock) => {
  87. if (!utils_auth.isLoggedIn()) {
  88. common_vendor.index.showModal({
  89. title: "登录提示",
  90. content: "添加自选股票需要登录,是否前往登录?",
  91. confirmText: "去登录",
  92. cancelText: "取消",
  93. success: (res) => {
  94. if (res.confirm) {
  95. common_vendor.index.navigateTo({ url: "/pages/login/login" });
  96. }
  97. }
  98. });
  99. return;
  100. }
  101. try {
  102. common_vendor.index.showLoading({ title: "添加中..." });
  103. let currentPrice = null;
  104. try {
  105. const quoteRes = await utils_api.getStockQuotes(stock.code);
  106. if (quoteRes.code === 200 && quoteRes.data && quoteRes.data.length > 0) {
  107. currentPrice = quoteRes.data[0].currentPrice;
  108. }
  109. } catch (e) {
  110. console.error("获取行情数据失败:", e);
  111. }
  112. const addRes = await utils_api.addUserStock({
  113. stockCode: stock.code,
  114. stockName: stock.name,
  115. currentPrice
  116. });
  117. common_vendor.index.hideLoading();
  118. if (addRes.code === 200 && addRes.data === true) {
  119. common_vendor.index.showToast({ title: "添加成功", icon: "success" });
  120. } else if (addRes.code === 200 && addRes.data === false) {
  121. common_vendor.index.showToast({ title: "股票已存在", icon: "none" });
  122. } else {
  123. common_vendor.index.showToast({ title: addRes.message || "添加失败", icon: "none" });
  124. }
  125. } catch (e) {
  126. common_vendor.index.hideLoading();
  127. console.error("添加股票失败:", e);
  128. common_vendor.index.showToast({ title: "添加失败", icon: "none" });
  129. }
  130. };
  131. common_vendor.onLoad(() => {
  132. console.log("[强势池] 登录状态:", utils_auth.isLoggedIn());
  133. checkPurchaseStatus();
  134. });
  135. common_vendor.onShow(() => {
  136. console.log("[强势池] 登录状态:", utils_auth.isLoggedIn());
  137. checkPurchaseStatus();
  138. common_vendor.index.setNavigationBarTitle({ title: "量化交易大师" });
  139. });
  140. return (_ctx, _cache) => {
  141. return common_vendor.e({
  142. a: common_vendor.p({
  143. successRate: "88%",
  144. profitRate: "+12.5%",
  145. totalTrades: 45
  146. }),
  147. b: !isPurchased.value
  148. }, !isPurchased.value ? {
  149. c: common_vendor.o(showPurchaseModal)
  150. } : {
  151. d: common_vendor.f(stockList.value, (stock, index, i0) => {
  152. return {
  153. a: common_vendor.t(stock.name),
  154. b: common_vendor.t(stock.code),
  155. c: common_vendor.o(($event) => addToMyStocks(stock), index),
  156. d: index
  157. };
  158. })
  159. }, {
  160. e: common_vendor.o(onHistorySearch),
  161. f: common_vendor.o(closePurchaseModal),
  162. g: common_vendor.o(handlePurchase),
  163. h: common_vendor.p({
  164. visible: showModal.value,
  165. icon: "📅",
  166. title: "年订阅解锁",
  167. description: "订阅全年,解锁强势趋势池内容",
  168. amountLabel: "订阅金额:",
  169. amount: 98
  170. })
  171. });
  172. };
  173. }
  174. };
  175. const MiniProgramPage = /* @__PURE__ */ common_vendor._export_sfc(_sfc_main, [["__file", "D:/program/gupiao-wx/src/pages/strong/strong.vue"]]);
  176. wx.createPage(MiniProgramPage);