This commit is contained in:
Phoenix 2025-05-23 11:39:00 +08:00
commit e56df423f5
2 changed files with 75 additions and 69 deletions

View File

@ -65,6 +65,7 @@ export const useHeaderMenuConfig = () => {
{ {
label: t('header_menu.stock_information.historic_stock_price'), label: t('header_menu.stock_information.historic_stock_price'),
key: 'historic_stock_price', key: 'historic_stock_price',
href: '/historic-stock',
}, },
{ {
label: t('header_menu.stock_information.investment_calculator'), label: t('header_menu.stock_information.investment_calculator'),

View File

@ -1,9 +1,9 @@
<template> <template>
<div class="historic-data-container" style="margin-bottom: 100px"> <div class="historic-data-container" style="margin-bottom: 100px;">
<img <img
src="@/assets/image/historic-stock.png" src="@/assets/image/historic-stock.png"
alt="1" alt="1"
style="max-width: 100%; margin: 0 auto" style="max-width: 100%; margin: 0 auto;"
/> />
<div class="header mt-[20px]"> <div class="header mt-[20px]">
@ -44,7 +44,8 @@
<div class="pagination-container"> <div class="pagination-container">
<n-button class="page-btn prev-btn" @click="handlePrevPage"> <n-button class="page-btn prev-btn" @click="handlePrevPage">
<n-icon><chevron-back-outline /></n-icon> Previous <n-icon><chevron-back-outline /></n-icon>
Previous
</n-button> </n-button>
<div class="page-info"> <div class="page-info">
@ -58,36 +59,39 @@
@select="handlePageSizeChange" @select="handlePageSizeChange"
> >
<n-button class="rows-dropdown"> <n-button class="rows-dropdown">
{{ state.pageSize }} Rows <n-icon><chevron-down-outline /></n-icon> {{ state.pageSize }} Rows
<n-icon><chevron-down-outline /></n-icon>
</n-button> </n-button>
</n-dropdown> </n-dropdown>
<n-button class="page-btn next-btn" @click="handleNextPage"> <n-button class="page-btn next-btn" @click="handleNextPage">
Next <n-icon><chevron-forward-outline /></n-icon> Next
<n-icon><chevron-forward-outline /></n-icon>
</n-button> </n-button>
</div> </div>
</div> </div>
<div class="back-to-top-link"> <div class="back-to-top-link">
<a href="#" @click.prevent="scrollToTop" <a href="#" @click.prevent="scrollToTop">
>Back to Top <n-icon><arrow-up-outline /></n-icon Back to Top
></a> <n-icon><arrow-up-outline /></n-icon>
</a>
</div> </div>
</div> </div>
</template> </template>
<script setup> <script setup>
import { NDataTable, NButton, NDropdown, NIcon } from "naive-ui"; import { NDataTable, NButton, NDropdown, NIcon } from 'naive-ui'
import { reactive, onMounted, h, computed } from "vue"; import { reactive, onMounted, h, computed } from 'vue'
import axios from "axios"; import axios from 'axios'
import { import {
ChevronDownOutline, ChevronDownOutline,
ChevronBackOutline, ChevronBackOutline,
ChevronForwardOutline, ChevronForwardOutline,
ArrowUpOutline, ArrowUpOutline,
} from "@vicons/ionicons5"; } from '@vicons/ionicons5'
import defaultTableData from "../data"; import defaultTableData from '../data'
console.log("defaultTableData", defaultTableData); console.log('defaultTableData', defaultTableData)
// //
const periodOptions = [ const periodOptions = [
@ -110,11 +114,11 @@ const durationOptions = [
// //
const pageSizeOptions = [ const pageSizeOptions = [
{ label: "50", key: 50 }, { label: '50', key: 50 },
{ label: "100", key: 100 }, { label: '100', key: 100 },
{ label: "500", key: 500 }, { label: '500', key: 500 },
{ label: "1000", key: 1000 }, { label: '1000', key: 1000 },
]; ]
const state = reactive({ const state = reactive({
selectedPeriod: 'Daily', selectedPeriod: 'Daily',
@ -122,19 +126,19 @@ const state = reactive({
tableData: [], tableData: [],
currentPage: 1, currentPage: 1,
pageSize: 50, pageSize: 50,
}); })
// //
const totalPages = computed(() => { const totalPages = computed(() => {
return Math.ceil(state.tableData.length / state.pageSize); return Math.ceil(state.tableData.length / state.pageSize)
}); })
// //
const paginatedData = computed(() => { const paginatedData = computed(() => {
const start = (state.currentPage - 1) * state.pageSize; const start = (state.currentPage - 1) * state.pageSize
const end = start + state.pageSize; const end = start + state.pageSize
return state.tableData.slice(start, end); return state.tableData.slice(start, end)
}); })
// //
const columns = [ const columns = [
@ -187,10 +191,19 @@ const columns = [
// //
const handlePeriodChange = (key) => { const handlePeriodChange = (key) => {
state.selectedPeriod = key
if (key === 'Annual') { if (key === 'Annual') {
handleDurationChange('Full History') handleDurationChange('Full History')
return
}
if (key === 'Monthly') {
handleDurationChange('10 Years')
return
}
if (key === 'Quarterly') {
handleDurationChange('10 Years')
return
} }
state.selectedPeriod = key
getPageData() getPageData()
} }
@ -202,30 +215,30 @@ const handleDurationChange = (key) => {
// //
const handlePrevPage = () => { const handlePrevPage = () => {
if (state.currentPage === 1) { if (state.currentPage === 1) {
return; return
} }
state.currentPage--; state.currentPage--
}; }
const handleNextPage = () => { const handleNextPage = () => {
if (state.currentPage >= totalPages.value) { if (state.currentPage >= totalPages.value) {
return; return
} }
state.currentPage++; state.currentPage++
}; }
const handlePageSizeChange = (size) => { const handlePageSizeChange = (size) => {
state.pageSize = size; state.pageSize = size
state.currentPage = 1; // state.currentPage = 1 //
}; }
// //
const scrollToTop = () => { const scrollToTop = () => {
window.scrollTo({ window.scrollTo({
top: 0, top: 0,
behavior: "smooth", behavior: 'smooth',
}); })
}; }
onMounted(() => { onMounted(() => {
getPageDefaultData() getPageDefaultData()
@ -234,27 +247,27 @@ onMounted(() => {
const getPageDefaultData = async () => { const getPageDefaultData = async () => {
try { try {
let url = let url =
"https://stockanalysis.com/api/symbol/a/OTC-MINM/history?type=chart"; 'https://stockanalysis.com/api/symbol/a/OTC-MINM/history?type=chart'
const res = await axios.get(url); const res = await axios.get(url)
let originalData = res.data.data; let originalData = res.data.data
// "Nov 26, 2024" // "Nov 26, 2024"
let calcApiData = originalData.map((item) => [ let calcApiData = originalData.map((item) => [
new Date(item[0]).toLocaleDateString("en-US", { new Date(item[0]).toLocaleDateString('en-US', {
month: "short", month: 'short',
day: "numeric", day: 'numeric',
year: "numeric", year: 'numeric',
}), }),
item[1], item[1],
]); ])
console.log("接口数据", calcApiData); console.log('接口数据', calcApiData)
// 使APIdefaultTableDatacloseadjClose // 使APIdefaultTableDatacloseadjClose
const updatedTableData = defaultTableData.map((tableItem) => { const updatedTableData = defaultTableData.map((tableItem) => {
// API // API
const matchedApiData = calcApiData.find( const matchedApiData = calcApiData.find(
(apiItem) => apiItem[0] === tableItem.date (apiItem) => apiItem[0] === tableItem.date,
); )
if (matchedApiData) { if (matchedApiData) {
// closeadjClose // closeadjClose
@ -262,12 +275,12 @@ const getPageDefaultData = async () => {
...tableItem, ...tableItem,
close: matchedApiData[1].toFixed(2), close: matchedApiData[1].toFixed(2),
adjClose: matchedApiData[1].toFixed(2), adjClose: matchedApiData[1].toFixed(2),
}; }
} }
return tableItem; return tableItem
}); })
state.tableData = updatedTableData; state.tableData = updatedTableData
} catch (error) { } catch (error) {
console.error('获取数据失败', error) console.error('获取数据失败', error)
} }
@ -291,11 +304,16 @@ const getPageData = async () => {
} }
let url = `https://stockanalysis.com/api/symbol/a/OTC-MINM/history?period=${state.selectedPeriod}&range=${range}` let url = `https://stockanalysis.com/api/symbol/a/OTC-MINM/history?period=${state.selectedPeriod}&range=${range}`
const res = await axios.get(url) const res = await axios.get(url)
if(res.data.status === 200){ if (res.data.status === 200) {
console.error(res.data.data) console.error(res.data.data)
// "Nov 26, 2024"
let resultData = res.data.data.map((item) => { let resultData = res.data.data.map((item) => {
return { return {
date: item.t, date: new Date(item.t).toLocaleDateString('en-US', {
month: 'short',
day: 'numeric',
year: 'numeric',
}),
open: item.o != null ? Number(item.o).toFixed(2) : '', open: item.o != null ? Number(item.o).toFixed(2) : '',
high: item.h != null ? Number(item.h).toFixed(2) : '', high: item.h != null ? Number(item.h).toFixed(2) : '',
low: item.l != null ? Number(item.l).toFixed(2) : '', low: item.l != null ? Number(item.l).toFixed(2) : '',
@ -307,19 +325,6 @@ const getPageData = async () => {
}) })
console.error(resultData, 'resultData') console.error(resultData, 'resultData')
state.tableData = resultData state.tableData = resultData
} else {
state.tableData = [
{
date: 'May 22, 2025',
open: '1.87',
high: '2.03',
low: '1.85',
close: '',
adjClose: '2.00',
change: '-2.44%',
volume: '2,103',
},
]
} }
} }
</script> </script>