Files
YG_FT_Platform/web/pages/dataset-preview.html

411 lines
18 KiB
HTML
Raw Normal View History

<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>数据管理-文件预览 - 远光软件微调平台</title>
<script src="../lib/tailwindcss/tailwind.js"></script>
<link href="../lib/font-awesome/css/font-awesome.min.css" rel="stylesheet">
<style>
.sidebar-section-title {
padding: 0.5rem 1rem;
font-size: 0.75rem;
color: rgba(191, 203, 217, 0.7);
font-weight: 500;
text-transform: uppercase;
letter-spacing: 0.05em;
}
.nav-link:hover {
background-color: rgba(0, 21, 41, 0.2);
}
.sidebar-item-active {
background-color: rgba(24, 144, 255, 0.1);
color: #1890ff;
border-left: 4px solid #1890ff;
}
.text-primary { color: #1890ff; }
.bg-primary { background-color: #1890ff; }
.text-danger { color: #f5222d; }
2026-01-21 15:33:43 +08:00
/* 侧边栏滑块动画 */
.sidebar-slider {
position: absolute;
width: 4px;
height: 0;
background-color: #1890ff;
border-radius: 0 2px 2px 0;
transition: top 0.3s cubic-bezier(0.4, 0, 0.2, 1),
height 0.3s cubic-bezier(0.4, 0, 0.2, 1);
pointer-events: none;
z-index: 10;
}
.nav-item-wrapper {
position: relative;
}
.nav-link {
position: relative;
z-index: 1;
}
</style>
</head>
<body class="antialiased bg-gray-50 flex h-screen overflow-hidden">
<!-- 侧边导航 -->
<aside class="w-64 text-[#bfcbd9] flex-shrink-0 hidden md:block flex flex-col h-full" style="background-color: #001529;">
<!-- 平台LOGO区域 -->
2026-01-21 15:33:43 +08:00
<div class="pt-5 pb-3 border-b border-[#001529]/30 flex items-center justify-center pl-2">
<img src="../assets/logo/logo.png" alt="Logo" class="w-8 h-8 object-contain mr-2">
<span class="text-white font-medium text-base">远光软件微调平台</span>
</div>
<!-- 导航主区域 -->
2026-01-21 15:33:43 +08:00
<nav class="flex-1 overflow-y-auto py-2 relative">
<!-- 滑块指示器 -->
<div class="sidebar-slider" id="sidebar-slider"></div>
<!-- 第一分区:模型服务 -->
<div class="sidebar-section-title">模型服务</div>
2026-01-21 15:33:43 +08:00
<div class="nav-item-wrapper">
<a href="#" data-page="fine-tune" class="nav-link flex items-center px-4 py-2.5 hover:bg-[#001529]/20 transition-colors">
<i class="fa fa-cogs w-5 text-center"></i>
<span class="ml-2">模型调优</span>
</a>
</div>
<div class="nav-item-wrapper">
<a href="#" data-page="my-models" class="nav-link flex items-center px-4 py-2.5 hover:bg-[#001529]/20 transition-colors">
<i class="fa fa-database w-5 text-center"></i>
<span class="ml-2">我的模型</span>
</a>
</div>
<div class="nav-item-wrapper">
<a href="#" data-page="model-eval" class="nav-link flex items-center px-4 py-2.5 hover:bg-[#001529]/20 transition-colors">
<i class="fa fa-line-chart w-5 text-center"></i>
<span class="ml-2">模型评测</span>
</a>
</div>
<div class="nav-item-wrapper">
<a href="#" data-page="model-compare" class="nav-link flex items-center px-4 py-2.5 hover:bg-[#001529]/20 transition-colors">
<i class="fa fa-server w-5 text-center"></i>
<span class="ml-2">模型对比</span>
</a>
</div>
<!-- 第二分区:资源管理 -->
<div class="sidebar-section-title mt-6">资源管理</div>
2026-01-21 15:33:43 +08:00
<div class="nav-item-wrapper">
<a href="#" data-page="model-manage" class="nav-link flex items-center px-4 py-2.5 hover:bg-[#001529]/20 transition-colors">
<i class="fa fa-cube w-5 text-center"></i>
<span class="ml-2">模型管理</span>
</a>
</div>
<div class="nav-item-wrapper">
<a href="#" data-page="dataset-manage" class="nav-link flex items-center px-4 py-2.5 hover:bg-[#001529]/20 transition-colors">
<i class="fa fa-file-text w-5 text-center"></i>
<span class="ml-2">数据集管理</span>
</a>
</div>
<div class="nav-item-wrapper">
<a href="#" data-page="data-generate" class="nav-link flex items-center px-4 py-2.5 hover:bg-[#001529]/20 transition-colors">
<i class="fa fa-database w-5 text-center"></i>
<span class="ml-2">其他工具</span>
</a>
</div>
<!-- 第三分区:系统设置 -->
<div class="sidebar-section-title mt-6">系统设置</div>
2026-01-21 15:33:43 +08:00
<div class="nav-item-wrapper">
<a href="#" data-page="config" class="nav-link flex items-center px-4 py-2.5 hover:bg-[#001529]/20 transition-colors">
<i class="fa fa-bar-chart w-5 text-center"></i>
<span class="ml-2">平台性能</span>
</a>
</div>
2026-01-26 14:33:49 +08:00
<div class="nav-item-wrapper">
<a href="main.html?page=logs" data-page="logs" class="nav-link flex items-center px-4 py-2.5 hover:bg-[#001529]/20 transition-colors">
<i class="fa fa-file-text w-5 text-center"></i>
<span class="ml-2">查看日志</span>
</a>
</div>
</nav>
<!-- 底部信息区域 -->
<div class="p-4 border-t border-[#001529]/30 text-xs mt-auto">
<div class="mb-2 text-[#bfcbd9]/80">默认业务空间</div>
<div class="flex items-center justify-between">
<span class="text-[#bfcbd9]">版本 v1.0.0</span>
<i class="fa fa-question-circle-o text-[#bfcbd9]/70"></i>
</div>
</div>
</aside>
<!-- 主内容区 -->
<div class="flex-1 flex flex-col overflow-hidden">
<!-- 顶部导航 -->
<header class="bg-white border-b border-gray-200 shadow-sm">
<div class="flex items-center justify-between px-6 h-14">
<div class="flex items-center space-x-6">
<a href="#" onclick="goBack()" class="text-gray-500 hover:text-gray-700 flex items-center px-3 py-1.5 rounded hover:bg-gray-100 transition-colors">
<i class="fa fa-arrow-left"></i>
<span class="ml-1">返回</span>
</a>
</div>
<div class="flex items-center space-x-4">
<div class="relative group">
<img src="https://picsum.photos/id/1005/32/32" class="w-8 h-8 rounded-full cursor-pointer" alt="用户头像">
<div class="absolute right-0 top-full mt-1 bg-white rounded shadow-lg py-1 hidden group-hover:block border border-gray-100 min-w-[140px] z-50">
<a href="login.html" class="block px-4 py-2 text-sm text-gray-700 hover:bg-gray-50 whitespace-nowrap">
<i class="fa fa-sign-out mr-1"></i>退出登录
</a>
</div>
</div>
</div>
</div>
</header>
<!-- 内容区域 - 文件预览 -->
<main class="flex-1 overflow-y-auto p-6 bg-gray-50">
<div id="page-content">
<!-- 文件预览卡片 -->
<div class="bg-white rounded-lg shadow-sm">
<!-- 面包屑导航 -->
<div class="px-4 py-3 border-b border-gray-100">
<div class="flex items-center text-sm">
<span class="text-primary cursor-pointer hover:underline" onclick="goBack()">数据集管理</span>
<span class="mx-2 text-gray-300">/</span>
<span class="text-gray-800 font-medium">文件预览</span>
</div>
</div>
<!-- 头部 -->
<div class="flex items-center justify-between p-4 border-b border-gray-100">
<div class="flex items-center">
<h2 class="text-lg font-medium">文件预览</h2>
<span id="fileNameDisplay" class="ml-3 text-sm text-gray-500"></span>
</div>
<div class="flex items-center space-x-3">
<button onclick="downloadFile()" class="px-3 py-1.5 bg-primary text-white rounded text-sm hover:bg-primary/90 transition-colors">
<i class="fa fa-download mr-1"></i>导出
</button>
<button onclick="deleteDataset()" class="px-3 py-1.5 border border-red-200 text-red-600 rounded text-sm hover:bg-red-50 transition-colors">
<i class="fa fa-trash mr-1"></i>删除
</button>
</div>
</div>
<!-- 状态栏 -->
<div id="fileStatus" class="px-4 py-3 bg-gray-50 border-b border-gray-100 flex items-center gap-6 text-sm text-gray-600 flex-wrap">
<!-- 动态生成 -->
</div>
<!-- 左侧文件列表 + 右侧预览区域 -->
<div class="flex" style="min-height: 500px;">
<!-- 右侧预览区域 -->
<div class="flex-1 flex flex-col">
<div class="p-3 border-b border-gray-100 bg-gray-50/30">
<h3 class="text-sm font-medium text-gray-700">预览内容</h3>
</div>
<div class="flex-1 p-4 overflow-auto">
<pre id="codePreview" class="text-sm text-gray-700 whitespace-pre-wrap font-mono bg-gray-50 rounded p-4" style="min-height: 400px;">加载中...</pre>
</div>
</div>
</div>
</div>
</div>
</main>
</div>
<script>
// API 基础地址 - 使用 config.yaml 中的 app.port (7861)
const getApiBase = () => {
const protocol = window.location.protocol;
const hostname = window.location.hostname;
return `${protocol}//${hostname}:7861/api`;
};
const API_BASE = getApiBase();
// 获取URL参数
const urlParams = new URLSearchParams(window.location.search);
const datasetId = urlParams.get('id');
const fileId = urlParams.get('fileId');
let currentDataset = null;
let selectedFileId = null;
// 返回上一页面
function goBack() {
window.location.href = 'main.html?page=dataset-manage';
}
// 页面加载完成后初始化
document.addEventListener('DOMContentLoaded', function() {
// 绑定导航点击事件
document.querySelectorAll('.nav-link').forEach(link => {
link.addEventListener('click', function(e) {
e.preventDefault();
const page = this.dataset.page;
window.location.href = `main.html?page=${page}`;
});
});
2026-01-21 15:33:43 +08:00
// 设置侧边栏当前页高亮
const currentPage = 'dataset-manage';
document.querySelectorAll('.nav-link').forEach(link => {
if (link.dataset.page === currentPage) {
link.classList.add('bg-[#1890ff]/10', 'text-[#1890ff]');
link.classList.remove('hover:bg-[#001529]/20', 'transition-colors');
}
});
updateSidebarSlider();
// 加载数据集信息
loadDataset();
});
2026-01-21 15:33:43 +08:00
// 更新侧边栏滑块位置
function updateSidebarSlider() {
const slider = document.getElementById('sidebar-slider');
if (!slider) return;
const activeLink = document.querySelector('.nav-link.bg-\\[\\#1890ff\\]\\/10');
if (activeLink) {
const wrapper = activeLink.closest('.nav-item-wrapper');
if (wrapper) {
slider.style.top = wrapper.offsetTop + 'px';
slider.style.height = wrapper.offsetHeight + 'px';
}
}
}
// 加载数据集信息
async function loadDataset() {
if (!datasetId) {
document.getElementById('codePreview').textContent = '缺少数据集ID参数';
return;
}
try {
const response = await fetch(`${API_BASE}/dataset-manage/${datasetId}`);
const result = await response.json();
if (result.code !== 0) {
document.getElementById('codePreview').textContent = '获取数据集信息失败: ' + (result.message || '未知错误');
return;
}
currentDataset = result.data;
updateUI();
} catch (error) {
document.getElementById('codePreview').textContent = '加载失败: ' + error.message;
}
}
// 更新UI
function updateUI() {
const dataset = currentDataset;
// 更新状态栏
const statusTag = dataset.storage_type === 'local'
? '<span class="px-2 py-0.5 rounded text-xs bg-blue-100 text-blue-700">本地存储</span>'
: '<span class="px-2 py-0.5 rounded text-xs bg-gray-100 text-gray-700">云存储</span>';
const count = dataset.count || 0;
const type = dataset.type || 'JSON/JSONL';
const createTime = dataset.create_time
? new Date(dataset.create_time).toLocaleString('zh-CN')
: '-';
document.getElementById('fileStatus').innerHTML = `
<span class="flex items-center">${statusTag}</span>
<span class="flex items-center">数据量:<span class="text-gray-800 ml-1">${count} 条</span></span>
<span class="flex items-center">数据类型:<span class="text-gray-800 ml-1">${type}</span></span>
<span class="flex items-center">创建时间:<span class="text-gray-800 ml-1">${createTime}</span></span>
`;
// 如果有文件ID选择该文件否则选择第一个文件
const targetFileId = fileId || (dataset.files && dataset.files.length > 0 ? dataset.files[0].id : null);
if (targetFileId) {
selectFile(targetFileId);
}
}
// 选择文件
async function selectFile(id) {
selectedFileId = id;
const previewEl = document.getElementById('codePreview');
previewEl.textContent = '加载中...';
try {
const response = await fetch(`${API_BASE}/dataset-manage/preview/${id}`);
const result = await response.json();
if (result.code !== 0) {
previewEl.textContent = '获取文件预览失败: ' + (result.message || '未知错误');
return;
}
const fileData = result.data;
document.getElementById('fileNameDisplay').textContent = fileData.file_name || '';
// 处理内容限制显示前100条记录
let content = fileData.content || '文件内容为空';
if (content && content.trim()) {
try {
// 尝试解析JSONL格式每行一个JSON对象
const lines = content.split('\n').filter(line => line.trim());
if (lines.length > 100) {
// 限制显示前100条
const limitedLines = lines.slice(0, 100);
content = limitedLines.join('\n') + '\n\n... 共 ' + lines.length + ' 条记录,已显示前 100 条 ...';
}
} catch (e) {
// 如果解析失败,直接显示原内容
}
}
previewEl.textContent = content;
} catch (error) {
previewEl.textContent = '加载失败: ' + error.message;
}
}
// 下载文件
function downloadFile() {
if (!selectedFileId) {
alert('请先选择一个文件');
return;
}
const protocol = window.location.protocol;
const hostname = window.location.hostname;
window.open(`${protocol}//${hostname}:7861/api/dataset-manage/download/${datasetId}/${selectedFileId}`, '_blank');
}
// 删除数据集
function deleteDataset() {
if (!datasetId) {
alert('缺少数据集ID');
return;
}
if (!confirm('确定要删除这个数据集吗?此操作不可恢复。')) {
return;
}
fetch(`${API_BASE}/dataset-manage/${datasetId}`, {
method: 'DELETE'
})
.then(response => response.json())
.then(result => {
if (result.code === 0) {
alert('删除成功');
window.location.href = 'main.html?page=dataset-manage';
} else {
alert('删除失败: ' + (result.message || '未知错误'));
}
})
.catch(error => {
alert('删除失败: ' + error.message);
});
}
</script>
</body>
</html>