strong.js 7.9 KB

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