From d4d35188227d7b24f8d20747ea1917d75fc2e584 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?M=E5=85=88=E7=94=9F?= <1211120248@qq.com> Date: Sun, 19 Jul 2026 19:06:56 +0800 Subject: [PATCH] fix: sync home livestock balance data --- src/views/grassLivestockBalance/data.js | 20 +++---- src/views/home/index.vue | 76 ++++++++++++++++++++++++- 2 files changed, 84 insertions(+), 12 deletions(-) diff --git a/src/views/grassLivestockBalance/data.js b/src/views/grassLivestockBalance/data.js index c038938..5edc4d4 100644 --- a/src/views/grassLivestockBalance/data.js +++ b/src/views/grassLivestockBalance/data.js @@ -175,16 +175,16 @@ export const countyBalanceRow = { } 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: "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: "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: "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: "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: "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: "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: "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: "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: "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: "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: 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: 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: 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: 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: 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: 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: 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: 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: 78752, livestockCapacity: 79358, overloadRate: 0.77, level: "基本实现草畜平衡", advice: CXPT_BALANCE_ADVICE, year: "2026" }, ] export const balanceFallbackRows = [ diff --git a/src/views/home/index.vue b/src/views/home/index.vue index 55e480f..f714053 100644 --- a/src/views/home/index.vue +++ b/src/views/home/index.vue @@ -176,6 +176,10 @@ :autoresize="true" />
+
+ + {{ homeBalanceEmptyText }} +
getForecastGranularity(acti const trendSeries = computed(() => buildForecastSeriesByGranularity(forecastTrendPeriod, activeForecastGranularityMeta.value.key)) const activeForecastTrendIndex = computed(() => getLoopIndex(trendSeries.value.labels.length)) 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) => ({ key: `home-balance-${item.areaCode || item.key || item.name}`, sourceIndex: index, @@ -661,6 +670,10 @@ const homeBalanceRows = computed(() => { extra: `载畜 ${formatNumber(item.livestockCapacity)}头`, })) }) +const homeBalanceEmptyText = computed(() => { + if (homeBalanceLoading.value) return "正在读取最新草畜平衡数据" + return homeBalanceLoadError.value || "暂无草畜平衡数据" +}) const homeBalanceGaugeRows = computed(() => { const rows = homeBalanceRows.value const pageSize = 3 @@ -1012,11 +1025,13 @@ onMounted(() => { document.addEventListener("pointerdown", handleOutsideFeaturePointerDown, true) document.addEventListener("click", handleHomeVideoDocumentClickCapture, true) emitHomeTopStats() + void loadHomeBalanceRows() initHomeMap() }) onBeforeUnmount(() => { destroyed = true + homeBalanceLoadSerial += 1 window.removeEventListener("resize", updateHomeViewportHeight) window.removeEventListener("keydown", handleHomeKeyDown) document.removeEventListener("pointerdown", handleOutsideFeaturePointerDown, true) @@ -1063,6 +1078,7 @@ watch( initHomeMap() restoreHomeMapOnActivate() startChartMotion() + void loadHomeBalanceRows() if (!homeIdleWorkLoaded) scheduleHomeIdleWork() } else { homeMapReadyReported = false @@ -1501,6 +1517,35 @@ function openHomeBalanceModal() { 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() { homeBalanceModalVisible.value = false } @@ -3931,6 +3976,33 @@ function handleOutsideFeaturePointerDown(event) { 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 { position: relative; display: grid;