strong.js 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242
  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 checkLogin = () => {
  26. isLoggedIn.value = utils_auth.isLoggedIn();
  27. console.log("[强势池] 登录状态:", isLoggedIn.value);
  28. };
  29. const onGetPhoneNumber = async (e) => {
  30. console.log("[强势池] 获取手机号回调:", e.detail);
  31. if (e.detail.errMsg === "getPhoneNumber:ok") {
  32. const phoneCode = e.detail.code;
  33. console.log("[强势池] phoneCode:", phoneCode);
  34. common_vendor.index.showLoading({
  35. title: "登录中...",
  36. mask: true
  37. });
  38. try {
  39. const loginRes = await common_vendor.index.login();
  40. console.log("[强势池] uni.login完整响应:", loginRes);
  41. console.log("[强势池] 微信登录code:", loginRes.code);
  42. if (!loginRes.code) {
  43. throw new Error("获取微信登录code失败");
  44. }
  45. const result = await utils_auth.wxAuthLogin(loginRes.code, phoneCode);
  46. common_vendor.index.hideLoading();
  47. if (result) {
  48. checkLogin();
  49. }
  50. } catch (error) {
  51. common_vendor.index.hideLoading();
  52. console.error("[强势池] 登录失败:", error);
  53. }
  54. } else {
  55. common_vendor.index.showToast({
  56. title: "需要授权手机号才能登录",
  57. icon: "none",
  58. duration: 2e3
  59. });
  60. }
  61. };
  62. const buyTotalAmount = common_vendor.computed(() => {
  63. const qty = parseInt(buyQuantity.value) || 0;
  64. const price = parseFloat(currentStock.value.price) || 0;
  65. return qty * price;
  66. });
  67. const sellTotalAmount = common_vendor.computed(() => {
  68. const qty = parseInt(sellQuantity.value) || 0;
  69. const price = parseFloat(currentStock.value.price) || 0;
  70. return qty * price;
  71. });
  72. const showBuyModal = (stock) => {
  73. console.log("点击买入按钮");
  74. currentStock.value = { ...stock };
  75. buyQuantity.value = "100";
  76. showBuyModalFlag.value = true;
  77. };
  78. const closeBuyModal = () => {
  79. showBuyModalFlag.value = false;
  80. };
  81. const showSellModal = (stock) => {
  82. console.log("点击卖出按钮");
  83. currentStock.value = { ...stock };
  84. sellQuantity.value = "100";
  85. showSellModalFlag.value = true;
  86. };
  87. const closeSellModal = () => {
  88. showSellModalFlag.value = false;
  89. };
  90. const onBuyQuantityChange = (e) => {
  91. const value = e.detail.value;
  92. if (value && parseInt(value) % 100 !== 0) {
  93. common_vendor.index.showToast({
  94. title: "股数必须是100的倍数",
  95. icon: "none"
  96. });
  97. }
  98. };
  99. const onSellQuantityChange = (e) => {
  100. const value = e.detail.value;
  101. if (value && parseInt(value) % 100 !== 0) {
  102. common_vendor.index.showToast({
  103. title: "股数必须是100的倍数",
  104. icon: "none"
  105. });
  106. }
  107. };
  108. const handleBuy = () => {
  109. const qty = parseInt(buyQuantity.value);
  110. if (!qty || qty <= 0) {
  111. common_vendor.index.showToast({
  112. title: "请输入有效的股数",
  113. icon: "none"
  114. });
  115. return;
  116. }
  117. if (qty % 100 !== 0) {
  118. common_vendor.index.showToast({
  119. title: "股数必须是100的倍数",
  120. icon: "none"
  121. });
  122. return;
  123. }
  124. const transaction = {
  125. type: "buy",
  126. stockName: currentStock.value.name,
  127. stockCode: currentStock.value.code,
  128. price: parseFloat(currentStock.value.price),
  129. quantity: qty,
  130. totalAmount: buyTotalAmount.value,
  131. timestamp: Date.now()
  132. };
  133. const transactions = common_vendor.index.getStorageSync("simulated_transactions") || [];
  134. transactions.push(transaction);
  135. common_vendor.index.setStorageSync("simulated_transactions", transactions);
  136. closeBuyModal();
  137. common_vendor.index.showToast({
  138. title: "买入成功",
  139. icon: "success"
  140. });
  141. };
  142. const handleSell = () => {
  143. const qty = parseInt(sellQuantity.value);
  144. if (!qty || qty <= 0) {
  145. common_vendor.index.showToast({
  146. title: "请输入有效的股数",
  147. icon: "none"
  148. });
  149. return;
  150. }
  151. if (qty % 100 !== 0) {
  152. common_vendor.index.showToast({
  153. title: "股数必须是100的倍数",
  154. icon: "none"
  155. });
  156. return;
  157. }
  158. const transaction = {
  159. type: "sell",
  160. stockName: currentStock.value.name,
  161. stockCode: currentStock.value.code,
  162. price: parseFloat(currentStock.value.price),
  163. quantity: qty,
  164. totalAmount: sellTotalAmount.value,
  165. timestamp: Date.now()
  166. };
  167. const transactions = common_vendor.index.getStorageSync("simulated_transactions") || [];
  168. transactions.push(transaction);
  169. common_vendor.index.setStorageSync("simulated_transactions", transactions);
  170. closeSellModal();
  171. common_vendor.index.showToast({
  172. title: "卖出成功",
  173. icon: "success"
  174. });
  175. };
  176. const onHistorySearch = () => {
  177. common_vendor.index.showToast({
  178. title: "历史查询功能开发中",
  179. icon: "none"
  180. });
  181. };
  182. common_vendor.onLoad(() => {
  183. checkLogin();
  184. });
  185. common_vendor.onShow(() => {
  186. checkLogin();
  187. });
  188. return (_ctx, _cache) => {
  189. return common_vendor.e({
  190. a: common_vendor.t(stockList.value.length),
  191. b: common_vendor.f(stockList.value, (stock, index, i0) => {
  192. return {
  193. a: common_vendor.t(stock.name),
  194. b: common_vendor.t(stock.code),
  195. c: common_vendor.t(stock.price),
  196. d: common_vendor.t(stock.score),
  197. e: common_vendor.o(($event) => showBuyModal(stock), index),
  198. f: common_vendor.o(($event) => showSellModal(stock), index),
  199. g: index
  200. };
  201. }),
  202. c: selectedDate.value,
  203. d: common_vendor.o(($event) => selectedDate.value = $event.detail.value),
  204. e: common_vendor.o(onHistorySearch),
  205. f: !isLoggedIn.value ? 1 : "",
  206. g: !isLoggedIn.value
  207. }, !isLoggedIn.value ? {
  208. h: common_vendor.o(onGetPhoneNumber)
  209. } : {}, {
  210. i: showBuyModalFlag.value
  211. }, showBuyModalFlag.value ? {
  212. j: common_vendor.o(closeBuyModal),
  213. k: common_vendor.t(_ctx.currentStock.name),
  214. l: common_vendor.t(_ctx.currentStock.code),
  215. m: common_vendor.t(_ctx.currentStock.price),
  216. n: common_vendor.o([($event) => _ctx.buyQuantity = $event.detail.value, onBuyQuantityChange]),
  217. o: _ctx.buyQuantity,
  218. p: common_vendor.t(common_vendor.unref(buyTotalAmount).toFixed(2)),
  219. q: common_vendor.o(handleBuy),
  220. r: common_vendor.o(() => {
  221. }),
  222. s: common_vendor.o(closeBuyModal)
  223. } : {}, {
  224. t: _ctx.showSellModalFlag
  225. }, _ctx.showSellModalFlag ? {
  226. v: common_vendor.o(closeSellModal),
  227. w: common_vendor.t(_ctx.currentStock.name),
  228. x: common_vendor.t(_ctx.currentStock.code),
  229. y: common_vendor.t(_ctx.currentStock.price),
  230. z: common_vendor.o([($event) => _ctx.sellQuantity = $event.detail.value, onSellQuantityChange]),
  231. A: _ctx.sellQuantity,
  232. B: common_vendor.t(common_vendor.unref(sellTotalAmount).toFixed(2)),
  233. C: common_vendor.o(handleSell),
  234. D: common_vendor.o(() => {
  235. }),
  236. E: common_vendor.o(closeSellModal)
  237. } : {});
  238. };
  239. }
  240. };
  241. const MiniProgramPage = /* @__PURE__ */ common_vendor._export_sfc(_sfc_main, [["__file", "D:/program/gupiao-wx/src/pages/strong/strong.vue"]]);
  242. wx.createPage(MiniProgramPage);