初版完成

This commit is contained in:
2025-12-03 10:43:50 +08:00
parent e902c1a221
commit 39867f2a23
2 changed files with 40 additions and 9 deletions

View File

@@ -515,6 +515,11 @@ export default {
try { try {
const apiParam = toApiProvinceParam(provinceName) const apiParam = toApiProvinceParam(provinceName)
url = `/api/cattle-data/provinces?province=${encodeURIComponent(apiParam)}` 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 }) const res = await fetch(url, { signal: provinceClickController.signal })
clearTimeout(timeoutId) clearTimeout(timeoutId)
if (!res.ok) throw new Error(`HTTP ${res.status}`) if (!res.ok) throw new Error(`HTTP ${res.status}`)

View File

@@ -31,7 +31,7 @@ export default {
// 省份基础价(元/斤),用于生成示例数据 // 省份基础价(元/斤),用于生成示例数据
const basePriceMap = { 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) => { const genData = (regionId = null) => {
// 根据筛选生成最近 N 天日期与价格数据(可按地区与重量微调)
const baseBase = basePriceMap[props.selectedProvince] ?? 6.8 const baseBase = basePriceMap[props.selectedProvince] ?? 6.8
const regionOffset = regionId ? (parseInt(regionId.split('-')[1]) || 0) * 0.03 : 0 const regionOffset = regionId ? (parseInt(regionId.split('-')[1]) || 0) * 0.03 : 0
const weightOffset = weight.value === '400' ? 0.15 : (weight.value === '500' ? 0.25 : 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) const dt = new Date(today)
dt.setDate(today.getDate() - i) dt.setDate(today.getDate() - i)
d.push(`${dt.getMonth() + 1}-${String(dt.getDate()).padStart(2, '0')}`) d.push(`${dt.getMonth() + 1}-${String(dt.getDate()).padStart(2, '0')}`)
// 价格在基础价附近小幅波动
const fluct = (Math.sin(i) * 0.08) + (Math.random() * 0.12 - 0.06) const fluct = (Math.sin(i) * 0.08) + (Math.random() * 0.12 - 0.06)
p.push(+((base + fluct)).toFixed(2)) p.push(+((base + fluct)).toFixed(2))
} }
@@ -228,7 +254,6 @@ export default {
const handleRowClick = (row) => { const handleRowClick = (row) => {
selectedRow.value = row selectedRow.value = row
genData(row?.id)
} }
// 年度统计数据(示例) // 年度统计数据(示例)
@@ -366,7 +391,8 @@ export default {
selectedRow.value = null selectedRow.value = null
const ok = await fetchProvinceRegionRows() const ok = await fetchProvinceRegionRows()
if (!ok) genRegionRows() if (!ok) genRegionRows()
genData() const dailyOk = await fetchDailyPrices()
if (!dailyOk) genData()
genStats() genStats()
}, { immediate: true }) }, { immediate: true })
@@ -420,17 +446,17 @@ export default {
</h3> </h3>
</div> </div>
<div class="detail-content"> <div class="detail-content">
<!-- <div class="today-price-line"> <div class="today-price-line">
<div class="labels"> <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> <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>
<div class="price-display"> <div class="price-display">
<span class="currency">¥</span> <span class="currency">¥</span>
<span class="value">{{ avgToday.toFixed(2) }}</span> <span class="value">{{ todayPrice.toFixed(2) }}</span>
<span class="unit">{{ unit }}</span> <span class="unit">{{ unit }}</span>
</div> </div>
</div> --> </div>
<!-- <div class="filters"> <!-- <div class="filters">
<div class="weight-group"> <div class="weight-group">