strong.js 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219
  1. "use strict";
  2. const common_vendor = require("../../common/vendor.js");
  3. const utils_auth = require("../../utils/auth.js");
  4. require("../../utils/api.js");
  5. const _sfc_main = {
  6. __name: "strong",
  7. setup(__props) {
  8. const isLoggedIn = common_vendor.ref(false);
  9. const stockList = common_vendor.ref([
  10. {
  11. name: "美的集团",
  12. code: "000333",
  13. price: "68.00",
  14. score: "88.5"
  15. },
  16. {
  17. name: "贵州茅台",
  18. code: "600519",
  19. price: "1700.00",
  20. score: "85.1"
  21. }
  22. ]);
  23. const selectedDate = common_vendor.ref("2025年11月20日");
  24. const showBuyModalFlag = common_vendor.ref(false);
  25. const showSellModalFlag = common_vendor.ref(false);
  26. const currentStock = common_vendor.ref({});
  27. const buyQuantity = common_vendor.ref("100");
  28. const sellQuantity = common_vendor.ref("100");
  29. const checkLogin = () => {
  30. isLoggedIn.value = utils_auth.isLoggedIn();
  31. console.log("[强势池] 登录状态:", isLoggedIn.value);
  32. };
  33. const goToLogin = () => {
  34. common_vendor.index.navigateTo({
  35. url: "/pages/login/login"
  36. });
  37. };
  38. const buyTotalAmount = common_vendor.computed(() => {
  39. const qty = parseInt(buyQuantity.value) || 0;
  40. const price = parseFloat(currentStock.value.price) || 0;
  41. return qty * price;
  42. });
  43. const sellTotalAmount = common_vendor.computed(() => {
  44. const qty = parseInt(sellQuantity.value) || 0;
  45. const price = parseFloat(currentStock.value.price) || 0;
  46. return qty * price;
  47. });
  48. const showBuyModal = (stock) => {
  49. console.log("点击买入按钮");
  50. currentStock.value = { ...stock };
  51. buyQuantity.value = "100";
  52. showBuyModalFlag.value = true;
  53. };
  54. const closeBuyModal = () => {
  55. showBuyModalFlag.value = false;
  56. };
  57. const showSellModal = (stock) => {
  58. console.log("点击卖出按钮");
  59. currentStock.value = { ...stock };
  60. sellQuantity.value = "100";
  61. showSellModalFlag.value = true;
  62. };
  63. const closeSellModal = () => {
  64. showSellModalFlag.value = false;
  65. };
  66. const onBuyQuantityChange = (e) => {
  67. const value = e.detail.value;
  68. if (value && parseInt(value) % 100 !== 0) {
  69. common_vendor.index.showToast({
  70. title: "股数必须是100的倍数",
  71. icon: "none"
  72. });
  73. }
  74. };
  75. const onSellQuantityChange = (e) => {
  76. const value = e.detail.value;
  77. if (value && parseInt(value) % 100 !== 0) {
  78. common_vendor.index.showToast({
  79. title: "股数必须是100的倍数",
  80. icon: "none"
  81. });
  82. }
  83. };
  84. const handleBuy = () => {
  85. const qty = parseInt(buyQuantity.value);
  86. if (!qty || qty <= 0) {
  87. common_vendor.index.showToast({
  88. title: "请输入有效的股数",
  89. icon: "none"
  90. });
  91. return;
  92. }
  93. if (qty % 100 !== 0) {
  94. common_vendor.index.showToast({
  95. title: "股数必须是100的倍数",
  96. icon: "none"
  97. });
  98. return;
  99. }
  100. const transaction = {
  101. type: "buy",
  102. stockName: currentStock.value.name,
  103. stockCode: currentStock.value.code,
  104. price: parseFloat(currentStock.value.price),
  105. quantity: qty,
  106. totalAmount: buyTotalAmount.value,
  107. timestamp: Date.now()
  108. };
  109. const transactions = common_vendor.index.getStorageSync("simulated_transactions") || [];
  110. transactions.push(transaction);
  111. common_vendor.index.setStorageSync("simulated_transactions", transactions);
  112. closeBuyModal();
  113. common_vendor.index.showToast({
  114. title: "买入成功",
  115. icon: "success"
  116. });
  117. };
  118. const handleSell = () => {
  119. const qty = parseInt(sellQuantity.value);
  120. if (!qty || qty <= 0) {
  121. common_vendor.index.showToast({
  122. title: "请输入有效的股数",
  123. icon: "none"
  124. });
  125. return;
  126. }
  127. if (qty % 100 !== 0) {
  128. common_vendor.index.showToast({
  129. title: "股数必须是100的倍数",
  130. icon: "none"
  131. });
  132. return;
  133. }
  134. const transaction = {
  135. type: "sell",
  136. stockName: currentStock.value.name,
  137. stockCode: currentStock.value.code,
  138. price: parseFloat(currentStock.value.price),
  139. quantity: qty,
  140. totalAmount: sellTotalAmount.value,
  141. timestamp: Date.now()
  142. };
  143. const transactions = common_vendor.index.getStorageSync("simulated_transactions") || [];
  144. transactions.push(transaction);
  145. common_vendor.index.setStorageSync("simulated_transactions", transactions);
  146. closeSellModal();
  147. common_vendor.index.showToast({
  148. title: "卖出成功",
  149. icon: "success"
  150. });
  151. };
  152. const onHistorySearch = () => {
  153. common_vendor.index.showToast({
  154. title: "历史查询功能开发中",
  155. icon: "none"
  156. });
  157. };
  158. common_vendor.onLoad(() => {
  159. checkLogin();
  160. });
  161. common_vendor.onShow(() => {
  162. checkLogin();
  163. common_vendor.index.setNavigationBarTitle({ title: "量化交易大师" });
  164. });
  165. return (_ctx, _cache) => {
  166. return common_vendor.e({
  167. a: common_vendor.t(stockList.value.length),
  168. b: common_vendor.f(stockList.value, (stock, index, i0) => {
  169. return {
  170. a: common_vendor.t(stock.name),
  171. b: common_vendor.t(stock.code),
  172. c: common_vendor.t(stock.price),
  173. d: common_vendor.t(stock.score),
  174. e: common_vendor.o(($event) => showBuyModal(stock), index),
  175. f: common_vendor.o(($event) => showSellModal(stock), index),
  176. g: index
  177. };
  178. }),
  179. c: selectedDate.value,
  180. d: common_vendor.o(($event) => selectedDate.value = $event.detail.value),
  181. e: common_vendor.o(onHistorySearch),
  182. f: !isLoggedIn.value ? 1 : "",
  183. g: !isLoggedIn.value
  184. }, !isLoggedIn.value ? {
  185. h: common_vendor.o(goToLogin)
  186. } : {}, {
  187. i: showBuyModalFlag.value
  188. }, showBuyModalFlag.value ? {
  189. j: common_vendor.o(closeBuyModal),
  190. k: common_vendor.t(currentStock.value.name),
  191. l: common_vendor.t(currentStock.value.code),
  192. m: common_vendor.t(currentStock.value.price),
  193. n: common_vendor.o([($event) => buyQuantity.value = $event.detail.value, onBuyQuantityChange]),
  194. o: buyQuantity.value,
  195. p: common_vendor.t(common_vendor.unref(buyTotalAmount).toFixed(2)),
  196. q: common_vendor.o(handleBuy),
  197. r: common_vendor.o(() => {
  198. }),
  199. s: common_vendor.o(closeBuyModal)
  200. } : {}, {
  201. t: showSellModalFlag.value
  202. }, showSellModalFlag.value ? {
  203. v: common_vendor.o(closeSellModal),
  204. w: common_vendor.t(currentStock.value.name),
  205. x: common_vendor.t(currentStock.value.code),
  206. y: common_vendor.t(currentStock.value.price),
  207. z: common_vendor.o([($event) => sellQuantity.value = $event.detail.value, onSellQuantityChange]),
  208. A: sellQuantity.value,
  209. B: common_vendor.t(common_vendor.unref(sellTotalAmount).toFixed(2)),
  210. C: common_vendor.o(handleSell),
  211. D: common_vendor.o(() => {
  212. }),
  213. E: common_vendor.o(closeSellModal)
  214. } : {});
  215. };
  216. }
  217. };
  218. const MiniProgramPage = /* @__PURE__ */ common_vendor._export_sfc(_sfc_main, [["__file", "D:/program/gupiao-wx/src/pages/strong/strong.vue"]]);
  219. wx.createPage(MiniProgramPage);