fix_map_search
This commit is contained in:
parent
4b58d6ed54
commit
3bc32d3be7
@ -239,11 +239,16 @@ public class AddressController {
|
|||||||
result.put("name", poi.get("name"));
|
result.put("name", poi.get("name"));
|
||||||
result.put("address", poi.get("address"));
|
result.put("address", poi.get("address"));
|
||||||
|
|
||||||
// 修复类型转换问题:先转换为String再连接
|
// 修复类型转换问题:避免 "null" 字符串
|
||||||
String pname = String.valueOf(poi.get("pname") != null ? poi.get("pname") : "");
|
Object pnameObj = poi.get("pname");
|
||||||
String cityname = String.valueOf(poi.get("cityname") != null ? poi.get("cityname") : "");
|
Object citynameObj = poi.get("cityname");
|
||||||
String adname = String.valueOf(poi.get("adname") != null ? poi.get("adname") : "");
|
Object adnameObj = poi.get("adname");
|
||||||
result.put("district", pname + cityname + adname);
|
|
||||||
|
String pname = (pnameObj != null && !"".equals(pnameObj)) ? String.valueOf(pnameObj) : "";
|
||||||
|
String cityname = (citynameObj != null && !"".equals(citynameObj)) ? String.valueOf(citynameObj) : "";
|
||||||
|
String adname = (adnameObj != null && !"".equals(adnameObj)) ? String.valueOf(adnameObj) : "";
|
||||||
|
|
||||||
|
result.put("district", (pname + cityname + adname).trim());
|
||||||
|
|
||||||
// 解析坐标
|
// 解析坐标
|
||||||
String location = (String) poi.get("location");
|
String location = (String) poi.get("location");
|
||||||
|
|||||||
@ -361,38 +361,63 @@ export default {
|
|||||||
})
|
})
|
||||||
})
|
})
|
||||||
.then(response => {
|
.then(response => {
|
||||||
|
console.log('📡 响应状态:', response.status, response.statusText);
|
||||||
|
|
||||||
|
// 检查响应状态
|
||||||
if (response.status === 401) {
|
if (response.status === 401) {
|
||||||
ElMessage.error('登录已过期,请重新登录');
|
ElMessage.error('登录已过期,请重新登录');
|
||||||
localStorage.removeItem('token');
|
localStorage.removeItem('token');
|
||||||
window.location.href = '/login';
|
window.location.href = '/login';
|
||||||
return;
|
throw new Error('Unauthorized');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 检查响应是否成功
|
||||||
|
if (!response.ok) {
|
||||||
|
throw new Error(`HTTP ${response.status}: ${response.statusText}`);
|
||||||
|
}
|
||||||
|
|
||||||
|
// 检查 Content-Type
|
||||||
|
const contentType = response.headers.get('content-type');
|
||||||
|
if (!contentType || !contentType.includes('application/json')) {
|
||||||
|
console.error('❌ 响应不是 JSON 格式:', contentType);
|
||||||
|
throw new Error('响应格式错误');
|
||||||
|
}
|
||||||
|
|
||||||
return response.json();
|
return response.json();
|
||||||
})
|
})
|
||||||
.then(result => {
|
.then(result => {
|
||||||
console.log('🔍 前端收到后端响应:', result);
|
console.log('🔍 前端收到后端响应:', result);
|
||||||
if (result && result.code === 200 && result.data) {
|
|
||||||
console.log('✅ 响应数据正常:', result.data);
|
if (result && result.code === 200) {
|
||||||
searchResults.value = result.data.map(poi => ({
|
if (result.data && result.data.length > 0) {
|
||||||
id: poi.id,
|
console.log('✅ 响应数据正常:', result.data);
|
||||||
name: poi.name,
|
searchResults.value = result.data.map(poi => ({
|
||||||
address: poi.address,
|
id: poi.id,
|
||||||
district: poi.district,
|
name: poi.name,
|
||||||
location: { lng: poi.lng, lat: poi.lat },
|
address: poi.address,
|
||||||
distance: 0
|
district: poi.district,
|
||||||
}));
|
location: { lng: poi.lng, lat: poi.lat },
|
||||||
console.log("🎯 处理后的搜索结果:", searchResults.value);
|
distance: 0
|
||||||
|
}));
|
||||||
|
console.log("🎯 处理后的搜索结果:", searchResults.value);
|
||||||
|
} else {
|
||||||
|
searchResults.value = [];
|
||||||
|
ElMessage.info('未找到相关地址');
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
searchResults.value = [];
|
searchResults.value = [];
|
||||||
if (result && result.message && result.code !== 200) {
|
const errorMsg = result?.message || '搜索失败';
|
||||||
console.error('搜索失败:', result.message);
|
console.error('❌ 搜索失败:', errorMsg);
|
||||||
}
|
ElMessage.error(errorMsg);
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.catch(error => {
|
.catch(error => {
|
||||||
console.error('搜索错误:', error);
|
console.error('❌ 搜索错误:', error);
|
||||||
searchResults.value = [];
|
searchResults.value = [];
|
||||||
ElMessage.error('搜索失败,请稍后重试');
|
|
||||||
|
if (error.message !== 'Unauthorized') {
|
||||||
|
ElMessage.error('搜索失败,请稍后重试');
|
||||||
|
}
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user