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("address", poi.get("address"));
|
||||
|
||||
// 修复类型转换问题:先转换为String再连接
|
||||
String pname = String.valueOf(poi.get("pname") != null ? poi.get("pname") : "");
|
||||
String cityname = String.valueOf(poi.get("cityname") != null ? poi.get("cityname") : "");
|
||||
String adname = String.valueOf(poi.get("adname") != null ? poi.get("adname") : "");
|
||||
result.put("district", pname + cityname + adname);
|
||||
// 修复类型转换问题:避免 "null" 字符串
|
||||
Object pnameObj = poi.get("pname");
|
||||
Object citynameObj = poi.get("cityname");
|
||||
Object adnameObj = poi.get("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");
|
||||
|
||||
@ -361,38 +361,63 @@ export default {
|
||||
})
|
||||
})
|
||||
.then(response => {
|
||||
console.log('📡 响应状态:', response.status, response.statusText);
|
||||
|
||||
// 检查响应状态
|
||||
if (response.status === 401) {
|
||||
ElMessage.error('登录已过期,请重新登录');
|
||||
localStorage.removeItem('token');
|
||||
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();
|
||||
})
|
||||
.then(result => {
|
||||
console.log('🔍 前端收到后端响应:', result);
|
||||
if (result && result.code === 200 && result.data) {
|
||||
console.log('✅ 响应数据正常:', result.data);
|
||||
searchResults.value = result.data.map(poi => ({
|
||||
id: poi.id,
|
||||
name: poi.name,
|
||||
address: poi.address,
|
||||
district: poi.district,
|
||||
location: { lng: poi.lng, lat: poi.lat },
|
||||
distance: 0
|
||||
}));
|
||||
console.log("🎯 处理后的搜索结果:", searchResults.value);
|
||||
|
||||
if (result && result.code === 200) {
|
||||
if (result.data && result.data.length > 0) {
|
||||
console.log('✅ 响应数据正常:', result.data);
|
||||
searchResults.value = result.data.map(poi => ({
|
||||
id: poi.id,
|
||||
name: poi.name,
|
||||
address: poi.address,
|
||||
district: poi.district,
|
||||
location: { lng: poi.lng, lat: poi.lat },
|
||||
distance: 0
|
||||
}));
|
||||
console.log("🎯 处理后的搜索结果:", searchResults.value);
|
||||
} else {
|
||||
searchResults.value = [];
|
||||
ElMessage.info('未找到相关地址');
|
||||
}
|
||||
} else {
|
||||
searchResults.value = [];
|
||||
if (result && result.message && result.code !== 200) {
|
||||
console.error('搜索失败:', result.message);
|
||||
}
|
||||
const errorMsg = result?.message || '搜索失败';
|
||||
console.error('❌ 搜索失败:', errorMsg);
|
||||
ElMessage.error(errorMsg);
|
||||
}
|
||||
})
|
||||
.catch(error => {
|
||||
console.error('搜索错误:', error);
|
||||
console.error('❌ 搜索错误:', error);
|
||||
searchResults.value = [];
|
||||
ElMessage.error('搜索失败,请稍后重试');
|
||||
|
||||
if (error.message !== 'Unauthorized') {
|
||||
ElMessage.error('搜索失败,请稍后重试');
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user