增加序号,配置导出,导入,求和采集数据导出

This commit is contained in:
2026-07-14 16:05:43 +08:00
parent fdd232989b
commit cc2214ccf6
9 changed files with 587 additions and 42 deletions

View File

@@ -23,15 +23,17 @@ function renderConfigList(configs) {
const tbody = document.getElementById('config-list');
if (configs.length === 0) {
tbody.innerHTML = '<tr><td colspan="6" class="empty">暂无配置,请点击"创建配置"按钮</td></tr>';
tbody.innerHTML = '<tr><td colspan="7" class="empty">暂无配置,请点击"创建配置"按钮</td></tr>';
return;
}
tbody.innerHTML = configs.map((config, index) => {
const isFirst = index === 0;
const isLast = index === configs.length - 1;
const sortOrder = index + 1;
return `
<tr>
<td style="text-align: center; font-weight: bold; color: #4472C4;">${sortOrder}</td>
<td>${config.config_name}</td>
<td>${config.split_type === 'company_id' ? '按企业 ID' : config.split_type === 'user_id' ? '按用户 ID' : '按场站 ID'}</td>
<td>${config.split_name || config.split_value}</td>
@@ -879,3 +881,56 @@ function onSplitTypeChange() {
document.getElementById('entity-list').innerHTML = '<div class="empty">请先选择拆分方式</div>';
}
}
// 导出配置
function exportConfigs() {
try {
window.open('/api/config/export', '_blank');
} catch (error) {
alert('导出失败: ' + error.message);
}
}
// 导入配置
async function importConfigs(event) {
const fileInput = event.target;
const file = fileInput.files[0];
if (!file) return;
if (!file.name.endsWith('.json')) {
alert('只支持 JSON 格式的配置文件');
fileInput.value = '';
return;
}
if (!confirm('确定要导入配置吗?\n导入的配置会自动命名为"原名称_导入",并默认禁用。')) {
fileInput.value = '';
return;
}
const formData = new FormData();
formData.append('file', file);
try {
const response = await fetch('/api/config/import', {
method: 'POST',
body: formData
});
const result = await response.json();
if (result.success) {
let message = result.message;
if (result.data && result.data.fail_messages && result.data.fail_messages.length > 0) {
message += '\n\n失败详情:\n' + result.data.fail_messages.join('\n');
}
alert(message);
loadConfigs();
} else {
alert('导入失败: ' + (result.message || '未知错误'));
}
} catch (error) {
alert('导入失败: ' + error.message);
}
fileInput.value = '';
}