strong.js 8.1 KB

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