初版完成
This commit is contained in:
@@ -515,6 +515,11 @@ export default {
|
||||
try {
|
||||
const apiParam = toApiProvinceParam(provinceName)
|
||||
url = `/api/cattle-data/provinces?province=${encodeURIComponent(apiParam)}`
|
||||
const dailyUrl = `/api/cattle-data/province-daily-prices?province=${encodeURIComponent(apiParam)}`
|
||||
const dailyReq = fetch(dailyUrl, { signal: provinceClickController.signal }).then(r => {
|
||||
if (!r.ok) throw new Error(`HTTP ${r.status}`)
|
||||
return r.json()
|
||||
}).catch(e => e)
|
||||
const res = await fetch(url, { signal: provinceClickController.signal })
|
||||
clearTimeout(timeoutId)
|
||||
if (!res.ok) throw new Error(`HTTP ${res.status}`)
|
||||
|
||||
@@ -31,7 +31,7 @@ export default {
|
||||
|
||||
// 省份基础价(元/斤),用于生成示例数据
|
||||
const basePriceMap = {
|
||||
NX: 6.8, BJ: 7.2, TJ: 6.9, HI: 7.0, CQ: 6.7, HE: 6.6, SD: 6.9, HB: 6.8
|
||||
NX: 6.8, BJ: 7.2, TJ: 6.9, HI: 7.0, CQ: 14, HE: 13.8, SD: 14, HB: 14.01
|
||||
}
|
||||
|
||||
// 牛品种列表(示例)
|
||||
@@ -204,8 +204,35 @@ export default {
|
||||
}
|
||||
|
||||
|
||||
const fetchDailyPrices = async () => {
|
||||
try {
|
||||
const apiParam = toApiProvinceParam(provinceName.value)
|
||||
const url = `/api/cattle-data/province-daily-prices?province=${encodeURIComponent(apiParam)}`
|
||||
const res = await fetch(url)
|
||||
if (!res.ok) throw new Error(`HTTP ${res.status}`)
|
||||
const raw = await res.json()
|
||||
const list = Array.isArray(raw) ? raw : (Array.isArray(raw?.data) ? raw.data : [])
|
||||
const items = list.map(it => ({
|
||||
date: it.priceDate || it.price_date || it.date,
|
||||
price: Number(it.price)
|
||||
})).filter(it => it.date && Number.isFinite(it.price))
|
||||
items.sort((a, b) => new Date(a.date) - new Date(b.date))
|
||||
const last7 = items.slice(-7)
|
||||
const d = last7.map(it => {
|
||||
const dt = new Date(it.date)
|
||||
return `${dt.getMonth() + 1}-${String(dt.getDate()).padStart(2, '0')}`
|
||||
})
|
||||
const p = last7.map(it => +it.price.toFixed(2))
|
||||
days.value = d
|
||||
priceSeries.value = p
|
||||
return true
|
||||
} catch (e) {
|
||||
console.warn('[Price] 获取近7天价格失败:', e)
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
const genData = (regionId = null) => {
|
||||
// 根据筛选生成最近 N 天日期与价格数据(可按地区与重量微调)
|
||||
const baseBase = basePriceMap[props.selectedProvince] ?? 6.8
|
||||
const regionOffset = regionId ? (parseInt(regionId.split('-')[1]) || 0) * 0.03 : 0
|
||||
const weightOffset = weight.value === '400' ? 0.15 : (weight.value === '500' ? 0.25 : 0)
|
||||
@@ -218,7 +245,6 @@ export default {
|
||||
const dt = new Date(today)
|
||||
dt.setDate(today.getDate() - i)
|
||||
d.push(`${dt.getMonth() + 1}-${String(dt.getDate()).padStart(2, '0')}`)
|
||||
// 价格在基础价附近小幅波动
|
||||
const fluct = (Math.sin(i) * 0.08) + (Math.random() * 0.12 - 0.06)
|
||||
p.push(+((base + fluct)).toFixed(2))
|
||||
}
|
||||
@@ -228,7 +254,6 @@ export default {
|
||||
|
||||
const handleRowClick = (row) => {
|
||||
selectedRow.value = row
|
||||
genData(row?.id)
|
||||
}
|
||||
|
||||
// 年度统计数据(示例)
|
||||
@@ -366,7 +391,8 @@ export default {
|
||||
selectedRow.value = null
|
||||
const ok = await fetchProvinceRegionRows()
|
||||
if (!ok) genRegionRows()
|
||||
genData()
|
||||
const dailyOk = await fetchDailyPrices()
|
||||
if (!dailyOk) genData()
|
||||
genStats()
|
||||
}, { immediate: true })
|
||||
|
||||
@@ -420,17 +446,17 @@ export default {
|
||||
</h3>
|
||||
</div>
|
||||
<div class="detail-content">
|
||||
<!-- <div class="today-price-line">
|
||||
<div class="today-price-line">
|
||||
<div class="labels">
|
||||
<span class="label">今日批发均价</span>
|
||||
<span class="label">今日价格</span>
|
||||
<span class="compare">相比昨日 <span :class="yesterdayDelta === 0 ? 'change-zero' : (yesterdayDelta > 0 ? 'change-up' : 'change-down')">{{ trendText }} {{ yesterdayDelta.toFixed(2) }}</span> <span class="symbol">{{ trendSymbol }}</span></span>
|
||||
</div>
|
||||
<div class="price-display">
|
||||
<span class="currency">¥</span>
|
||||
<span class="value">{{ avgToday.toFixed(2) }}</span>
|
||||
<span class="value">{{ todayPrice.toFixed(2) }}</span>
|
||||
<span class="unit">{{ unit }}</span>
|
||||
</div>
|
||||
</div> -->
|
||||
</div>
|
||||
|
||||
<!-- <div class="filters">
|
||||
<div class="weight-group">
|
||||
|
||||
Reference in New Issue
Block a user