fix: sync home livestock balance data

V2.2
M先生 3 weeks ago
parent 64ce8b117c
commit d4d3518822
  1. 20
      src/views/grassLivestockBalance/data.js
  2. 76
      src/views/home/index.vue

@ -175,16 +175,16 @@ export const countyBalanceRow = {
} }
export const balanceTownRows = [ export const balanceTownRows = [
{ key: "town-邛溪镇", type: "town", name: "邛溪镇", areaCode: "513233100", areaRange: 930604.2, yakNumber: 49140, bearingCapacity: 47723, livestockCapacity: 49140, overloadRate: 2.97, level: "基本实现草畜平衡", advice: CXPT_BALANCE_ADVICE, year: "2026" }, { key: "town-邛溪镇", type: "town", name: "邛溪镇", areaCode: "513233100", areaRange: 930604.2, yakNumber: 49140, bearingCapacity: 48619, livestockCapacity: 49140, overloadRate: 1.07, level: "基本实现草畜平衡", advice: CXPT_BALANCE_ADVICE, year: "2026" },
{ key: "town-刷经寺镇", type: "town", name: "刷经寺镇", areaCode: "513233101", areaRange: 743557.5, yakNumber: 18283, bearingCapacity: 18002, livestockCapacity: 18283, overloadRate: 1.56, level: "基本实现草畜平衡", advice: CXPT_BALANCE_ADVICE, year: "2026" }, { key: "town-刷经寺镇", type: "town", name: "刷经寺镇", areaCode: "513233101", areaRange: 743557.5, yakNumber: 18283, bearingCapacity: 18181, livestockCapacity: 18283, overloadRate: 0.56, level: "基本实现草畜平衡", advice: CXPT_BALANCE_ADVICE, year: "2026" },
{ key: "town-安曲镇", type: "town", name: "安曲镇", areaCode: "513233103", areaRange: 900696.75, yakNumber: 59725, bearingCapacity: 58479, livestockCapacity: 59725, overloadRate: 2.13, level: "基本实现草畜平衡", advice: CXPT_BALANCE_ADVICE, year: "2026" }, { key: "town-安曲镇", type: "town", name: "安曲镇", areaCode: "513233103", areaRange: 900696.75, yakNumber: 59725, bearingCapacity: 59269, livestockCapacity: 59725, overloadRate: 0.77, level: "基本实现草畜平衡", advice: CXPT_BALANCE_ADVICE, year: "2026" },
{ key: "town-龙日镇", type: "town", name: "龙日镇", areaCode: "513233105", areaRange: 628303.8, yakNumber: 40192, bearingCapacity: 39462, livestockCapacity: 40192, overloadRate: 1.85, level: "基本实现草畜平衡", advice: CXPT_BALANCE_ADVICE, year: "2026" }, { key: "town-龙日镇", type: "town", name: "龙日镇", areaCode: "513233105", areaRange: 628303.8, yakNumber: 40192, bearingCapacity: 39925, livestockCapacity: 40192, overloadRate: 0.67, level: "基本实现草畜平衡", advice: CXPT_BALANCE_ADVICE, year: "2026" },
{ key: "town-江茸乡", type: "town", name: "江茸乡", areaCode: "513233202", areaRange: 496888.95, yakNumber: 20789, bearingCapacity: 20563, livestockCapacity: 20789, overloadRate: 1.1, level: "基本实现草畜平衡", advice: CXPT_BALANCE_ADVICE, year: "2026" }, { key: "town-江茸乡", type: "town", name: "江茸乡", areaCode: "513233202", areaRange: 496888.95, yakNumber: 20789, bearingCapacity: 20706, livestockCapacity: 20789, overloadRate: 0.4, level: "基本实现草畜平衡", advice: CXPT_BALANCE_ADVICE, year: "2026" },
{ key: "town-查尔玛乡", type: "town", name: "查尔玛乡", areaCode: "513233203", areaRange: 808628.4, yakNumber: 28836, bearingCapacity: 28312, livestockCapacity: 28836, overloadRate: 1.85, level: "基本实现草畜平衡", advice: CXPT_BALANCE_ADVICE, year: "2026" }, { key: "town-查尔玛乡", type: "town", name: "查尔玛乡", areaCode: "513233203", areaRange: 808628.4, yakNumber: 28836, bearingCapacity: 28644, livestockCapacity: 28836, overloadRate: 0.67, level: "基本实现草畜平衡", advice: CXPT_BALANCE_ADVICE, year: "2026" },
{ key: "town-瓦切镇", type: "town", name: "瓦切镇", areaCode: "513233204", areaRange: 747837.6, yakNumber: 76127, bearingCapacity: 74598, livestockCapacity: 76127, overloadRate: 2.05, level: "基本实现草畜平衡", advice: CXPT_BALANCE_ADVICE, year: "2026" }, { key: "town-瓦切镇", type: "town", name: "瓦切镇", areaCode: "513233204", areaRange: 747837.6, yakNumber: 76127, bearingCapacity: 75568, livestockCapacity: 76127, overloadRate: 0.74, level: "基本实现草畜平衡", advice: CXPT_BALANCE_ADVICE, year: "2026" },
{ key: "town-阿木乡", type: "town", name: "阿木乡", areaCode: "513233205", areaRange: 863346, yakNumber: 38587, bearingCapacity: 37554, livestockCapacity: 38587, overloadRate: 2.75, level: "基本实现草畜平衡", advice: CXPT_BALANCE_ADVICE, year: "2026" }, { key: "town-阿木乡", type: "town", name: "阿木乡", areaCode: "513233205", areaRange: 863346, yakNumber: 38587, bearingCapacity: 38209, livestockCapacity: 38587, overloadRate: 0.99, level: "基本实现草畜平衡", advice: CXPT_BALANCE_ADVICE, year: "2026" },
{ key: "town-麦洼乡", type: "town", name: "麦洼乡", areaCode: "513233207", areaRange: 458338.35, yakNumber: 47193, bearingCapacity: 46643, livestockCapacity: 47193, overloadRate: 1.18, level: "基本实现草畜平衡", advice: CXPT_BALANCE_ADVICE, year: "2026" }, { key: "town-麦洼乡", type: "town", name: "麦洼乡", areaCode: "513233207", areaRange: 458338.35, yakNumber: 47193, bearingCapacity: 46991, livestockCapacity: 47193, overloadRate: 0.43, level: "基本实现草畜平衡", advice: CXPT_BALANCE_ADVICE, year: "2026" },
{ key: "town-色地镇", type: "town", name: "色地镇", areaCode: "513233208", areaRange: 991265.25, yakNumber: 79358, bearingCapacity: 77695, livestockCapacity: 79358, overloadRate: 2.14, level: "基本实现草畜平衡", advice: CXPT_BALANCE_ADVICE, year: "2026" }, { key: "town-色地镇", type: "town", name: "色地镇", areaCode: "513233208", areaRange: 991265.25, yakNumber: 79358, bearingCapacity: 78752, livestockCapacity: 79358, overloadRate: 0.77, level: "基本实现草畜平衡", advice: CXPT_BALANCE_ADVICE, year: "2026" },
] ]
export const balanceFallbackRows = [ export const balanceFallbackRows = [

@ -176,6 +176,10 @@
:autoresize="true" :autoresize="true"
/> />
<div v-else-if="panel.key === 'home-town-balance-gauge'" class="home-balance-gauge-grid"> <div v-else-if="panel.key === 'home-town-balance-gauge'" class="home-balance-gauge-grid">
<div v-if="!homeBalanceGaugeRows.length" class="home-balance-empty" aria-live="polite">
<i></i>
<span>{{ homeBalanceEmptyText }}</span>
</div>
<div <div
v-for="(item, index) in homeBalanceGaugeRows" v-for="(item, index) in homeBalanceGaugeRows"
:key="item.key" :key="item.key"
@ -355,7 +359,8 @@ import {
getForecastMonthCount, getForecastMonthCount,
structureRows, structureRows,
} from "@/views/yakManagement/data" } from "@/views/yakManagement/data"
import { balanceTownRows } from "@/views/grassLivestockBalance/data" import { getAreaBalanceRows } from "@/services/balanceApi"
import { normalizeBalanceResult } from "@/views/grassLivestockBalance/data"
import { import {
homeTopStats, homeTopStats,
yakTownRows, yakTownRows,
@ -470,6 +475,7 @@ let featureQueryRequestId = 0
let threeHomeAssets = null let threeHomeAssets = null
let threeHomeAssetLoading = false let threeHomeAssetLoading = false
let threeHomeAssetLoaded = false let threeHomeAssetLoaded = false
let homeBalanceLoadSerial = 0
const homeVideoFitRafs = new Map() const homeVideoFitRafs = new Map()
const chartMotionTick = ref(0) const chartMotionTick = ref(0)
const homeVideoRows = ref([]) const homeVideoRows = ref([])
@ -481,6 +487,9 @@ const homeVideoModalPage = ref(1)
const homeVideoRotationPaused = ref(false) const homeVideoRotationPaused = ref(false)
const homeVideoExpandedIndex = ref(null) const homeVideoExpandedIndex = ref(null)
const homeBalanceModalVisible = ref(false) const homeBalanceModalVisible = ref(false)
const homeBalanceSourceRows = ref([])
const homeBalanceLoading = ref(false)
const homeBalanceLoadError = ref("")
const activeForecastGranularity = ref("month") const activeForecastGranularity = ref("month")
const videoPlaying = ref(false) const videoPlaying = ref(false)
const videoLoading = ref(false) const videoLoading = ref(false)
@ -650,7 +659,7 @@ const activeForecastGranularityMeta = computed(() => getForecastGranularity(acti
const trendSeries = computed(() => buildForecastSeriesByGranularity(forecastTrendPeriod, activeForecastGranularityMeta.value.key)) const trendSeries = computed(() => buildForecastSeriesByGranularity(forecastTrendPeriod, activeForecastGranularityMeta.value.key))
const activeForecastTrendIndex = computed(() => getLoopIndex(trendSeries.value.labels.length)) const activeForecastTrendIndex = computed(() => getLoopIndex(trendSeries.value.labels.length))
const homeBalanceRows = computed(() => { const homeBalanceRows = computed(() => {
const rows = balanceTownRows.filter((item) => item?.name) const rows = homeBalanceSourceRows.value.filter((item) => item?.name && item.type === "town")
return rows.map((item, index) => ({ return rows.map((item, index) => ({
key: `home-balance-${item.areaCode || item.key || item.name}`, key: `home-balance-${item.areaCode || item.key || item.name}`,
sourceIndex: index, sourceIndex: index,
@ -661,6 +670,10 @@ const homeBalanceRows = computed(() => {
extra: `载畜 ${formatNumber(item.livestockCapacity)}`, extra: `载畜 ${formatNumber(item.livestockCapacity)}`,
})) }))
}) })
const homeBalanceEmptyText = computed(() => {
if (homeBalanceLoading.value) return "正在读取最新草畜平衡数据"
return homeBalanceLoadError.value || "暂无草畜平衡数据"
})
const homeBalanceGaugeRows = computed(() => { const homeBalanceGaugeRows = computed(() => {
const rows = homeBalanceRows.value const rows = homeBalanceRows.value
const pageSize = 3 const pageSize = 3
@ -1012,11 +1025,13 @@ onMounted(() => {
document.addEventListener("pointerdown", handleOutsideFeaturePointerDown, true) document.addEventListener("pointerdown", handleOutsideFeaturePointerDown, true)
document.addEventListener("click", handleHomeVideoDocumentClickCapture, true) document.addEventListener("click", handleHomeVideoDocumentClickCapture, true)
emitHomeTopStats() emitHomeTopStats()
void loadHomeBalanceRows()
initHomeMap() initHomeMap()
}) })
onBeforeUnmount(() => { onBeforeUnmount(() => {
destroyed = true destroyed = true
homeBalanceLoadSerial += 1
window.removeEventListener("resize", updateHomeViewportHeight) window.removeEventListener("resize", updateHomeViewportHeight)
window.removeEventListener("keydown", handleHomeKeyDown) window.removeEventListener("keydown", handleHomeKeyDown)
document.removeEventListener("pointerdown", handleOutsideFeaturePointerDown, true) document.removeEventListener("pointerdown", handleOutsideFeaturePointerDown, true)
@ -1063,6 +1078,7 @@ watch(
initHomeMap() initHomeMap()
restoreHomeMapOnActivate() restoreHomeMapOnActivate()
startChartMotion() startChartMotion()
void loadHomeBalanceRows()
if (!homeIdleWorkLoaded) scheduleHomeIdleWork() if (!homeIdleWorkLoaded) scheduleHomeIdleWork()
} else { } else {
homeMapReadyReported = false homeMapReadyReported = false
@ -1501,6 +1517,35 @@ function openHomeBalanceModal() {
homeBalanceModalVisible.value = true homeBalanceModalVisible.value = true
} }
async function loadHomeBalanceRows() {
const loadId = ++homeBalanceLoadSerial
homeBalanceLoading.value = true
homeBalanceLoadError.value = ""
try {
const sourceRows = await getAreaBalanceRows()
if (destroyed || loadId !== homeBalanceLoadSerial) return
const uniqueRows = new Map()
sourceRows.forEach((sourceRow) => {
const row = normalizeBalanceResult(sourceRow, sourceRow)
if (row.type !== "town" || !row.name) return
const identity = row.areaCode || row.key || row.name
uniqueRows.set(String(identity), row)
})
homeBalanceSourceRows.value = [...uniqueRows.values()].sort((left, right) =>
String(left.areaCode || left.name).localeCompare(String(right.areaCode || right.name), "zh-CN"),
)
if (!homeBalanceSourceRows.value.length) homeBalanceLoadError.value = "暂未查询到最新草畜平衡数据"
} catch (error) {
if (destroyed || loadId !== homeBalanceLoadSerial) return
console.warn("[home] balance rows unavailable", error)
homeBalanceSourceRows.value = []
homeBalanceLoadError.value = "草畜平衡数据暂时无法连接"
} finally {
if (!destroyed && loadId === homeBalanceLoadSerial) homeBalanceLoading.value = false
}
}
function closeHomeBalanceModal() { function closeHomeBalanceModal() {
homeBalanceModalVisible.value = false homeBalanceModalVisible.value = false
} }
@ -3931,6 +3976,33 @@ function handleOutsideFeaturePointerDown(event) {
overflow: hidden; overflow: hidden;
} }
.home-balance-empty {
display: flex;
grid-column: 1 / -1;
align-items: center;
justify-content: center;
gap: 10px;
color: rgba(238, 253, 255, 0.72);
font-size: 14px;
font-weight: 700;
i {
width: 8px;
height: 8px;
border-radius: 50%;
background: #30dcff;
box-shadow: 0 0 12px rgba(48, 220, 255, 0.86);
animation: home-balance-loading 1.25s ease-in-out infinite;
}
}
@keyframes home-balance-loading {
50% {
opacity: 0.3;
transform: scale(0.72);
}
}
.home-balance-gauge-card { .home-balance-gauge-card {
position: relative; position: relative;
display: grid; display: grid;

Loading…
Cancel
Save