|
|
@@ -12,6 +12,7 @@ const _sfc_main = {
|
|
|
const lastLoadTime = common_vendor.ref(0);
|
|
|
const CACHE_DURATION = 5e3;
|
|
|
const isPageVisible = common_vendor.ref(false);
|
|
|
+ const getRandomInterval = () => 2e3 + Math.random() * 1e3;
|
|
|
const SLIDE_WIDTH = 100;
|
|
|
const slideStates = common_vendor.reactive({});
|
|
|
let slideTimers = {};
|
|
|
@@ -75,7 +76,8 @@ const _sfc_main = {
|
|
|
priceChange: null,
|
|
|
changePercent: null
|
|
|
});
|
|
|
- let refreshTimer = null;
|
|
|
+ let priceRefreshTimer = null;
|
|
|
+ let trendRefreshTimer = null;
|
|
|
const fetchIndexData = async () => {
|
|
|
try {
|
|
|
const res = await utils_api.getIndexQuote("000001");
|
|
|
@@ -338,6 +340,36 @@ const _sfc_main = {
|
|
|
isLoading.value = false;
|
|
|
}
|
|
|
};
|
|
|
+ const refreshPriceOnly = async () => {
|
|
|
+ if (myStocks.value.length === 0)
|
|
|
+ return;
|
|
|
+ try {
|
|
|
+ const codes = myStocks.value.map((stock) => stock.code).join(",");
|
|
|
+ const quoteRes = await utils_api.getStockQuotes(codes);
|
|
|
+ if (quoteRes.code === 200 && quoteRes.data && quoteRes.data.length > 0) {
|
|
|
+ quoteRes.data.forEach((quoteData) => {
|
|
|
+ const index = myStocks.value.findIndex((stock) => stock.code === quoteData.stockCode);
|
|
|
+ if (index !== -1) {
|
|
|
+ const stock = myStocks.value[index];
|
|
|
+ stock.priceChange = quoteData.priceChange;
|
|
|
+ stock.changePercent = quoteData.changePercent;
|
|
|
+ stock.currentPrice = quoteData.currentPrice;
|
|
|
+ stock.name = quoteData.stockName || stock.name;
|
|
|
+ if (stock.addPrice && quoteData.currentPrice) {
|
|
|
+ const addPrice = parseFloat(stock.addPrice);
|
|
|
+ const currentPrice = parseFloat(quoteData.currentPrice);
|
|
|
+ if (addPrice > 0) {
|
|
|
+ const profit = ((currentPrice - addPrice) / addPrice * 100).toFixed(2);
|
|
|
+ stock.profitPercent = profit >= 0 ? `+${profit}%` : `${profit}%`;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+ } catch (e) {
|
|
|
+ console.error("[我的股票] 价格刷新异常:", e.message);
|
|
|
+ }
|
|
|
+ };
|
|
|
const refreshAllQuotes = async () => {
|
|
|
if (myStocks.value.length === 0)
|
|
|
return;
|
|
|
@@ -373,31 +405,51 @@ const _sfc_main = {
|
|
|
if (!isLoggedIn.value || !isPageVisible.value)
|
|
|
return;
|
|
|
stopAutoRefresh();
|
|
|
- const scheduleNextRefresh = () => {
|
|
|
+ const schedulePriceRefresh = () => {
|
|
|
if (!isPageVisible.value) {
|
|
|
stopAutoRefresh();
|
|
|
return;
|
|
|
}
|
|
|
- const delay = 1e4;
|
|
|
- refreshTimer = setTimeout(async () => {
|
|
|
+ priceRefreshTimer = setTimeout(async () => {
|
|
|
if (!isPageVisible.value) {
|
|
|
stopAutoRefresh();
|
|
|
return;
|
|
|
}
|
|
|
await fetchIndexData();
|
|
|
+ if (myStocks.value.length > 0) {
|
|
|
+ await refreshPriceOnly();
|
|
|
+ }
|
|
|
+ schedulePriceRefresh();
|
|
|
+ }, getRandomInterval());
|
|
|
+ };
|
|
|
+ const scheduleTrendRefresh = () => {
|
|
|
+ if (!isPageVisible.value) {
|
|
|
+ stopAutoRefresh();
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ trendRefreshTimer = setTimeout(async () => {
|
|
|
+ if (!isPageVisible.value) {
|
|
|
+ stopAutoRefresh();
|
|
|
+ return;
|
|
|
+ }
|
|
|
if (myStocks.value.length > 0) {
|
|
|
await refreshAllQuotes();
|
|
|
drawAllTrendCharts();
|
|
|
}
|
|
|
- scheduleNextRefresh();
|
|
|
- }, delay);
|
|
|
+ scheduleTrendRefresh();
|
|
|
+ }, 1e4);
|
|
|
};
|
|
|
- scheduleNextRefresh();
|
|
|
+ schedulePriceRefresh();
|
|
|
+ scheduleTrendRefresh();
|
|
|
};
|
|
|
const stopAutoRefresh = () => {
|
|
|
- if (refreshTimer) {
|
|
|
- clearTimeout(refreshTimer);
|
|
|
- refreshTimer = null;
|
|
|
+ if (priceRefreshTimer) {
|
|
|
+ clearTimeout(priceRefreshTimer);
|
|
|
+ priceRefreshTimer = null;
|
|
|
+ }
|
|
|
+ if (trendRefreshTimer) {
|
|
|
+ clearTimeout(trendRefreshTimer);
|
|
|
+ trendRefreshTimer = null;
|
|
|
}
|
|
|
};
|
|
|
const goToLogin = () => {
|