| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150 |
- "use strict";
- const common_vendor = require("../../common/vendor.js");
- const utils_auth = require("../../utils/auth.js");
- const utils_api = require("../../utils/api.js");
- if (!Math) {
- HistorySearchCard();
- }
- const HistorySearchCard = () => "../../components/HistorySearchCard.js";
- const _sfc_main = {
- __name: "strong",
- setup(__props) {
- const isPageVisible = common_vendor.ref(false);
- const stockList = common_vendor.ref([]);
- let refreshTimer = null;
- const getChangeClass = (changePercent) => {
- if (!changePercent || changePercent === "-")
- return "";
- return changePercent.startsWith("+") ? "text-red" : "text-green";
- };
- const getRandomInterval = () => 4500 + Math.random() * 1e3;
- const startAutoRefresh = () => {
- if (!isPageVisible.value)
- return;
- stopAutoRefresh();
- const scheduleNextRefresh = () => {
- if (!isPageVisible.value) {
- stopAutoRefresh();
- return;
- }
- refreshTimer = setTimeout(async () => {
- if (!isPageVisible.value) {
- stopAutoRefresh();
- return;
- }
- await loadStockPool();
- scheduleNextRefresh();
- }, getRandomInterval());
- };
- scheduleNextRefresh();
- };
- const stopAutoRefresh = () => {
- if (refreshTimer) {
- clearTimeout(refreshTimer);
- refreshTimer = null;
- }
- };
- const loadStockPool = async () => {
- try {
- const res = await utils_api.getStockPoolList(2);
- if (res.code === 200 && res.data) {
- stockList.value = res.data;
- }
- } catch (e) {
- console.error("加载股票池失败:", e);
- }
- };
- const loadAndStartRefresh = async () => {
- await loadStockPool();
- startAutoRefresh();
- };
- const addToMyStocks = async (stock) => {
- if (!utils_auth.isLoggedIn()) {
- common_vendor.index.showModal({
- title: "登录提示",
- content: "此功能需要登录后使用,是否前往登录?",
- confirmText: "去登录",
- cancelText: "取消",
- success: (res) => {
- if (res.confirm) {
- common_vendor.index.navigateTo({ url: "/pages/login/login" });
- }
- }
- });
- return;
- }
- try {
- common_vendor.index.showLoading({ title: "添加中..." });
- let currentPrice = null;
- try {
- const quoteRes = await utils_api.getStockQuotes(stock.code);
- if (quoteRes.code === 200 && quoteRes.data && quoteRes.data.length > 0) {
- currentPrice = quoteRes.data[0].currentPrice;
- }
- } catch (e) {
- console.error("获取行情数据失败:", e);
- }
- const addRes = await utils_api.addUserStock({
- stockCode: stock.code,
- stockName: stock.name,
- currentPrice,
- poolType: 2
- // 强势池
- });
- common_vendor.index.hideLoading();
- if (addRes.code === 200 && addRes.data === true) {
- common_vendor.index.showToast({ title: "添加成功", icon: "success" });
- } else if (addRes.code === 200 && addRes.data === false) {
- common_vendor.index.showToast({ title: "样本已存在", icon: "none" });
- } else {
- common_vendor.index.showToast({ title: addRes.message || "添加失败", icon: "none" });
- }
- } catch (e) {
- common_vendor.index.hideLoading();
- console.error("添加样本失败:", e);
- common_vendor.index.showToast({ title: "添加失败", icon: "none" });
- }
- };
- common_vendor.onLoad(() => {
- console.log("[强势池] onLoad");
- isPageVisible.value = true;
- loadAndStartRefresh();
- });
- common_vendor.onShow(() => {
- console.log("[强势池] onShow");
- isPageVisible.value = true;
- loadAndStartRefresh();
- common_vendor.index.setNavigationBarTitle({ title: "量化交易大师" });
- });
- common_vendor.onHide(() => {
- console.log("[强势池] onHide");
- isPageVisible.value = false;
- stopAutoRefresh();
- });
- common_vendor.onUnmounted(() => {
- isPageVisible.value = false;
- stopAutoRefresh();
- });
- return (_ctx, _cache) => {
- return {
- a: 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.currentPrice || "-"),
- d: common_vendor.t(stock.changePercent || "-"),
- e: common_vendor.n(getChangeClass(stock.changePercent)),
- f: common_vendor.o(($event) => addToMyStocks(stock), index),
- g: index
- };
- }),
- b: common_vendor.p({
- poolType: 2,
- canSearch: true
- })
- };
- };
- }
- };
- const MiniProgramPage = /* @__PURE__ */ common_vendor._export_sfc(_sfc_main, [["__file", "D:/program/gupiao/gupiao-wx/src/pages/strong/strong.vue"]]);
- wx.createPage(MiniProgramPage);
|