From c4b11ec76a9790b564f3f091a40907f3c889bc31 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=BD=90=E6=96=8C?= <1134087124@qq.com> Date: Wed, 28 May 2025 15:07:00 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B0=E8=82=A1=E7=A5=A8=E4=BA=A4?= =?UTF-8?q?=E6=98=93=E6=97=A5=E8=AE=A1=E7=AE=97=E9=80=BB=E8=BE=91=EF=BC=8C?= =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E8=8E=B7=E5=8F=96=E8=82=A1=E7=A5=A8=E6=95=B0?= =?UTF-8?q?=E6=8D=AE=E7=9A=84API=E5=9C=B0=E5=9D=80=EF=BC=8C=E5=B9=B6?= =?UTF-8?q?=E7=BB=9F=E4=B8=80=E4=BF=AE=E6=94=B9=E9=A1=B5=E9=9D=A2=E6=95=B0?= =?UTF-8?q?=E6=8D=AE=E8=8E=B7=E5=8F=96=E5=87=BD=E6=95=B0=E5=90=8D=E7=A7=B0?= =?UTF-8?q?=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/store/stock-quote/index.js | 46 ++++++++++++++------- src/views/historic-stock/size1440/index.vue | 2 +- src/views/historic-stock/size1920/index.vue | 4 +- src/views/historic-stock/size375/index.vue | 2 +- src/views/historic-stock/size768/index.vue | 2 +- 5 files changed, 36 insertions(+), 20 deletions(-) diff --git a/src/store/stock-quote/index.js b/src/store/stock-quote/index.js index ea2434b..62e88a4 100644 --- a/src/store/stock-quote/index.js +++ b/src/store/stock-quote/index.js @@ -31,27 +31,43 @@ const options = { dayjs.extend(utc) dayjs.extend(timezone) - -const getFormattedFriday = () => { +/* +美股的常规发行日(交易日)为周一至周五,遇到法定假日则顺延。 +如果你只需要“上一个交易日”(不考虑法定假日),可以这样实现: +获取当前美东时间。 +如果今天是周一,则上一个交易日为上周五。 +如果今天是周日,则上一个交易日为上周五。 +如果今天是周六,则上一个交易日为周五。 +其他情况,上一个交易日为昨天。 +*/ +const getLastTradingDay = () => { const now = dayjs().tz('America/New_York') - // 本周五16:00 - const thisFriday = now.day() >= 5 - ? now.day(5).hour(16).minute(0).second(0).millisecond(0) - : now.day(5 - 7).hour(16).minute(0).second(0).millisecond(0) - // 判断当前是否已到本周五16:00 - let showFriday - if (now.isAfter(thisFriday)) { - showFriday = thisFriday + let lastTradingDay + const dayOfWeek = now.day() // 0:周日, 1:周一, ..., 5:周五, 6:周六 + const isBeforeClose = now.hour() < 16 || (now.hour() === 16 && now.minute() === 0 && now.second() === 0) + + if (dayOfWeek === 0) { // 周日 + // 返回本周五16:00 + lastTradingDay = now.day(-2).hour(16).minute(0).second(0).millisecond(0) + } else if (dayOfWeek === 6) { // 周六 + // 返回本周五16:00 + lastTradingDay = now.day(-1).hour(16).minute(0).second(0).millisecond(0) + } else if (dayOfWeek === 1 && isBeforeClose) { // 周一16:00前 + // 返回上周五16:00 + lastTradingDay = now.day(-2).hour(16).minute(0).second(0).millisecond(0) + } else if (isBeforeClose) { // 工作日16:00前 + // 返回前一天16:00 + lastTradingDay = now.subtract(1, 'day').hour(16).minute(0).second(0).millisecond(0) } else { - // 上周五16:00 - showFriday = thisFriday.subtract(7, 'day') + // 工作日16:00后,返回今天16:00 + lastTradingDay = now.hour(16).minute(0).second(0).millisecond(0) } - return showFriday.format('MMM D, YYYY, h:mm A [EDT]') + return lastTradingDay.format('MMM D, YYYY, h:mm A [EDT]') } -const formatted = ref(getFormattedFriday()) +const formatted = ref(getLastTradingDay()) const getStockQuate= async()=>{ - const res = await axios.get('https://saas-test.szjixun.cn/api/chart/forward/test') + const res = await axios.get('https://saas-test.szjixun.cn/api/fiee/chart/forward/test') stockQuote.value=res.data } return { diff --git a/src/views/historic-stock/size1440/index.vue b/src/views/historic-stock/size1440/index.vue index 30a6200..ebd8e56 100644 --- a/src/views/historic-stock/size1440/index.vue +++ b/src/views/historic-stock/size1440/index.vue @@ -249,7 +249,7 @@ const scrollToTop = () => { }); }; onMounted(() => { - getPageDefaultData(); + getPageData(); }); const getPageDefaultData = async () => { diff --git a/src/views/historic-stock/size1920/index.vue b/src/views/historic-stock/size1920/index.vue index 30a6200..808c11f 100644 --- a/src/views/historic-stock/size1920/index.vue +++ b/src/views/historic-stock/size1920/index.vue @@ -249,13 +249,13 @@ const scrollToTop = () => { }); }; onMounted(() => { - getPageDefaultData(); + getPageData(); }); const getPageDefaultData = async () => { try { let url = - "https://stockanalysis.com/api/symbol/a/OTC-MINM/history?type=chart"; + "https://stockanalysis.com/api/symbol/a/OTC-MINM/history?period=Daily&range=3M"; const res = await axios.get(url); let originalData = res.data.data; diff --git a/src/views/historic-stock/size375/index.vue b/src/views/historic-stock/size375/index.vue index 724a03e..4afbbe1 100644 --- a/src/views/historic-stock/size375/index.vue +++ b/src/views/historic-stock/size375/index.vue @@ -248,7 +248,7 @@ const scrollToTop = () => { }); }; onMounted(() => { - getPageDefaultData(); + getPageData(); }); const getPageDefaultData = async () => { diff --git a/src/views/historic-stock/size768/index.vue b/src/views/historic-stock/size768/index.vue index 7c420be..9310d1a 100644 --- a/src/views/historic-stock/size768/index.vue +++ b/src/views/historic-stock/size768/index.vue @@ -249,7 +249,7 @@ const scrollToTop = () => { }); }; onMounted(() => { - getPageDefaultData(); + getPageData(); }); const getPageDefaultData = async () => {