| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242 |
- "use strict";
- const common_vendor = require("../../common/vendor.js");
- const utils_auth = require("../../utils/auth.js");
- require("../../utils/api.js");
- const _sfc_main = {
- __name: "strong",
- setup(__props) {
- const isLoggedIn = common_vendor.ref(false);
- const stockList = common_vendor.ref([
- {
- name: "美的集团",
- code: "000333",
- price: "68.00",
- score: "88.5"
- },
- {
- name: "贵州茅台",
- code: "600519",
- price: "1700.00",
- score: "85.1"
- }
- ]);
- const selectedDate = common_vendor.ref("2025年11月20日");
- const showBuyModalFlag = common_vendor.ref(false);
- const checkLogin = () => {
- isLoggedIn.value = utils_auth.isLoggedIn();
- console.log("[强势池] 登录状态:", isLoggedIn.value);
- };
- const onGetPhoneNumber = async (e) => {
- console.log("[强势池] 获取手机号回调:", e.detail);
- if (e.detail.errMsg === "getPhoneNumber:ok") {
- const phoneCode = e.detail.code;
- console.log("[强势池] phoneCode:", phoneCode);
- common_vendor.index.showLoading({
- title: "登录中...",
- mask: true
- });
- try {
- const loginRes = await common_vendor.index.login();
- console.log("[强势池] uni.login完整响应:", loginRes);
- console.log("[强势池] 微信登录code:", loginRes.code);
- if (!loginRes.code) {
- throw new Error("获取微信登录code失败");
- }
- const result = await utils_auth.wxAuthLogin(loginRes.code, phoneCode);
- common_vendor.index.hideLoading();
- if (result) {
- checkLogin();
- }
- } catch (error) {
- common_vendor.index.hideLoading();
- console.error("[强势池] 登录失败:", error);
- }
- } else {
- common_vendor.index.showToast({
- title: "需要授权手机号才能登录",
- icon: "none",
- duration: 2e3
- });
- }
- };
- const buyTotalAmount = common_vendor.computed(() => {
- const qty = parseInt(buyQuantity.value) || 0;
- const price = parseFloat(currentStock.value.price) || 0;
- return qty * price;
- });
- const sellTotalAmount = common_vendor.computed(() => {
- const qty = parseInt(sellQuantity.value) || 0;
- const price = parseFloat(currentStock.value.price) || 0;
- return qty * price;
- });
- const showBuyModal = (stock) => {
- console.log("点击买入按钮");
- currentStock.value = { ...stock };
- buyQuantity.value = "100";
- showBuyModalFlag.value = true;
- };
- const closeBuyModal = () => {
- showBuyModalFlag.value = false;
- };
- const showSellModal = (stock) => {
- console.log("点击卖出按钮");
- currentStock.value = { ...stock };
- sellQuantity.value = "100";
- showSellModalFlag.value = true;
- };
- const closeSellModal = () => {
- showSellModalFlag.value = false;
- };
- const onBuyQuantityChange = (e) => {
- const value = e.detail.value;
- if (value && parseInt(value) % 100 !== 0) {
- common_vendor.index.showToast({
- title: "股数必须是100的倍数",
- icon: "none"
- });
- }
- };
- const onSellQuantityChange = (e) => {
- const value = e.detail.value;
- if (value && parseInt(value) % 100 !== 0) {
- common_vendor.index.showToast({
- title: "股数必须是100的倍数",
- icon: "none"
- });
- }
- };
- const handleBuy = () => {
- const qty = parseInt(buyQuantity.value);
- if (!qty || qty <= 0) {
- common_vendor.index.showToast({
- title: "请输入有效的股数",
- icon: "none"
- });
- return;
- }
- if (qty % 100 !== 0) {
- common_vendor.index.showToast({
- title: "股数必须是100的倍数",
- icon: "none"
- });
- return;
- }
- const transaction = {
- type: "buy",
- stockName: currentStock.value.name,
- stockCode: currentStock.value.code,
- price: parseFloat(currentStock.value.price),
- quantity: qty,
- totalAmount: buyTotalAmount.value,
- timestamp: Date.now()
- };
- const transactions = common_vendor.index.getStorageSync("simulated_transactions") || [];
- transactions.push(transaction);
- common_vendor.index.setStorageSync("simulated_transactions", transactions);
- closeBuyModal();
- common_vendor.index.showToast({
- title: "买入成功",
- icon: "success"
- });
- };
- const handleSell = () => {
- const qty = parseInt(sellQuantity.value);
- if (!qty || qty <= 0) {
- common_vendor.index.showToast({
- title: "请输入有效的股数",
- icon: "none"
- });
- return;
- }
- if (qty % 100 !== 0) {
- common_vendor.index.showToast({
- title: "股数必须是100的倍数",
- icon: "none"
- });
- return;
- }
- const transaction = {
- type: "sell",
- stockName: currentStock.value.name,
- stockCode: currentStock.value.code,
- price: parseFloat(currentStock.value.price),
- quantity: qty,
- totalAmount: sellTotalAmount.value,
- timestamp: Date.now()
- };
- const transactions = common_vendor.index.getStorageSync("simulated_transactions") || [];
- transactions.push(transaction);
- common_vendor.index.setStorageSync("simulated_transactions", transactions);
- closeSellModal();
- common_vendor.index.showToast({
- title: "卖出成功",
- icon: "success"
- });
- };
- const onHistorySearch = () => {
- common_vendor.index.showToast({
- title: "历史查询功能开发中",
- icon: "none"
- });
- };
- common_vendor.onLoad(() => {
- checkLogin();
- });
- common_vendor.onShow(() => {
- checkLogin();
- });
- return (_ctx, _cache) => {
- return common_vendor.e({
- a: common_vendor.t(stockList.value.length),
- b: common_vendor.f(stockList.value, (stock, index, i0) => {
- return {
- a: common_vendor.t(stock.name),
- b: common_vendor.t(stock.code),
- c: common_vendor.t(stock.price),
- d: common_vendor.t(stock.score),
- e: common_vendor.o(($event) => showBuyModal(stock), index),
- f: common_vendor.o(($event) => showSellModal(stock), index),
- g: index
- };
- }),
- c: selectedDate.value,
- d: common_vendor.o(($event) => selectedDate.value = $event.detail.value),
- e: common_vendor.o(onHistorySearch),
- f: !isLoggedIn.value ? 1 : "",
- g: !isLoggedIn.value
- }, !isLoggedIn.value ? {
- h: common_vendor.o(onGetPhoneNumber)
- } : {}, {
- i: showBuyModalFlag.value
- }, showBuyModalFlag.value ? {
- j: common_vendor.o(closeBuyModal),
- k: common_vendor.t(_ctx.currentStock.name),
- l: common_vendor.t(_ctx.currentStock.code),
- m: common_vendor.t(_ctx.currentStock.price),
- n: common_vendor.o([($event) => _ctx.buyQuantity = $event.detail.value, onBuyQuantityChange]),
- o: _ctx.buyQuantity,
- p: common_vendor.t(common_vendor.unref(buyTotalAmount).toFixed(2)),
- q: common_vendor.o(handleBuy),
- r: common_vendor.o(() => {
- }),
- s: common_vendor.o(closeBuyModal)
- } : {}, {
- t: _ctx.showSellModalFlag
- }, _ctx.showSellModalFlag ? {
- v: common_vendor.o(closeSellModal),
- w: common_vendor.t(_ctx.currentStock.name),
- x: common_vendor.t(_ctx.currentStock.code),
- y: common_vendor.t(_ctx.currentStock.price),
- z: common_vendor.o([($event) => _ctx.sellQuantity = $event.detail.value, onSellQuantityChange]),
- A: _ctx.sellQuantity,
- B: common_vendor.t(common_vendor.unref(sellTotalAmount).toFixed(2)),
- C: common_vendor.o(handleSell),
- D: common_vendor.o(() => {
- }),
- E: common_vendor.o(closeSellModal)
- } : {});
- };
- }
- };
- const MiniProgramPage = /* @__PURE__ */ common_vendor._export_sfc(_sfc_main, [["__file", "D:/program/gupiao-wx/src/pages/strong/strong.vue"]]);
- wx.createPage(MiniProgramPage);
|