增加了工具页面
This commit is contained in:
@@ -79,7 +79,7 @@
|
||||
</a>
|
||||
<a href="#" data-page="model-deploy" class="nav-link flex items-center px-4 py-2.5 hover:bg-sidebarBg/20 transition-colors">
|
||||
<i class="fa fa-server w-5 text-center"></i>
|
||||
<span class="ml-2">模型部署</span>
|
||||
<span class="ml-2">模型对比</span>
|
||||
</a>
|
||||
|
||||
<!-- 第二分区:资源管理 -->
|
||||
@@ -94,7 +94,7 @@
|
||||
</a>
|
||||
<a href="#" data-page="data-generate" class="nav-link flex items-center px-4 py-2.5 hover:bg-sidebarBg/20 transition-colors">
|
||||
<i class="fa fa-database w-5 text-center"></i>
|
||||
<span class="ml-2">数据生成</span>
|
||||
<span class="ml-2">其他工具</span>
|
||||
</a>
|
||||
|
||||
<!-- 第三分区:系统设置 -->
|
||||
@@ -229,18 +229,14 @@
|
||||
actions: ['preview', 'download', 'delete']
|
||||
},
|
||||
'data-generate': {
|
||||
title: '数据生成',
|
||||
api: 'data-generate',
|
||||
hasCreate: true,
|
||||
createText: '新建生成任务',
|
||||
columns: [
|
||||
{ title: '任务名称', key: 'name' },
|
||||
{ title: '模板', key: 'template' },
|
||||
{ title: '生成数', key: 'count' },
|
||||
{ title: '状态', key: 'status' },
|
||||
{ title: '创建时间', key: 'create_time', render: (val) => val ? new Date(val).toLocaleString('zh-CN') : '-' }
|
||||
title: '其他工具',
|
||||
isTools: true,
|
||||
defaultTools: [
|
||||
{ id: 'data-generate', name: '数据生成', icon: 'fa-database', description: '基于LLM生成微调数据集' },
|
||||
{ id: 'json2jsonl', name: 'JSON转JSONL', icon: 'fa-code', description: '将JSON文件转换为JSONL格式' },
|
||||
{ id: 'md-convert', name: '转换Markdown', icon: 'fa-file-text', description: '将Markdown文件转换为训练数据' }
|
||||
],
|
||||
actions: ['stop', 'detail', 'delete']
|
||||
customTools: []
|
||||
},
|
||||
'model-manage': {
|
||||
title: '模型管理',
|
||||
@@ -287,6 +283,12 @@
|
||||
|
||||
// 页面加载完成后初始化
|
||||
document.addEventListener('DOMContentLoaded', function() {
|
||||
// 从 localStorage 加载自定义工具
|
||||
const savedCustomTools = localStorage.getItem('customTools');
|
||||
if (savedCustomTools) {
|
||||
tableConfigs['data-generate'].customTools = JSON.parse(savedCustomTools);
|
||||
}
|
||||
|
||||
// 检查URL参数
|
||||
const urlParams = new URLSearchParams(window.location.search);
|
||||
const pageParam = urlParams.get('page');
|
||||
@@ -340,19 +342,14 @@
|
||||
`;
|
||||
|
||||
try {
|
||||
// 获取数据
|
||||
let data = [];
|
||||
if (config.isForm) {
|
||||
// 平台配置页面,直接获取配置列表
|
||||
data = await fetchData(`${API_BASE}/${config.api}`);
|
||||
} else {
|
||||
data = await fetchData(`${API_BASE}/${config.api}`);
|
||||
}
|
||||
|
||||
// 渲染页面
|
||||
if (config.isForm) {
|
||||
const data = await fetchData(`${API_BASE}/${config.api}`);
|
||||
container.innerHTML = renderConfigPage(config, data);
|
||||
} else if (config.isTools) {
|
||||
container.innerHTML = renderToolsPage(config);
|
||||
} else {
|
||||
const data = await fetchData(`${API_BASE}/${config.api}`);
|
||||
container.innerHTML = renderTablePage(config, data);
|
||||
}
|
||||
} catch (error) {
|
||||
@@ -462,6 +459,103 @@
|
||||
`;
|
||||
}
|
||||
|
||||
// 渲染工具卡片页面
|
||||
function renderToolsPage(config) {
|
||||
// 渲染单个工具卡片
|
||||
const renderToolCard = (tool, canDelete = false, isCustom = false) => `
|
||||
<div class="relative group border border-gray-200 rounded-lg p-6 cursor-pointer hover:border-primary hover:shadow-md transition-all ${canDelete ? '' : ''}" onclick="navigateToTool('${tool.id}', '${tool.url || ''}', ${isCustom})">
|
||||
<div class="w-12 h-12 rounded-lg bg-primary/10 flex items-center justify-center mb-4 group-hover:bg-primary/20 transition-colors">
|
||||
<i class="fa ${tool.icon} text-xl text-primary"></i>
|
||||
</div>
|
||||
<h3 class="text-base font-medium text-gray-800 mb-2">${tool.name}</h3>
|
||||
<p class="text-sm text-gray-500">${tool.description}</p>
|
||||
${canDelete ? `
|
||||
<button onclick="event.stopPropagation(); editCustomTool('${tool.id}')" class="absolute top-2 right-10 w-6 h-6 rounded-full bg-gray-100 hover:bg-blue-100 flex items-center justify-center opacity-0 group-hover:opacity-100 transition-opacity z-10" title="修改">
|
||||
<i class="fa fa-pencil text-gray-400 hover:text-blue-500 text-xs"></i>
|
||||
</button>
|
||||
<button onclick="event.stopPropagation(); deleteCustomTool('${tool.id}')" class="absolute top-2 right-2 w-6 h-6 rounded-full bg-gray-100 hover:bg-red-100 flex items-center justify-center opacity-0 group-hover:opacity-100 transition-opacity z-10" title="删除">
|
||||
<i class="fa fa-times text-gray-400 hover:text-red-500 text-xs"></i>
|
||||
</button>
|
||||
` : ''}
|
||||
</div>
|
||||
`;
|
||||
|
||||
const defaultCards = config.defaultTools.map(t => renderToolCard(t, false, false)).join('');
|
||||
const customCards = config.customTools.map(t => renderToolCard(t, true, true)).join('');
|
||||
|
||||
return `
|
||||
<div class="bg-white rounded-lg shadow-sm mb-6">
|
||||
<div class="flex items-center justify-between p-4 border-b border-gray-100">
|
||||
<h2 class="text-lg font-medium">${config.title}</h2>
|
||||
<button onclick="showCreateToolModal()" class="bg-primary text-white px-3 py-1.5 rounded text-sm hover:bg-primary/90 transition-colors">
|
||||
<i class="fa fa-plus mr-1"></i>添加自定义工具
|
||||
</button>
|
||||
</div>
|
||||
<div class="p-6">
|
||||
<!-- 默认工具 -->
|
||||
<h3 class="text-sm font-semibold text-gray-700 mb-4 pb-2 border-b border-gray-100">默认工具</h3>
|
||||
<div class="grid grid-cols-3 gap-6 mb-8">
|
||||
${defaultCards || '<p class="text-gray-400 text-sm col-span-3">暂无默认工具</p>'}
|
||||
</div>
|
||||
|
||||
<!-- 自定义工具 -->
|
||||
<h3 class="text-sm font-semibold text-gray-700 mb-4 pb-2 border-b border-gray-100">自定义工具</h3>
|
||||
<div class="grid grid-cols-3 gap-6">
|
||||
${customCards || '<p class="text-gray-400 text-sm col-span-3">暂无自定义工具,点击右上角添加</p>'}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
`;
|
||||
}
|
||||
|
||||
// 删除自定义工具
|
||||
function deleteCustomTool(toolId) {
|
||||
showConfirm('确认删除', '确定要删除这个自定义工具吗?', () => {
|
||||
const config = tableConfigs['data-generate'];
|
||||
config.customTools = config.customTools.filter(t => t.id !== toolId);
|
||||
// 保存到 localStorage
|
||||
localStorage.setItem('customTools', JSON.stringify(config.customTools));
|
||||
document.getElementById('page-content').innerHTML = renderToolsPage(config);
|
||||
// 删除成功,无需额外弹窗提示
|
||||
});
|
||||
}
|
||||
|
||||
// 修改自定义工具
|
||||
function editCustomTool(toolId) {
|
||||
const config = tableConfigs['data-generate'];
|
||||
const tool = config.customTools.find(t => t.id === toolId);
|
||||
if (tool) {
|
||||
// 将工具信息存储到 localStorage,编辑页面读取
|
||||
localStorage.setItem('editTool', JSON.stringify(tool));
|
||||
window.location.href = 'custom-tool-create.html?edit=true';
|
||||
}
|
||||
}
|
||||
|
||||
// 显示创建工具弹窗
|
||||
function showCreateToolModal() {
|
||||
window.location.href = 'custom-tool-create.html';
|
||||
}
|
||||
|
||||
// 跳转到工具页面
|
||||
function navigateToTool(toolId, url, isCustom = false) {
|
||||
if (isCustom && url) {
|
||||
// 自定义工具,使用配置的URL
|
||||
if (url.startsWith('http')) {
|
||||
window.open(url, '_blank');
|
||||
} else {
|
||||
window.location.href = url;
|
||||
}
|
||||
} else if (toolId === 'data-generate') {
|
||||
window.location.href = 'data-generate.html';
|
||||
} else if (toolId === 'json2jsonl') {
|
||||
showMessage('提示', 'JSON转JSONL 工具开发中...', 'info');
|
||||
} else if (toolId === 'md-convert') {
|
||||
showMessage('提示', '转换Markdown 工具开发中...', 'info');
|
||||
} else {
|
||||
showMessage('提示', `${toolId} 功能开发中...`, 'info');
|
||||
}
|
||||
}
|
||||
|
||||
// 渲染配置页面
|
||||
function renderConfigPage(config, data) {
|
||||
return `
|
||||
@@ -1265,22 +1359,22 @@
|
||||
|
||||
<!-- 自定义消息弹窗 -->
|
||||
<div id="customModal" class="hidden fixed inset-0 bg-black/50 z-50 flex items-center justify-center" onclick="if(event.target === this) closeModal();">
|
||||
<div class="bg-white rounded-xl shadow-xl max-w-md w-full mx-4 overflow-hidden transform transition-all">
|
||||
<div class="p-6 text-center">
|
||||
<div class="bg-white rounded-xl shadow-xl max-w-sm w-full mx-4 overflow-hidden transform transition-all">
|
||||
<div class="flex flex-col items-center justify-center min-h-[160px] py-6">
|
||||
<div id="modalIcon"></div>
|
||||
<h3 id="modalTitle" class="text-lg font-medium text-gray-800 mb-2"></h3>
|
||||
<h3 id="modalTitle" class="text-base font-medium text-gray-800 mb-2"></h3>
|
||||
<p id="modalMessage" class="text-gray-600 text-sm"></p>
|
||||
</div>
|
||||
<div id="modalBtnGroup" class="hidden px-6 pb-6 flex justify-center space-x-3">
|
||||
<button id="modalCancelBtn" class="px-6 py-2 border border-gray-300 text-gray-700 rounded-lg hover:bg-gray-50 transition-colors">
|
||||
取消
|
||||
</button>
|
||||
<button id="modalConfirmBtn" class="px-6 py-2 text-white rounded-lg transition-colors">
|
||||
<div id="modalBtnGroup" class="hidden px-6 pb-6 flex flex-col space-y-2 mx-4">
|
||||
<button id="modalConfirmBtn" class="px-4 py-2 w-full text-white rounded transition-colors text-sm">
|
||||
确定
|
||||
</button>
|
||||
<button id="modalCancelBtn" class="px-4 py-2 w-full border border-gray-300 text-gray-700 rounded hover:bg-gray-50 transition-colors text-sm">
|
||||
取消
|
||||
</button>
|
||||
</div>
|
||||
<div id="modalSingleBtnGroup" class="px-6 pb-6 flex justify-center">
|
||||
<button id="modalConfirmBtn2" class="px-6 py-2 text-white rounded-lg transition-colors">
|
||||
<button id="modalConfirmBtn2" class="px-6 py-2 w-full text-white rounded transition-colors text-sm max-w-[160px]">
|
||||
确定
|
||||
</button>
|
||||
</div>
|
||||
|
||||
Reference in New Issue
Block a user