strong.js 7.2 KB

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