在股票报价模块中添加格式化日期功能,并在相关视图中引入以显示当前日期和时间。

This commit is contained in:
Phoenix 2025-05-23 20:21:14 +08:00
parent fa00cdd6bc
commit bdb29764be
3 changed files with 19 additions and 16 deletions

View File

@ -14,11 +14,25 @@ export const useStockQuote = createGlobalState(() => {
""
]
})
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'
};
const formatted = ref(date.toLocaleString('en-US', options))
const getStockQuate= async()=>{
const res = await axios.get('https://saas-test.szjixun.cn/api/chart/forward/test')
stockQuote.value=res.data
}
return {
formatted,
getStockQuate,
stockQuote
}

View File

@ -1,19 +1,7 @@
<script setup>
import {useStockQuote} from '@/store/stock-quote/index.js'
const {getStockQuate,stockQuote}=useStockQuote()
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'
};
const {getStockQuate,stockQuote,formatted}=useStockQuote()
const formatted = date.toLocaleString('en-US', options);
getStockQuate()
</script>

View File

@ -1,6 +1,6 @@
<script setup>
import { useStockQuote } from '@/store/stock-quote/index.js';
const { getStockQuate, stockQuote } = useStockQuote();
const { getStockQuate, stockQuote ,formatted} = useStockQuote();
getStockQuate();
</script>
@ -8,8 +8,9 @@ getStockQuate();
<main class="min-h-60vh flex flex-col items-center justify-start px-2 py-5 pt-500px">
<!-- 价格卡片 -->
<section class="w-full max-w-90vw flex flex-col items-center justify-center glass-card p-4 rounded-2xl shadow mb-5">
<div class="text-4xl font-extrabold text-#8A5AFB animate-bg-move select-none drop-shadow-lg">$1.98</div>
<div class="mt-2 text-sm text-gray-500 font-semibold tracking-widest">NASDAQ: <span class="text-black">UK</span></div>
<div class="text-4xl font-extrabold text-#8A5AFB animate-bg-move select-none drop-shadow-lg">${{ stockQuote.change?.[0].slice(0,4) }}</div>
<div class="mt-2 text-sm text-gray-500 font-semibold tracking-widest mb-0px">NASDAQ: <span class="text-black">MINM</span></div>
<div class="text-gray-500 text-60px">{{ formatted }}</div>
</section>
<!-- 信息卡片列表 -->
<section class="w-full max-w-90vw grid grid-cols-2 gap-2">