This commit is contained in:
2025-09-10 08:32:07 +08:00
parent a87e6e4853
commit 5d64aa2648
2 changed files with 43 additions and 52 deletions

View File

@@ -408,62 +408,53 @@ document.addEventListener('DOMContentLoaded', function() {
} }
} }
// 移除内部DOMContentLoaded嵌套直接绑定事件
// 阻止右键菜单冒泡 // 阻止右键菜单冒泡
contextMenu.addEventListener('click', function(e) { contextMenu.addEventListener('click', function(e) {
e.stopPropagation(); e.stopPropagation();
}); });
// 替换原导入按钮事件为直接加载指定JSON文件
document.addEventListener('DOMContentLoaded', function() { // 导入数据按钮事件 - 修复DOMContentLoaded嵌套问题
// 导入数据按钮事件 - 直接加载指定文件版
const importDataBtn = document.getElementById('importDataBtn'); const importDataBtn = document.getElementById('importDataBtn');
if (!importDataBtn) { if (!importDataBtn) {
alert('错误:未找到导入按钮元素!'); //alert('错误:未找到导入按钮元素!');
console.error('导入按钮元素不存在'); console.error('导入按钮元素不存在');
return; } else {
} //alert('导入按钮已找到,准备绑定事件...'); // 调试提示
importDataBtn.addEventListener('click', function() { importDataBtn.addEventListener('click', function() {
alert('开始导入指定数据文件...'); // 确认进入代码逻辑 //alert('导入按钮被点击,开始加载数据...'); // 确认进入点击事件
console.log('开始导入指定JSON文件'); console.log('导入按钮点击事件触发');
// 直接加载指定JSON文件使用相对路径 // 修正JSON文件路径根据HTTP服务器根目录调整
const jsonFilePath = 'json/arrow_data_2025-09-10.json'; // 文件相对路径 const jsonFilePath = './json/arrow_data_2025-09-10.json';
const loadIndex = layer.load(2, {shade: [0.3, '#333']}); const loadIndex = layer.load(2, {shade: [0.3, '#333']});
// 添加完整的错误追踪
console.log('尝试加载JSON文件:', jsonFilePath);
fetch(jsonFilePath) fetch(jsonFilePath)
.then(response => { .then(response => {
alert(`文件请求状态: ${response.status}`); // 网络请求反馈 console.log('服务器响应状态:', response.status);
if (!response.ok) { //alert(`服务器响应状态: ${response.status}`);
throw new Error(`网络响应错误: ${response.status}`); if (!response.ok) throw new Error(`HTTP错误: ${response.status}`);
}
return response.json(); return response.json();
}) })
.then(data => { .then(data => {
alert('JSON文件解析成功,准备保存数据...'); console.log('JSON解析成功:', data);
console.log('JSON文件解析成功:', data); //alert('数据解析成功,准备保存...');
// 保存数据到localStorage // 保存数据到localStorage
if (data.elements) { localStorage.setItem('savedElements', JSON.stringify(data.elements || []));
localStorage.setItem('savedElements', JSON.stringify(data.elements)); localStorage.setItem('centerPoint', JSON.stringify(data.centerPoint || {}));
}
if (data.centerPoint) {
localStorage.setItem('centerPoint', JSON.stringify(data.centerPoint));
}
layer.close(loadIndex); layer.close(loadIndex);
alert('数据导入成功,页面将刷新'); //alert('导入成功,将刷新页面');
layer.msg('数据导入成功,页面将刷新', {icon: 1, time: 1500}, function() {
location.reload(); location.reload();
});
}) })
.catch(error => { .catch(error => {
console.error('完整错误信息:', error);
layer.close(loadIndex); layer.close(loadIndex);
alert(`导入失败: ${error.message}`); // 错误反馈 alert(`导入失败: ${error.message}\n请查看控制台获取详细信息`);
console.error('文件加载/解析错误:', error);
layer.msg('导入失败: ' + error.message, {icon: 5});
});
}); });
}); });
}
}); });

View File

@@ -3,34 +3,34 @@
{ {
"type": "arrow", "type": "arrow",
"imagePath": "images/1.png", "imagePath": "images/1.png",
"left": "645.469px", "left": "653.438px",
"top": "210.891px", "top": "327.547px",
"text": "", "text": "第4野战军8纵",
"referencePoint": "top-left", "referencePoint": "top-right",
"stopDistance": "50" "stopDistance": "100"
}, },
{ {
"type": "arrow", "type": "arrow",
"imagePath": "images/2.png", "imagePath": "images/2.png",
"left": "838.891px", "left": "943.016px",
"top": "-87.625px", "top": "-71.875px",
"text": "", "text": "第4野战军2纵",
"referencePoint": "top-left", "referencePoint": "bottom-left",
"stopDistance": "50" "stopDistance": "100"
}, },
{ {
"type": "arrow", "type": "arrow",
"imagePath": "images/4.png", "imagePath": "images/4.png",
"left": "960.688px", "left": "1006.42px",
"top": "208.344px", "top": "305.703px",
"text": "", "text": "17集团军",
"referencePoint": "top-left", "referencePoint": "top-left",
"stopDistance": "50" "stopDistance": "120"
} }
], ],
"centerPoint": { "centerPoint": {
"left": "871px", "left": "893px",
"top": "172px" "top": "263px"
}, },
"exportTime": "2025-09-10T00:13:39.941Z" "exportTime": "2025-09-10T00:31:21.175Z"
} }