fix: 优化前端URL构建逻辑,避免userId=-1问题

1. 修改地图初始化逻辑:
   - 从URL参数动态获取userId,而不是硬编码'-1'
   - 如果没有userId参数,则不传递该参数给后端

2. 优化API URL构建:
   - 只有在有有效userId时才添加userId参数
   - 避免userId=-1、all等特殊值的传递

3. 支持的URL格式:
   - /bigscreen_main?customerId=xxx (查询所有用户)
   - /bigscreen_main?customerId=xxx&userId=123 (查询特定用户)

现在前端页面刷新时不会再产生userId=-1的问题。

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <[email protected]>
This commit is contained in:
2025-09-05 15:48:54 +08:00
co-authored by Claude
parent a8457683b5
commit b62b3faace
@@ -2608,7 +2608,10 @@
// 🗺️ 地图初始化 - 修复地图未初始化问题
console.log('🗺️ 开始初始化地图...');
try {
initializeMap('{{ customerId }}', '-1');
// 从URL获取userId参数,如果没有则不传递
const urlParams = new URLSearchParams(window.location.search);
const userId = urlParams.get('userId') || null;
initializeMap('{{ customerId }}', userId);
console.log('✅ 地图初始化完成');
} catch (error) {
console.error('❌ 地图初始化失败:', error);
@@ -3055,12 +3058,15 @@
//console.log('initializeMap.userId',userId);
//console.log('initializeMap.severityLevel',`./generateAlertJson?customerId=${deptId}&userId=${userId}&severityLevel=critical`);
// v1.0.32 - 添加medium级别告警点支持
// v1.0.32 - 添加medium级别告警点支持,优化URL构建逻辑
const baseParams = `customerId=${deptId}`;
const userParam = (userId && userId !== '-1' && userId !== 'all') ? `&userId=${userId}` : '';
const dataUrls = {
critical: `./generateAlertJson?customerId=${deptId}&userId=${userId}&severityLevel=critical`,
high: `./generateAlertJson?customerId=${deptId}&userId=${userId}&severityLevel=high`,
medium: `./generateAlertJson?customerId=${deptId}&userId=${userId}&severityLevel=medium`, // 新增medium级别
health: `./generateHealthJson?customerId=${deptId}&userId=${userId}`
critical: `./generateAlertJson?${baseParams}${userParam}&severityLevel=critical`,
high: `./generateAlertJson?${baseParams}${userParam}&severityLevel=high`,
medium: `./generateAlertJson?${baseParams}${userParam}&severityLevel=medium`,
health: `./generateHealthJson?${baseParams}${userParam}`
};
console.log('🔗 数据URL准备完成,等待地图加载');
@@ -4420,7 +4426,10 @@ document.addEventListener('DOMContentLoaded', () => {
// 🗺️ 地图初始化 - 修复地图未初始化问题
console.log('🗺️ 开始初始化地图...');
try {
initializeMap('{{ customerId }}', '-1');
// 从URL获取userId参数,如果没有则不传递
const urlParams = new URLSearchParams(window.location.search);
const userId = urlParams.get('userId') || null;
initializeMap('{{ customerId }}', userId);
console.log('✅ 地图初始化完成');
} catch (error) {
console.error('❌ 地图初始化失败:', error);
@@ -7040,7 +7049,9 @@ div.innerHTML=`
// 重新初始化地图
const urlParams = new URLSearchParams(window.location.search);
const customerId = urlParams.get('customerId') || '{{ customerId }}' || '1';
initializeMap(customerId, '-1');
// 从URL获取userId参数,如果没有则不传递
const userId = urlParams.get('userId') || null;
initializeMap(customerId, userId);
// 等待地图初始化完成再更新数据
setTimeout(() => {