strong.js 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209
  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. if (!utils_auth.isLoggedIn()) {
  55. common_vendor.index.showModal({
  56. title: "登录提示",
  57. content: "此功能需要登录后使用,是否前往登录?",
  58. confirmText: "去登录",
  59. cancelText: "取消",
  60. success: (res) => {
  61. if (res.confirm) {
  62. common_vendor.index.navigateTo({
  63. url: "/pages/login/login"
  64. });
  65. }
  66. }
  67. });
  68. return;
  69. }
  70. showModal.value = true;
  71. };
  72. const closePurchaseModal = () => {
  73. showModal.value = false;
  74. };
  75. const handlePurchase = () => {
  76. const now = Date.now();
  77. const expireTime = now + 365 * 24 * 60 * 60 * 1e3;
  78. const purchaseInfo = {
  79. plan: "yearly",
  80. purchaseTime: now,
  81. expireTime
  82. };
  83. common_vendor.index.setStorageSync("strong_pool_purchase", purchaseInfo);
  84. isPurchased.value = true;
  85. closePurchaseModal();
  86. common_vendor.index.showToast({
  87. title: "解锁成功",
  88. icon: "success"
  89. });
  90. };
  91. const onStartMonthChange = (e) => {
  92. startMonth.value = e.detail.value;
  93. };
  94. const onEndMonthChange = (e) => {
  95. endMonth.value = e.detail.value;
  96. };
  97. const onHistorySearch = () => {
  98. if (!startMonth.value || !endMonth.value) {
  99. common_vendor.index.showToast({
  100. title: "请选择开始和结束月份",
  101. icon: "none"
  102. });
  103. return;
  104. }
  105. if (startMonth.value > endMonth.value) {
  106. common_vendor.index.showToast({
  107. title: "开始月份不能晚于结束月份",
  108. icon: "none"
  109. });
  110. return;
  111. }
  112. common_vendor.index.showToast({
  113. title: `查询${formatMonth(startMonth.value)}至${formatMonth(endMonth.value)}`,
  114. icon: "none",
  115. duration: 2e3
  116. });
  117. };
  118. const addToMyStocks = async (stock) => {
  119. try {
  120. const myStocks = common_vendor.index.getStorageSync("my_stocks") || [];
  121. const exists = myStocks.some((item) => item.code === stock.code);
  122. if (exists) {
  123. common_vendor.index.showToast({
  124. title: "该股票已在列表中",
  125. icon: "none"
  126. });
  127. return;
  128. }
  129. common_vendor.index.showLoading({ title: "获取行情..." });
  130. let priceChange = null;
  131. let changePercent = null;
  132. try {
  133. const quoteRes = await utils_api.getStockQuotes(stock.code);
  134. if (quoteRes.code === 200 && quoteRes.data && quoteRes.data.length > 0) {
  135. const quoteData = quoteRes.data[0];
  136. priceChange = quoteData.priceChange;
  137. changePercent = quoteData.changePercent;
  138. }
  139. } catch (e) {
  140. console.error("获取行情数据失败:", e);
  141. }
  142. common_vendor.index.hideLoading();
  143. myStocks.push({
  144. name: stock.name,
  145. code: stock.code,
  146. priceChange,
  147. changePercent,
  148. addTime: Date.now()
  149. });
  150. common_vendor.index.setStorageSync("my_stocks", myStocks);
  151. common_vendor.index.showToast({
  152. title: "添加成功",
  153. icon: "success"
  154. });
  155. } catch (e) {
  156. common_vendor.index.hideLoading();
  157. console.error("添加股票失败:", e);
  158. common_vendor.index.showToast({
  159. title: "添加失败",
  160. icon: "none"
  161. });
  162. }
  163. };
  164. common_vendor.onLoad(() => {
  165. const loginStatus = utils_auth.isLoggedIn();
  166. console.log("[强势池] 登录状态:", loginStatus);
  167. checkPurchaseStatus();
  168. });
  169. common_vendor.onShow(() => {
  170. const loginStatus = utils_auth.isLoggedIn();
  171. console.log("[强势池] 登录状态:", loginStatus);
  172. checkPurchaseStatus();
  173. common_vendor.index.setNavigationBarTitle({ title: "量化交易大师" });
  174. });
  175. return (_ctx, _cache) => {
  176. return common_vendor.e({
  177. a: !isPurchased.value
  178. }, !isPurchased.value ? {
  179. b: common_vendor.o(showPurchaseModal)
  180. } : {
  181. c: common_vendor.f(stockList.value, (stock, index, i0) => {
  182. return {
  183. a: common_vendor.t(stock.name),
  184. b: common_vendor.t(stock.code),
  185. c: common_vendor.o(($event) => addToMyStocks(stock), index),
  186. d: index
  187. };
  188. })
  189. }, {
  190. d: common_vendor.t(formatMonth(startMonth.value)),
  191. e: startMonth.value,
  192. f: common_vendor.o(onStartMonthChange),
  193. g: common_vendor.t(formatMonth(endMonth.value)),
  194. h: endMonth.value,
  195. i: common_vendor.o(onEndMonthChange),
  196. j: common_vendor.o(onHistorySearch),
  197. k: showModal.value
  198. }, showModal.value ? {
  199. l: common_vendor.o(closePurchaseModal),
  200. m: common_vendor.o(handlePurchase),
  201. n: common_vendor.o(() => {
  202. }),
  203. o: common_vendor.o(closePurchaseModal)
  204. } : {});
  205. };
  206. }
  207. };
  208. const MiniProgramPage = /* @__PURE__ */ common_vendor._export_sfc(_sfc_main, [["__file", "D:/program/gupiao-wx/src/pages/strong/strong.vue"]]);
  209. wx.createPage(MiniProgramPage);