简化分类导出导入,仅处理分类本身不含数据项

This commit is contained in:
2026-07-11 00:14:08 +08:00
parent bc2720257d
commit f83bf11669
3 changed files with 38 additions and 174 deletions
+4 -26
View File
@@ -2828,26 +2828,6 @@
html += `<div class="font-medium text-gray-800"><i class="ri-folder-line mr-1"></i>单个分类: ${importData.category.name}</div>`;
}
// 数据项
const itemTypes = ['models', 'gpus', 'cpus', 'items'];
let totalItems = 0;
itemTypes.forEach(type => {
if (importData[type] && importData[type].length > 0) {
totalItems += importData[type].length;
html += `<div class="text-sm text-gray-600 ml-5"><i class="ri-database-line mr-1"></i>${type}: ${importData[type].length} 条</div>`;
}
});
// 动态分类数据
const dynamicCats = Object.keys(importData).filter(k =>
k !== 'categories' && k !== 'category' && k !== 'export_time' && k !== 'version' &&
!itemTypes.includes(k) && Array.isArray(importData[k])
);
dynamicCats.forEach(catId => {
totalItems += importData[catId].length;
html += `<div class="text-sm text-gray-600 ml-5"><i class="ri-database-line mr-1"></i>${catId}: ${importData[catId].length} 条</div>`;
});
html += `<div class="mt-3 text-sm text-gray-500">导出时间: ${importData.export_time || '未知'}</div>`;
html += '</div>';content.innerHTML = html;
}
@@ -2860,15 +2840,14 @@
}
const mode = document.getElementById('importMode').value;
const categoryId = document.getElementById('importCategoryId').value;
try {
let endpoint;
if (categoryId && importData.category) {
if (importData.category) {
// 导入单个分类
endpoint = `/api/categories/import/${categoryId}?mode=${mode}`;
endpoint = `/api/categories/import/${importData.category.id}?mode=${mode}`;
} else {
// 导入全部
// 导入全部分类
endpoint = `/api/categories/import?mode=${mode}`;
}
@@ -2884,7 +2863,7 @@
alert('导入失败: ' + result.error);
} else {
let msg = '导入成功!\n';
msg += `新增分类: ${result.imported_categories || 0}\n`;msg += `新增数据: ${result.imported_items || 0}\n`;msg += `更新数据: ${result.updated_items || 0}`;
msg += `新增分类: ${result.imported || 0}\n`;msg += `更新分类: ${result.updated || 0}`;
if (result.skipped && result.skipped.length > 0) {
msg += `\n跳过已存在分类: ${result.skipped.join(', ')}`;
}
@@ -2894,7 +2873,6 @@
await loadCategories();
renderSidebar();
loadAdminCategories();
loadOverview();
}
} catch (e) {
alert('导入失败: ' + e.message);