|
|
@@ -1,7 +1,7 @@
|
|
|
<template>
|
|
|
<div class="chart-list">
|
|
|
<div class="chart-item">
|
|
|
- <chart-box name="2025年广东省作物种植面积占比">
|
|
|
+ <chart-box :name="`${props.areaName}作物种植面积占比`">
|
|
|
<div class="box-content">
|
|
|
<div class="chart-dom">
|
|
|
<pie-chart :chartData="pieChartData" :totalArea="totalArea"></pie-chart>
|
|
|
@@ -23,7 +23,7 @@
|
|
|
</chart-box>
|
|
|
</div>
|
|
|
<div class="chart-item">
|
|
|
- <chart-box name="2025年广东省作物区域占比">
|
|
|
+ <chart-box :name="twoTitle">
|
|
|
<div class="box-content">
|
|
|
<div class="chart-dom">
|
|
|
<bar-chart :key="0" :chartData="regionChartData"></bar-chart>
|
|
|
@@ -38,17 +38,15 @@
|
|
|
<div class="chart-dom">
|
|
|
<line-chart :chartData="areaTrendChartData"></line-chart>
|
|
|
</div>
|
|
|
- <div class="box-bg">
|
|
|
- 暂无数据
|
|
|
- </div>
|
|
|
+ <div class="box-bg">暂无数据</div>
|
|
|
</div>
|
|
|
</chart-box>
|
|
|
</div>
|
|
|
<div class="chart-item">
|
|
|
- <chart-box name="2025年广东省作物预估产量对比">
|
|
|
+ <chart-box :name="threeTitle">
|
|
|
<div class="box-content">
|
|
|
<div class="chart-dom">
|
|
|
- <bar-chart :key="1" :chartData="yieldChartData" :yAxisFormatter="'{value}吨'"></bar-chart>
|
|
|
+ <bar-chart :key="1" :chartData="yieldChartData" :yAxisFormatter="yAxisFormatter"></bar-chart>
|
|
|
</div>
|
|
|
<div class="box-bg">{{ yieldSummaryText }}</div>
|
|
|
</div>
|
|
|
@@ -61,7 +59,7 @@
|
|
|
import chartBox from "@/components/chartBox.vue";
|
|
|
import pieChart from "./pieChart.vue";
|
|
|
import lineChart from "./lineChart.vue";
|
|
|
-import { computed, onMounted, ref } from "vue";
|
|
|
+import { computed, onMounted, ref, watch } from "vue";
|
|
|
import { pieOption } from "./chartOption.js";
|
|
|
import barChart from "./barChart.vue";
|
|
|
|
|
|
@@ -70,6 +68,14 @@ const props = defineProps({
|
|
|
type: String,
|
|
|
default: "作物分布",
|
|
|
},
|
|
|
+ areaCode: {
|
|
|
+ type: String,
|
|
|
+ default: "156440000",
|
|
|
+ },
|
|
|
+ areaName: {
|
|
|
+ type: String,
|
|
|
+ default: "广东省",
|
|
|
+ },
|
|
|
});
|
|
|
|
|
|
// 图表数据
|
|
|
@@ -94,6 +100,11 @@ const yieldChartData = ref({
|
|
|
// 预估产量摘要文字
|
|
|
const yieldSummaryText = ref("暂无数据");
|
|
|
|
|
|
+// 根据 activeBaseTab 动态设置 y 轴单位
|
|
|
+const yAxisFormatter = computed(() => {
|
|
|
+ return props.activeBaseTab === "物候期分布" ? "{value}亩" : "{value}吨";
|
|
|
+});
|
|
|
+
|
|
|
// 种植面积趋势图表数据
|
|
|
const areaTrendChartData = ref({
|
|
|
xAxisData: [], // 时间轴数据
|
|
|
@@ -116,16 +127,164 @@ const legendData = computed(() => {
|
|
|
});
|
|
|
});
|
|
|
|
|
|
-onMounted(() => {
|
|
|
- fetchStatSpeciesAreaYield();
|
|
|
- fetchStatRegionAreaRatio();
|
|
|
- fetchAreaTrend();
|
|
|
-});
|
|
|
+const twoTitle = ref(`${props.areaName}作物区域占比`);
|
|
|
+const threeTitle = ref(`${props.areaName}作物预估产量对比`);
|
|
|
+
|
|
|
+// 监听 activeBaseTab 变化
|
|
|
+watch(
|
|
|
+ () => props.activeBaseTab,
|
|
|
+ () => {
|
|
|
+ initData();
|
|
|
+ }
|
|
|
+);
|
|
|
+
|
|
|
+// 监听 areaCode 变化,当切换到物候期分布时重新获取数据
|
|
|
+watch(
|
|
|
+ () => props.areaCode,
|
|
|
+ (newVal) => {
|
|
|
+ if (newVal) {
|
|
|
+ initData();
|
|
|
+ }
|
|
|
+ }
|
|
|
+);
|
|
|
+
|
|
|
+const initData = () => {
|
|
|
+ if (props.activeBaseTab === "物候期分布") {
|
|
|
+ twoTitle.value = `${props.areaName}小麦物候进程分布`;
|
|
|
+ threeTitle.value = `${props.areaName}小麦预告产量统计`;
|
|
|
+ fetchStatPhenologyRatio();
|
|
|
+ fetchStatRegionYieldRatio();
|
|
|
+ } else {
|
|
|
+ twoTitle.value = `${props.areaName}作物区域占比`;
|
|
|
+ threeTitle.value = `${props.areaName}作物预估产量对比`;
|
|
|
+ fetchStatSpeciesAreaYield();
|
|
|
+ fetchStatRegionAreaRatio();
|
|
|
+ fetchAreaTrend();
|
|
|
+ }
|
|
|
+};
|
|
|
+
|
|
|
+//统计指定物种在下级区划中的预估产量占比
|
|
|
+const fetchStatRegionYieldRatio = () => {
|
|
|
+ const params = {
|
|
|
+ speciesId: 1,
|
|
|
+ adminCode: props.areaCode,
|
|
|
+ adminLevel: "province",
|
|
|
+ };
|
|
|
+ VE_API.warning
|
|
|
+ .fetchStatRegionYieldRatio(params)
|
|
|
+ .then((res) => {
|
|
|
+ if (res.code === 0 && res.data && res.data.length > 0) {
|
|
|
+ // 转换接口数据为图表格式
|
|
|
+ const categories = res.data.map((item) => item.adminName);
|
|
|
+ // 如果是物候期分布,使用 expectYield(但单位显示为亩),否则使用 expectYield(单位显示为吨)
|
|
|
+ const values = res.data.map((item) => parseFloat(item.expectYield.toFixed(2)));
|
|
|
+
|
|
|
+ // 更新图表数据
|
|
|
+ yieldChartData.value = {
|
|
|
+ categories,
|
|
|
+ values,
|
|
|
+ };
|
|
|
+
|
|
|
+ // 找到最大值的区域
|
|
|
+ let maxValue = 0;
|
|
|
+ let maxRegion = "";
|
|
|
+ res.data.forEach((item) => {
|
|
|
+ if (item.expectYield > maxValue) {
|
|
|
+ maxValue = item.expectYield;
|
|
|
+ maxRegion = item.adminName;
|
|
|
+ }
|
|
|
+ });
|
|
|
+
|
|
|
+ // 更新摘要文字
|
|
|
+ if (maxRegion) {
|
|
|
+ const maxValueFormatted = maxValue.toFixed(1);
|
|
|
+ const unit = props.activeBaseTab === "物候期分布" ? "亩" : "吨";
|
|
|
+ yieldSummaryText.value = `${maxRegion}的${
|
|
|
+ props.activeBaseTab === "物候期分布" ? "种植面积" : "预估产量"
|
|
|
+ }最大,为${maxValueFormatted}${unit}`;
|
|
|
+ } else {
|
|
|
+ yieldSummaryText.value = "暂无数据";
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ yieldChartData.value = {
|
|
|
+ categories: [],
|
|
|
+ values: [],
|
|
|
+ };
|
|
|
+ yieldSummaryText.value = "暂无数据";
|
|
|
+ }
|
|
|
+ })
|
|
|
+ .catch((error) => {
|
|
|
+ console.error("获取区域产量占比数据失败:", error);
|
|
|
+ yieldChartData.value = {
|
|
|
+ categories: [],
|
|
|
+ values: [],
|
|
|
+ };
|
|
|
+ yieldSummaryText.value = "暂无数据";
|
|
|
+ });
|
|
|
+};
|
|
|
+
|
|
|
+//统计指定物种在不同物候期下的面积占比
|
|
|
+const fetchStatPhenologyRatio = () => {
|
|
|
+ const params = {
|
|
|
+ speciesId: 1,
|
|
|
+ adminCode: props.areaCode,
|
|
|
+ adminLevel: "province",
|
|
|
+ };
|
|
|
+
|
|
|
+ VE_API.warning
|
|
|
+ .fetchStatPhenologyRatio(params)
|
|
|
+ .then((res) => {
|
|
|
+ if (res.code === 0 && res.data && res.data.length > 0) {
|
|
|
+ console.log(res.data);
|
|
|
+ // 转换接口数据为图表格式
|
|
|
+ const categories = res.data.map((item) => item.phenologyName);
|
|
|
+ const values = res.data.map((item) => parseFloat((item.areaRatio * 100).toFixed(2))); // 转换为百分比,保留两位小数
|
|
|
+
|
|
|
+ // 更新图表数据
|
|
|
+ regionChartData.value = {
|
|
|
+ categories,
|
|
|
+ values,
|
|
|
+ };
|
|
|
+
|
|
|
+ // 找到最大占比的物候期
|
|
|
+ let maxRatio = 0;
|
|
|
+ let maxPhenology = "";
|
|
|
+ res.data.forEach((item) => {
|
|
|
+ if (item.areaRatio > maxRatio) {
|
|
|
+ maxRatio = item.areaRatio;
|
|
|
+ maxPhenology = item.phenologyName;
|
|
|
+ }
|
|
|
+ });
|
|
|
+
|
|
|
+ // 更新摘要文字
|
|
|
+ if (maxPhenology) {
|
|
|
+ const maxPercent = (maxRatio * 100).toFixed(1);
|
|
|
+ regionSummaryText.value = `${maxPhenology}的种植面积最大,占比${maxPercent}%`;
|
|
|
+ } else {
|
|
|
+ regionSummaryText.value = "暂无数据";
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ regionChartData.value = {
|
|
|
+ categories: [],
|
|
|
+ values: [],
|
|
|
+ };
|
|
|
+ regionSummaryText.value = "暂无数据";
|
|
|
+ }
|
|
|
+ })
|
|
|
+ .catch((error) => {
|
|
|
+ console.error("获取物候期占比数据失败:", error);
|
|
|
+ regionChartData.value = {
|
|
|
+ categories: [],
|
|
|
+ values: [],
|
|
|
+ };
|
|
|
+ regionSummaryText.value = "暂无数据";
|
|
|
+ });
|
|
|
+};
|
|
|
|
|
|
const fetchAreaTrend = () => {
|
|
|
const params = {
|
|
|
speciesIds: [1, 222, 60876],
|
|
|
- adminCode: "156440000",
|
|
|
+ adminCode: props.areaCode,
|
|
|
adminLevel: "province",
|
|
|
};
|
|
|
VE_API.warning.fetchAreaTrend(params).then((res) => {
|
|
|
@@ -141,17 +300,17 @@ const fetchAreaTrend = () => {
|
|
|
|
|
|
// 转换为数组并排序
|
|
|
const xAxisData = Array.from(timePointSet).sort((a, b) => {
|
|
|
- const [yearA, quarterA] = a.split('Q').map(Number);
|
|
|
- const [yearB, quarterB] = b.split('Q').map(Number);
|
|
|
+ const [yearA, quarterA] = a.split("Q").map(Number);
|
|
|
+ const [yearB, quarterB] = b.split("Q").map(Number);
|
|
|
if (yearA !== yearB) return yearA - yearB;
|
|
|
return quarterA - quarterB;
|
|
|
});
|
|
|
|
|
|
// 定义颜色映射(可以根据需要调整)
|
|
|
const colorMap = {
|
|
|
- '荔枝': '#2199F8',
|
|
|
- '籼稻': '#178B00',
|
|
|
- '小麦': '#FAA53D',
|
|
|
+ 荔枝: "#2199F8",
|
|
|
+ 籼稻: "#178B00",
|
|
|
+ 小麦: "#FAA53D",
|
|
|
};
|
|
|
|
|
|
// 为每个作物创建系列数据
|
|
|
@@ -170,15 +329,15 @@ const fetchAreaTrend = () => {
|
|
|
|
|
|
return {
|
|
|
name: species.speciesName,
|
|
|
- type: 'line',
|
|
|
+ type: "line",
|
|
|
smooth: true,
|
|
|
showSymbol: false,
|
|
|
data: data,
|
|
|
itemStyle: {
|
|
|
- color: colorMap[species.speciesName] || '#2199F8',
|
|
|
+ color: colorMap[species.speciesName] || "#2199F8",
|
|
|
},
|
|
|
lineStyle: {
|
|
|
- color: colorMap[species.speciesName] || '#2199F8',
|
|
|
+ color: colorMap[species.speciesName] || "#2199F8",
|
|
|
},
|
|
|
};
|
|
|
});
|
|
|
@@ -188,15 +347,28 @@ const fetchAreaTrend = () => {
|
|
|
xAxisData,
|
|
|
series,
|
|
|
};
|
|
|
+ } else {
|
|
|
+ console.log("空数据");
|
|
|
+ // 接口返回空数据时,清空图表数据
|
|
|
+ areaTrendChartData.value = {
|
|
|
+ xAxisData: [],
|
|
|
+ series: [],
|
|
|
+ };
|
|
|
}
|
|
|
+ }).catch(() => {
|
|
|
+ // 错误时也清空数据
|
|
|
+ areaTrendChartData.value = {
|
|
|
+ xAxisData: [],
|
|
|
+ series: [],
|
|
|
+ };
|
|
|
});
|
|
|
};
|
|
|
|
|
|
const fetchStatRegionAreaRatio = () => {
|
|
|
const params = {
|
|
|
- speciesId: 222,
|
|
|
- adminCode: 156441400,
|
|
|
- adminLevel: "city",
|
|
|
+ speciesId: "1",
|
|
|
+ adminCode: props.areaCode,
|
|
|
+ adminLevel: "",
|
|
|
};
|
|
|
VE_API.warning.fetchStatRegionAreaRatio(params).then((res) => {
|
|
|
if (res.code === 0 && res.data && res.data.length > 0) {
|
|
|
@@ -228,15 +400,28 @@ const fetchStatRegionAreaRatio = () => {
|
|
|
regionSummaryText.value = "暂无数据";
|
|
|
}
|
|
|
} else {
|
|
|
+ // 接口返回空数据时,清空图表数据
|
|
|
+ regionChartData.value = {
|
|
|
+ categories: [],
|
|
|
+ values: [],
|
|
|
+ };
|
|
|
regionSummaryText.value = "暂无数据";
|
|
|
}
|
|
|
+ }).catch((error) => {
|
|
|
+ console.error("获取区域面积占比数据失败:", error);
|
|
|
+ // 错误时也清空数据
|
|
|
+ regionChartData.value = {
|
|
|
+ categories: [],
|
|
|
+ values: [],
|
|
|
+ };
|
|
|
+ regionSummaryText.value = "暂无数据";
|
|
|
});
|
|
|
};
|
|
|
|
|
|
const fetchStatSpeciesAreaYield = () => {
|
|
|
const params = {
|
|
|
year: 2025,
|
|
|
- adminCode: null,
|
|
|
+ adminCode: props.areaCode,
|
|
|
adminLevel: null,
|
|
|
};
|
|
|
VE_API.warning.fetchStatSpeciesAreaYield(params).then((res) => {
|
|
|
@@ -284,8 +469,25 @@ const fetchStatSpeciesAreaYield = () => {
|
|
|
yieldSummaryText.value = "暂无数据";
|
|
|
}
|
|
|
} else {
|
|
|
+ // 接口返回空数据时,清空图表数据
|
|
|
+ pieChartData.value = [];
|
|
|
+ totalArea.value = 0;
|
|
|
+ yieldChartData.value = {
|
|
|
+ categories: [],
|
|
|
+ values: [],
|
|
|
+ };
|
|
|
yieldSummaryText.value = "暂无数据";
|
|
|
}
|
|
|
+ }).catch((error) => {
|
|
|
+ console.error("获取作物面积产量数据失败:", error);
|
|
|
+ // 错误时也清空数据
|
|
|
+ pieChartData.value = [];
|
|
|
+ totalArea.value = 0;
|
|
|
+ yieldChartData.value = {
|
|
|
+ categories: [],
|
|
|
+ values: [],
|
|
|
+ };
|
|
|
+ yieldSummaryText.value = "暂无数据";
|
|
|
});
|
|
|
};
|
|
|
</script>
|