fiee-official-website/src/store/stock-quote/index.js

63 lines
1.5 KiB
JavaScript
Raw Normal View History

import { ref } from 'vue'
import { createGlobalState, useLocalStorage } from '@vueuse/core'
import axios from 'axios'
2025-05-26 07:13:40 +00:00
import dayjs from 'dayjs'
import utc from 'dayjs/plugin/utc'
import timezone from 'dayjs/plugin/timezone'
export const useStockQuote = createGlobalState(() => {
const stockQuote = useLocalStorage('stockQuote', {
"Open": "",
"Volume": "",
"DayRange": "",
"WeekRange": "",
"MarketCap": "",
"change": [
"",
""
]
})
2025-05-26 07:13:40 +00:00
const date = new Date();
const options = {
year: 'numeric',
month: 'short',
day: 'numeric',
hour: 'numeric',
minute: '2-digit',
hour12: true,
timeZone: 'America/New_York',
timeZoneName: 'short'
};
2025-05-26 07:13:40 +00:00
dayjs.extend(utc)
dayjs.extend(timezone)
2025-05-26 06:12:54 +00:00
2025-05-26 07:13:40 +00:00
const getFormattedFriday = () => {
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
} else {
// 上周五16:00
showFriday = thisFriday.subtract(7, 'day')
2025-05-26 06:12:54 +00:00
}
2025-05-26 07:13:40 +00:00
return showFriday.format('MMM D, YYYY, h:mm A [EDT]')
}
2025-05-26 06:12:54 +00:00
2025-05-26 07:13:40 +00:00
const formatted = ref(getFormattedFriday())
const getStockQuate= async()=>{
const res = await axios.get('https://saas-test.szjixun.cn/api/chart/forward/test')
stockQuote.value=res.data
2025-05-26 07:13:40 +00:00
}
return {
formatted,
getStockQuate,
stockQuote
}
})