2025-05-23 01:37:30 +00:00
|
|
|
|
import { ref } from 'vue'
|
|
|
|
|
import { createGlobalState, useLocalStorage } from '@vueuse/core'
|
|
|
|
|
import axios from 'axios'
|
2025-05-23 02:39:23 +00:00
|
|
|
|
|
2025-05-23 01:37:30 +00:00
|
|
|
|
export const useStockQuote = createGlobalState(() => {
|
2025-05-23 02:39:23 +00:00
|
|
|
|
const stockQuote = useLocalStorage('stockQuote', {
|
|
|
|
|
"Open": "",
|
|
|
|
|
"Volume": "",
|
|
|
|
|
"DayRange": "",
|
|
|
|
|
"WeekRange": "",
|
|
|
|
|
"MarketCap": "",
|
|
|
|
|
"change": [
|
|
|
|
|
"",
|
|
|
|
|
""
|
|
|
|
|
]
|
|
|
|
|
})
|
2025-05-23 12:21:14 +00:00
|
|
|
|
|
2025-05-26 06:12:54 +00:00
|
|
|
|
// 计算美东时间的当前时间
|
|
|
|
|
function getTargetFridayTime() {
|
|
|
|
|
// 当前美东时间
|
|
|
|
|
const now = new Date(new Date().toLocaleString('en-US', { timeZone: 'America/New_York' }))
|
|
|
|
|
// 获取今天是周几(0=周日, 1=周一, ..., 5=周五, 6=周六)
|
|
|
|
|
const day = now.getDay()
|
|
|
|
|
// 计算本周五的日期
|
|
|
|
|
const diffToFriday = 5 - day
|
|
|
|
|
const thisFriday = new Date(now)
|
|
|
|
|
thisFriday.setDate(now.getDate() + diffToFriday)
|
|
|
|
|
thisFriday.setHours(16, 0, 0, 0) // 设置为16:00:00
|
|
|
|
|
|
|
|
|
|
if (now >= thisFriday) {
|
|
|
|
|
// 当前时间在本周五16:00及以后,显示本周五16:00
|
|
|
|
|
return thisFriday
|
|
|
|
|
} else {
|
|
|
|
|
// 当前时间早于本周五16:00,显示上周五16:00
|
|
|
|
|
const lastFriday = new Date(thisFriday)
|
|
|
|
|
lastFriday.setDate(thisFriday.getDate() - 7)
|
|
|
|
|
return lastFriday
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const options = {
|
|
|
|
|
year: 'numeric',
|
|
|
|
|
month: 'short',
|
|
|
|
|
day: 'numeric',
|
|
|
|
|
hour: 'numeric',
|
|
|
|
|
minute: '2-digit',
|
|
|
|
|
hour12: true,
|
|
|
|
|
timeZone: 'America/New_York',
|
|
|
|
|
timeZoneName: 'short'
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const formatted = ref(getTargetFridayTime().toLocaleString('en-US', options))
|
|
|
|
|
|
|
|
|
|
const getStockQuate= async()=>{
|
2025-05-23 06:55:12 +00:00
|
|
|
|
const res = await axios.get('https://saas-test.szjixun.cn/api/chart/forward/test')
|
2025-05-23 02:39:23 +00:00
|
|
|
|
stockQuote.value=res.data
|
2025-05-26 06:12:54 +00:00
|
|
|
|
}
|
2025-05-23 01:37:30 +00:00
|
|
|
|
return {
|
2025-05-23 12:21:14 +00:00
|
|
|
|
formatted,
|
2025-05-23 01:37:30 +00:00
|
|
|
|
getStockQuate,
|
|
|
|
|
stockQuote
|
|
|
|
|
}
|
|
|
|
|
})
|