2025-05-23 01:37:30 +00:00
|
|
|
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'
|
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-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-23 12:21:14 +00:00
|
|
|
|
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()=>{
|
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 07:13:40 +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
|
|
|
|
}
|
|
|
|
})
|