fix: 配置Vite代理解决跨域问题,并对接真实API接口
This commit is contained in:
@@ -55,36 +55,36 @@ const popupPos = ref({ x: 0, y: 0 });
|
||||
const districtUrl =
|
||||
"https://geo.datav.aliyun.com/areas_v3/bound/120000_full.json";
|
||||
|
||||
// 区级与街道级指标(模拟数据)
|
||||
const indicatorData = {
|
||||
完成状态: {
|
||||
和平区: "已完成",
|
||||
河东区: "未完成",
|
||||
河西区: "已完成",
|
||||
南开区: "未开始",
|
||||
河北区: "未完成",
|
||||
红桥区: "已完成",
|
||||
滨海新区: "未完成",
|
||||
},
|
||||
图斑面积: {
|
||||
和平区: 230,
|
||||
河东区: 340,
|
||||
河西区: 410,
|
||||
南开区: 300,
|
||||
河北区: 500,
|
||||
红桥区: 270,
|
||||
滨海新区: 1200,
|
||||
},
|
||||
图斑数量: {
|
||||
和平区: 45,
|
||||
河东区: 80,
|
||||
河西区: 70,
|
||||
南开区: 60,
|
||||
河北区: 85,
|
||||
红桥区: 50,
|
||||
滨海新区: 150,
|
||||
},
|
||||
};
|
||||
|
||||
const indicatorData =ref({
|
||||
完成状态:{},
|
||||
图斑面积:{},
|
||||
图斑数量:{},
|
||||
})
|
||||
|
||||
async function fetchDistrictStatus(){
|
||||
console.log("🔥 正在尝试发起请求...");
|
||||
try{
|
||||
const response=await fetch('/api/stats/district')
|
||||
const res=await response.json();
|
||||
console.log("区级指标数据:",res);
|
||||
if(res.code==0&&res.data){
|
||||
indicatorData.value={
|
||||
完成状态:res.data.completionStatus || {},
|
||||
图斑面积:res.data.plotArea || {},
|
||||
图斑数量:res.data.plotCount || {},
|
||||
};
|
||||
|
||||
|
||||
if (map&&map.getSource("tianjin")){
|
||||
updateMapColors("district");
|
||||
}
|
||||
}
|
||||
|
||||
}catch(error){
|
||||
console.error("获取区级指标数据失败:",error);
|
||||
}
|
||||
}
|
||||
|
||||
// 模拟街道级指标(真实项目应从接口获取)
|
||||
const streetIndicatorData = {
|
||||
@@ -144,6 +144,9 @@ function handleMapClick(e) {
|
||||
|
||||
// 初始化地图
|
||||
onMounted(async () => {
|
||||
console.log("Vue组件已挂载");
|
||||
fetchDistrictStatus();
|
||||
console.log("初始化地图");
|
||||
map = new maplibregl.Map({
|
||||
container: mapContainer.value,
|
||||
style: {
|
||||
@@ -224,8 +227,11 @@ function updateMapColors(level = currentLevel.value) {
|
||||
const data = map.getSource(sourceId)?._data;
|
||||
if (!data) return;
|
||||
|
||||
const indicator = level === "district" ? indicatorData : streetIndicatorData;
|
||||
const indicator = level === "district" ? indicatorData.value : streetIndicatorData;
|
||||
const selected = selectedIndicator.value;
|
||||
|
||||
// 防止接口还没返回数据时报错
|
||||
if (!indicator[selected]) return;
|
||||
|
||||
if (selected === "完成状态") {
|
||||
const colors = { 已完成: "#4CAF50", 未完成: "#FFC107", 未开始: "#BDBDBD" };
|
||||
|
||||
Reference in New Issue
Block a user