strong.js 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216
  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. const _sfc_main = {
  6. __name: "strong",
  7. setup(__props) {
  8. const isPurchased = common_vendor.ref(false);
  9. const showModal = common_vendor.ref(false);
  10. common_vendor.ref("yearly");
  11. const stockList = common_vendor.ref([
  12. {
  13. name: "航天发展",
  14. code: "000547"
  15. },
  16. {
  17. name: "贵州茅台",
  18. code: "600519"
  19. }
  20. ]);
  21. const startMonth = common_vendor.ref("2025-01");
  22. const endMonth = common_vendor.ref("2025-11");
  23. const formatMonth = (monthStr) => {
  24. if (!monthStr)
  25. return "请选择";
  26. const [year, month] = monthStr.split("-");
  27. return `${year}年${month}月`;
  28. };
  29. const checkPurchaseStatus = () => {
  30. if (!utils_auth.isLoggedIn()) {
  31. isPurchased.value = false;
  32. return;
  33. }
  34. try {
  35. const purchaseInfo = common_vendor.index.getStorageSync("strong_pool_purchase");
  36. if (purchaseInfo) {
  37. const now = Date.now();
  38. const expireTime = purchaseInfo.expireTime;
  39. if (now < expireTime) {
  40. isPurchased.value = true;
  41. } else {
  42. common_vendor.index.removeStorageSync("strong_pool_purchase");
  43. isPurchased.value = false;
  44. }
  45. } else {
  46. isPurchased.value = false;
  47. }
  48. } catch (e) {
  49. console.error("检查购买状态失败:", e);
  50. isPurchased.value = false;
  51. }
  52. };
  53. const showPurchaseModal = () => {
  54. console.log("点击立即解锁");
  55. if (!utils_auth.isLoggedIn()) {
  56. console.log("未登录,跳转到登录页");
  57. common_vendor.index.showModal({
  58. title: "登录提示",
  59. content: "此功能需要登录后使用,是否前往登录?",
  60. confirmText: "去登录",
  61. cancelText: "取消",
  62. success: (res) => {
  63. if (res.confirm) {
  64. common_vendor.index.navigateTo({
  65. url: "/pages/login/login"
  66. });
  67. }
  68. }
  69. });
  70. return;
  71. }
  72. console.log("已登录,显示购买弹窗");
  73. showModal.value = true;
  74. };
  75. const closePurchaseModal = () => {
  76. showModal.value = false;
  77. };
  78. const handlePurchase = () => {
  79. const now = Date.now();
  80. const expireTime = now + 365 * 24 * 60 * 60 * 1e3;
  81. const purchaseInfo = {
  82. plan: "yearly",
  83. purchaseTime: now,
  84. expireTime
  85. };
  86. common_vendor.index.setStorageSync("strong_pool_purchase", purchaseInfo);
  87. isPurchased.value = true;
  88. closePurchaseModal();
  89. common_vendor.index.showToast({
  90. title: "解锁成功",
  91. icon: "success"
  92. });
  93. };
  94. const onStartMonthChange = (e) => {
  95. startMonth.value = e.detail.value;
  96. console.log("[强势池] 选择开始月份:", startMonth.value);
  97. };
  98. const onEndMonthChange = (e) => {
  99. endMonth.value = e.detail.value;
  100. console.log("[强势池] 选择结束月份:", endMonth.value);
  101. };
  102. const onHistorySearch = () => {
  103. if (!startMonth.value || !endMonth.value) {
  104. common_vendor.index.showToast({
  105. title: "请选择开始和结束月份",
  106. icon: "none"
  107. });
  108. return;
  109. }
  110. if (startMonth.value > endMonth.value) {
  111. common_vendor.index.showToast({
  112. title: "开始月份不能晚于结束月份",
  113. icon: "none"
  114. });
  115. return;
  116. }
  117. console.log("[强势池] 查询历史数据区间:", startMonth.value, "至", endMonth.value);
  118. common_vendor.index.showToast({
  119. title: `查询${formatMonth(startMonth.value)}至${formatMonth(endMonth.value)}`,
  120. icon: "none",
  121. duration: 2e3
  122. });
  123. };
  124. const addToMyStocks = async (stock) => {
  125. try {
  126. const myStocks = common_vendor.index.getStorageSync("my_stocks") || [];
  127. const exists = myStocks.some((item) => item.code === stock.code);
  128. if (exists) {
  129. common_vendor.index.showToast({
  130. title: "该股票已在列表中",
  131. icon: "none"
  132. });
  133. return;
  134. }
  135. common_vendor.index.showLoading({ title: "获取行情..." });
  136. let priceChange = null;
  137. let changePercent = null;
  138. try {
  139. const quoteRes = await utils_api.getStockQuotes(stock.code);
  140. console.log("[强势池] 行情数据:", quoteRes);
  141. if (quoteRes.code === 200 && quoteRes.data && quoteRes.data.length > 0) {
  142. const quoteData = quoteRes.data[0];
  143. priceChange = quoteData.priceChange;
  144. changePercent = quoteData.changePercent;
  145. }
  146. } catch (e) {
  147. console.error("获取行情数据失败:", e);
  148. }
  149. common_vendor.index.hideLoading();
  150. myStocks.push({
  151. name: stock.name,
  152. code: stock.code,
  153. priceChange,
  154. changePercent,
  155. addTime: Date.now()
  156. });
  157. common_vendor.index.setStorageSync("my_stocks", myStocks);
  158. common_vendor.index.showToast({
  159. title: "添加成功",
  160. icon: "success"
  161. });
  162. } catch (e) {
  163. common_vendor.index.hideLoading();
  164. console.error("添加股票失败:", e);
  165. common_vendor.index.showToast({
  166. title: "添加失败",
  167. icon: "none"
  168. });
  169. }
  170. };
  171. common_vendor.onLoad(() => {
  172. const loginStatus = utils_auth.isLoggedIn();
  173. console.log("[强势池] 登录状态:", loginStatus);
  174. checkPurchaseStatus();
  175. });
  176. common_vendor.onShow(() => {
  177. const loginStatus = utils_auth.isLoggedIn();
  178. console.log("[强势池] 登录状态:", loginStatus);
  179. checkPurchaseStatus();
  180. common_vendor.index.setNavigationBarTitle({ title: "量化交易大师" });
  181. });
  182. return (_ctx, _cache) => {
  183. return common_vendor.e({
  184. a: !isPurchased.value
  185. }, !isPurchased.value ? {
  186. b: common_vendor.o(showPurchaseModal)
  187. } : {
  188. c: common_vendor.f(stockList.value, (stock, index, i0) => {
  189. return {
  190. a: common_vendor.t(stock.name),
  191. b: common_vendor.t(stock.code),
  192. c: common_vendor.o(($event) => addToMyStocks(stock), index),
  193. d: index
  194. };
  195. })
  196. }, {
  197. d: common_vendor.t(formatMonth(startMonth.value)),
  198. e: startMonth.value,
  199. f: common_vendor.o(onStartMonthChange),
  200. g: common_vendor.t(formatMonth(endMonth.value)),
  201. h: endMonth.value,
  202. i: common_vendor.o(onEndMonthChange),
  203. j: common_vendor.o(onHistorySearch),
  204. k: showModal.value
  205. }, showModal.value ? {
  206. l: common_vendor.o(closePurchaseModal),
  207. m: common_vendor.o(handlePurchase),
  208. n: common_vendor.o(() => {
  209. }),
  210. o: common_vendor.o(closePurchaseModal)
  211. } : {});
  212. };
  213. }
  214. };
  215. const MiniProgramPage = /* @__PURE__ */ common_vendor._export_sfc(_sfc_main, [["__file", "D:/program/gupiao-wx/src/pages/strong/strong.vue"]]);
  216. wx.createPage(MiniProgramPage);