1405/02/24-Optimization home index.vue

This commit is contained in:
2026-05-14 13:44:43 +03:30
parent e3b4182f6c
commit 1b13aa2a7d
19 changed files with 2143 additions and 1082 deletions
@@ -0,0 +1,33 @@
import { ref } from 'vue'
import { getAllPrices } from '@/api/home'
export function usePriceChart() {
const priceChartSeries = ref([{ name: 'قیمت', data: [] }])
const selection = ref('DAILY')
const chartLoading = ref(false)
const toPersianNumber = (num: number) => {
return num.toString().replace(/\d/g, (d) => '۰۱۲۳۴۵۶۷۸۹'[d])
}
const fetchPrices = async () => {
try {
chartLoading.value = true
const response = await getAllPrices()
const data = response.data?.prices
const selectedData = data[selection.value] || []
priceChartSeries.value[0].data = selectedData.map((item: any) => [item.timestamp, item.value - 1])
} catch (error) {
console.error('Error fetching prices:', error)
} finally {
chartLoading.value = false
}
}
const updateChartData = (timeline: string) => {
selection.value = timeline
fetchPrices()
}
return { priceChartSeries, chartLoading, updateChartData, fetchPrices }
}