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

View File

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