strong.js 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252
  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. const selectedPlan = common_vendor.ref("yearly");
  11. const stockList = common_vendor.ref([
  12. {
  13. name: "美的集团",
  14. code: "000333",
  15. price: "68.00",
  16. score: "88.5"
  17. },
  18. {
  19. name: "贵州茅台",
  20. code: "600519",
  21. price: "1700.00",
  22. score: "85.1"
  23. }
  24. ]);
  25. const startMonth = common_vendor.ref("2025-01");
  26. const endMonth = common_vendor.ref("2025-11");
  27. const formatMonth = (monthStr) => {
  28. if (!monthStr)
  29. return "请选择";
  30. const [year, month] = monthStr.split("-");
  31. return `${year}年${month}月`;
  32. };
  33. const checkPurchaseStatus = () => {
  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. if (!selectedPlan.value) {
  80. common_vendor.index.showToast({
  81. title: "请选择订阅方案",
  82. icon: "none"
  83. });
  84. return;
  85. }
  86. const now = Date.now();
  87. let expireTime = now;
  88. if (selectedPlan.value === "yearly") {
  89. expireTime = now + 365 * 24 * 60 * 60 * 1e3;
  90. }
  91. const purchaseInfo = {
  92. plan: selectedPlan.value,
  93. purchaseTime: now,
  94. expireTime
  95. };
  96. common_vendor.index.setStorageSync("strong_pool_purchase", purchaseInfo);
  97. isPurchased.value = true;
  98. closePurchaseModal();
  99. common_vendor.index.showToast({
  100. title: "解锁成功",
  101. icon: "success"
  102. });
  103. };
  104. const onStartMonthChange = (e) => {
  105. startMonth.value = e.detail.value;
  106. console.log("[强势池] 选择开始月份:", startMonth.value);
  107. };
  108. const onEndMonthChange = (e) => {
  109. endMonth.value = e.detail.value;
  110. console.log("[强势池] 选择结束月份:", endMonth.value);
  111. };
  112. const onHistorySearch = () => {
  113. if (!startMonth.value || !endMonth.value) {
  114. common_vendor.index.showToast({
  115. title: "请选择开始和结束月份",
  116. icon: "none"
  117. });
  118. return;
  119. }
  120. if (startMonth.value > endMonth.value) {
  121. common_vendor.index.showToast({
  122. title: "开始月份不能晚于结束月份",
  123. icon: "none"
  124. });
  125. return;
  126. }
  127. console.log("[强势池] 查询历史数据区间:", startMonth.value, "至", endMonth.value);
  128. common_vendor.index.showToast({
  129. title: `查询${formatMonth(startMonth.value)}至${formatMonth(endMonth.value)}`,
  130. icon: "none",
  131. duration: 2e3
  132. });
  133. };
  134. const addToMyStocks = async (stock) => {
  135. try {
  136. const myStocks = common_vendor.index.getStorageSync("my_stocks") || [];
  137. const exists = myStocks.some((item) => item.code === stock.code);
  138. if (exists) {
  139. common_vendor.index.showToast({
  140. title: "该股票已在列表中",
  141. icon: "none"
  142. });
  143. return;
  144. }
  145. common_vendor.index.showLoading({ title: "获取行情..." });
  146. let priceChange = null;
  147. let changePercent = null;
  148. try {
  149. const quoteRes = await utils_api.getStockQuotes(stock.code);
  150. console.log("[强势池] 行情数据:", quoteRes);
  151. if (quoteRes.code === 200 && quoteRes.data && quoteRes.data.length > 0) {
  152. const quoteData = quoteRes.data[0];
  153. priceChange = quoteData.priceChange;
  154. changePercent = quoteData.changePercent;
  155. }
  156. } catch (e) {
  157. console.error("获取行情数据失败:", e);
  158. }
  159. common_vendor.index.hideLoading();
  160. myStocks.push({
  161. name: stock.name,
  162. code: stock.code,
  163. priceChange,
  164. changePercent,
  165. addTime: Date.now()
  166. });
  167. common_vendor.index.setStorageSync("my_stocks", myStocks);
  168. common_vendor.index.showToast({
  169. title: "添加成功",
  170. icon: "success"
  171. });
  172. } catch (e) {
  173. common_vendor.index.hideLoading();
  174. console.error("添加股票失败:", e);
  175. common_vendor.index.showToast({
  176. title: "添加失败",
  177. icon: "none"
  178. });
  179. }
  180. };
  181. const removeFromMyStocks = (stock) => {
  182. try {
  183. let myStocks = common_vendor.index.getStorageSync("my_stocks") || [];
  184. const index = myStocks.findIndex((item) => item.code === stock.code);
  185. if (index === -1) {
  186. common_vendor.index.showToast({
  187. title: "该股票不在列表中",
  188. icon: "none"
  189. });
  190. return;
  191. }
  192. myStocks.splice(index, 1);
  193. common_vendor.index.setStorageSync("my_stocks", myStocks);
  194. common_vendor.index.showToast({
  195. title: "移除成功",
  196. icon: "success"
  197. });
  198. } catch (e) {
  199. console.error("移除股票失败:", e);
  200. common_vendor.index.showToast({
  201. title: "移除失败",
  202. icon: "none"
  203. });
  204. }
  205. };
  206. common_vendor.onLoad(() => {
  207. const loginStatus = utils_auth.isLoggedIn();
  208. console.log("[强势池] 登录状态:", loginStatus);
  209. checkPurchaseStatus();
  210. });
  211. common_vendor.onShow(() => {
  212. const loginStatus = utils_auth.isLoggedIn();
  213. console.log("[强势池] 登录状态:", loginStatus);
  214. checkPurchaseStatus();
  215. common_vendor.index.setNavigationBarTitle({ title: "量化交易大师" });
  216. });
  217. return (_ctx, _cache) => {
  218. return common_vendor.e({
  219. a: !isPurchased.value
  220. }, !isPurchased.value ? {
  221. b: common_vendor.o(showPurchaseModal)
  222. } : {
  223. c: common_vendor.f(stockList.value, (stock, index, i0) => {
  224. return {
  225. a: common_vendor.t(stock.name),
  226. b: common_vendor.t(stock.code),
  227. c: common_vendor.o(($event) => addToMyStocks(stock), index),
  228. d: common_vendor.o(($event) => removeFromMyStocks(stock), index),
  229. e: index
  230. };
  231. })
  232. }, {
  233. d: common_vendor.t(formatMonth(startMonth.value)),
  234. e: startMonth.value,
  235. f: common_vendor.o(onStartMonthChange),
  236. g: common_vendor.t(formatMonth(endMonth.value)),
  237. h: endMonth.value,
  238. i: common_vendor.o(onEndMonthChange),
  239. j: common_vendor.o(onHistorySearch),
  240. k: showModal.value
  241. }, showModal.value ? {
  242. l: common_vendor.o(closePurchaseModal),
  243. m: common_vendor.o(handlePurchase),
  244. n: common_vendor.o(() => {
  245. }),
  246. o: common_vendor.o(closePurchaseModal)
  247. } : {});
  248. };
  249. }
  250. };
  251. const MiniProgramPage = /* @__PURE__ */ common_vendor._export_sfc(_sfc_main, [["__file", "D:/program/gupiao-wx/src/pages/strong/strong.vue"]]);
  252. wx.createPage(MiniProgramPage);