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

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

@@ -208,6 +208,15 @@ color: white;
background: #d35400;
}
.btn-info {
background: #17a2b8;
color: white;
}
.btn-info:hover {
background: #138496;
}
.btn-secondary {
background: #eef2f7;
color: #555;

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 = '';
}

View File

@@ -77,6 +77,7 @@ function renderSumDataList(rawList) {
split_type: item.split_type,
split_value: item.split_value,
split_name: item.split_name,
sort_order: item.sort_order || 9999,
total_orders: item.total_orders || 0,
data_source: item.data_source,
remark: item.remark || '',
@@ -97,7 +98,7 @@ function renderSumDataList(rawList) {
sumDataGroupedList = Object.values(groupMap).sort((a, b) => {
if (a.report_date !== b.report_date) return b.report_date.localeCompare(a.report_date);
return (a.config_name || '').localeCompare(b.config_name || '');
return (a.sort_order || 9999) - (b.sort_order || 9999);
});
// 分页处理
@@ -176,12 +177,21 @@ function renderSumDataPagination(total) {
// 加载求和数据
async function loadSumData(page = 1) {
sumDataCurrentPage = page;
const reportDate = document.getElementById('sum-data-report-date').value;
const startDate = document.getElementById('sum-data-start-date').value;
const endDate = document.getElementById('sum-data-end-date').value;
const configName = document.getElementById('sum-data-config-name').value;
const dataSource = document.getElementById('sum-data-source').value;
const params = new URLSearchParams();
params.append('page', '1');
params.append('page_size', '5000');
if (startDate) params.append('start_date', startDate);
if (endDate) params.append('end_date', endDate);
if (configName) params.append('config_name', configName);
if (dataSource) params.append('data_source', dataSource);
try {
const response = await fetch(`/api/sum-data?page=1&page_size=5000&report_date=${encodeURIComponent(reportDate)}&config_name=${encodeURIComponent(configName)}&data_source=${encodeURIComponent(dataSource)}`);
const response = await fetch(`/api/sum-data?${params.toString()}`);
const result = await response.json();
if (result.success) {
renderSumDataList(result.data.list || []);
@@ -195,7 +205,8 @@ async function loadSumData(page = 1) {
// 清除查询
function clearSumDataQuery() {
document.getElementById('sum-data-report-date').value = '';
document.getElementById('sum-data-start-date').value = '';
document.getElementById('sum-data-end-date').value = '';
document.getElementById('sum-data-config-name').value = '';
document.getElementById('sum-data-source').value = '';
loadSumData(1);
@@ -525,3 +536,33 @@ async function batchDeleteSumData() {
alert('删除失败: ' + error.message);
}
}
async function exportSumData() {
const startDate = document.getElementById('sum-data-start-date').value;
const endDate = document.getElementById('sum-data-end-date').value;
const configName = document.getElementById('sum-data-config-name').value;
const dataSource = document.getElementById('sum-data-source').value;
const params = new URLSearchParams();
if (startDate) params.append('start_date', startDate);
if (endDate) params.append('end_date', endDate);
if (configName) params.append('keyword', configName);
if (dataSource) params.append('data_source', dataSource);
try {
const response = await fetch(`/api/sum-data/export?${params.toString()}`);
const result = await response.json();
if (result.success) {
if (result.total === 0) {
alert('没有可导出的数据');
return;
}
window.open(result.file_path, '_blank');
} else {
alert('导出失败: ' + (result.message || '未知错误'));
}
} catch (error) {
alert('导出失败: ' + error.message);
}
}