strong.js 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224
  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: "300136"
  15. },
  16. {
  17. name: "中国卫星",
  18. code: "600118"
  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. if (!utils_auth.isLoggedIn()) {
  120. common_vendor.index.showModal({
  121. title: "登录提示",
  122. content: "添加自选股票需要登录,是否前往登录?",
  123. confirmText: "去登录",
  124. cancelText: "取消",
  125. success: (res) => {
  126. if (res.confirm) {
  127. common_vendor.index.navigateTo({ url: "/pages/login/login" });
  128. }
  129. }
  130. });
  131. return;
  132. }
  133. try {
  134. common_vendor.index.showLoading({ title: "添加中..." });
  135. let currentPrice = null;
  136. try {
  137. const quoteRes = await utils_api.getStockQuotes(stock.code);
  138. console.log("[添加股票] 行情数据:", JSON.stringify(quoteRes));
  139. if (quoteRes.code === 200 && quoteRes.data && quoteRes.data.length > 0) {
  140. const quoteData = quoteRes.data[0];
  141. currentPrice = quoteData.currentPrice;
  142. }
  143. } catch (e) {
  144. console.error("获取行情数据失败:", e);
  145. }
  146. console.log("[添加股票] 请求参数:", { stockCode: stock.code, stockName: stock.name, currentPrice });
  147. const addRes = await utils_api.addUserStock({
  148. stockCode: stock.code,
  149. stockName: stock.name,
  150. currentPrice
  151. });
  152. console.log("[添加股票] 服务器返回:", JSON.stringify(addRes));
  153. common_vendor.index.hideLoading();
  154. if (addRes.code === 200 && addRes.data === true) {
  155. common_vendor.index.showToast({
  156. title: "添加成功",
  157. icon: "success"
  158. });
  159. } else if (addRes.code === 200 && addRes.data === false) {
  160. common_vendor.index.showToast({
  161. title: "股票已存在",
  162. icon: "none"
  163. });
  164. } else {
  165. common_vendor.index.showToast({
  166. title: addRes.message || "添加失败",
  167. icon: "none"
  168. });
  169. }
  170. } catch (e) {
  171. common_vendor.index.hideLoading();
  172. console.error("添加股票失败:", e);
  173. common_vendor.index.showToast({
  174. title: "添加失败",
  175. icon: "none"
  176. });
  177. }
  178. };
  179. common_vendor.onLoad(() => {
  180. const loginStatus = utils_auth.isLoggedIn();
  181. console.log("[强势池] 登录状态:", loginStatus);
  182. checkPurchaseStatus();
  183. });
  184. common_vendor.onShow(() => {
  185. const loginStatus = utils_auth.isLoggedIn();
  186. console.log("[强势池] 登录状态:", loginStatus);
  187. checkPurchaseStatus();
  188. common_vendor.index.setNavigationBarTitle({ title: "量化交易大师" });
  189. });
  190. return (_ctx, _cache) => {
  191. return common_vendor.e({
  192. a: !isPurchased.value
  193. }, !isPurchased.value ? {
  194. b: common_vendor.o(showPurchaseModal)
  195. } : {
  196. c: common_vendor.f(stockList.value, (stock, index, i0) => {
  197. return {
  198. a: common_vendor.t(stock.name),
  199. b: common_vendor.t(stock.code),
  200. c: common_vendor.o(($event) => addToMyStocks(stock), index),
  201. d: index
  202. };
  203. })
  204. }, {
  205. d: common_vendor.t(formatMonth(startMonth.value)),
  206. e: startMonth.value,
  207. f: common_vendor.o(onStartMonthChange),
  208. g: common_vendor.t(formatMonth(endMonth.value)),
  209. h: endMonth.value,
  210. i: common_vendor.o(onEndMonthChange),
  211. j: common_vendor.o(onHistorySearch),
  212. k: showModal.value
  213. }, showModal.value ? {
  214. l: common_vendor.o(closePurchaseModal),
  215. m: common_vendor.o(handlePurchase),
  216. n: common_vendor.o(() => {
  217. }),
  218. o: common_vendor.o(closePurchaseModal)
  219. } : {});
  220. };
  221. }
  222. };
  223. const MiniProgramPage = /* @__PURE__ */ common_vendor._export_sfc(_sfc_main, [["__file", "D:/program/gupiao-wx/src/pages/strong/strong.vue"]]);
  224. wx.createPage(MiniProgramPage);