增加了工具页面
This commit is contained in:
442
web/pages/custom-tool-create.html
Normal file
442
web/pages/custom-tool-create.html
Normal file
@@ -0,0 +1,442 @@
|
||||
<!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="https://cdn.tailwindcss.com"></script>
|
||||
<link href="https://cdn.jsdelivr.net/npm/font-awesome@4.7.0/css/font-awesome.min.css" rel="stylesheet">
|
||||
<script>
|
||||
tailwind.config = {
|
||||
theme: {
|
||||
extend: {
|
||||
colors: {
|
||||
primary: '#1890ff',
|
||||
sidebarBg: '#001529',
|
||||
sidebarText: '#bfcbd9',
|
||||
headerBg: '#fff',
|
||||
danger: '#f5222d',
|
||||
success: '#52c41a',
|
||||
},
|
||||
fontFamily: {
|
||||
sans: ['Inter', 'system-ui', 'sans-serif'],
|
||||
},
|
||||
}
|
||||
}
|
||||
}
|
||||
</script>
|
||||
<style type="text/tailwindcss">
|
||||
@layer utilities {
|
||||
.sidebar-item-active {
|
||||
@apply bg-primary/10 text-primary border-l-4 border-primary;
|
||||
}
|
||||
.sidebar-section-title {
|
||||
@apply px-4 py-2 text-xs text-sidebarText/70 font-medium uppercase tracking-wider;
|
||||
}
|
||||
.form-input {
|
||||
@apply w-full px-3 py-2 border border-gray-300 rounded-lg text-sm focus:border-primary focus:outline-none transition-colors;
|
||||
}
|
||||
.form-label {
|
||||
@apply block text-sm font-medium text-gray-700 mb-1;
|
||||
}
|
||||
.icon-option {
|
||||
@apply w-10 h-10 rounded-lg border border-gray-200 flex items-center justify-center cursor-pointer hover:border-primary hover:bg-primary/5 transition-all;
|
||||
}
|
||||
.icon-option.selected {
|
||||
@apply border-primary bg-primary/10;
|
||||
}
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body class="antialiased bg-gray-50 flex h-screen overflow-hidden">
|
||||
<!-- 侧边导航 -->
|
||||
<aside class="w-64 bg-sidebarBg text-sidebarText flex-shrink-0 hidden md:block flex flex-col h-full">
|
||||
<!-- 平台LOGO区域 -->
|
||||
<div class="p-4 border-b border-sidebarBg/30 flex items-center">
|
||||
<img src="../assets/logo/logo.png" alt="Logo" class="w-6 h-6 object-contain mr-2">
|
||||
<span class="text-white font-medium">远光软件微调平台</span>
|
||||
</div>
|
||||
|
||||
<!-- 导航主区域 -->
|
||||
<nav class="flex-1 overflow-y-auto py-2">
|
||||
<!-- 第一分区:模型服务 -->
|
||||
<div class="sidebar-section-title">模型服务</div>
|
||||
<a href="main.html" data-page="fine-tune" class="nav-link flex items-center px-4 py-2.5 hover:bg-sidebarBg/20 transition-colors">
|
||||
<i class="fa fa-cogs w-5 text-center"></i>
|
||||
<span class="ml-2">模型调优</span>
|
||||
</a>
|
||||
<a href="main.html?page=my-models" data-page="my-models" 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>
|
||||
</a>
|
||||
<a href="main.html?page=model-eval" data-page="model-eval" class="nav-link flex items-center px-4 py-2.5 hover:bg-sidebarBg/20 transition-colors">
|
||||
<i class="fa fa-line-chart w-5 text-center"></i>
|
||||
<span class="ml-2">模型评测</span>
|
||||
</a>
|
||||
<a href="main.html?page=model-deploy" 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>
|
||||
</a>
|
||||
|
||||
<!-- 第二分区:资源管理 -->
|
||||
<div class="sidebar-section-title mt-6">资源管理</div>
|
||||
<a href="main.html?page=model-manage" data-page="model-manage" class="nav-link flex items-center px-4 py-2.5 hover:bg-sidebarBg/20 transition-colors">
|
||||
<i class="fa fa-cube w-5 text-center"></i>
|
||||
<span class="ml-2">模型管理</span>
|
||||
</a>
|
||||
<a href="main.html?page=dataset-manage" data-page="dataset-manage" class="nav-link flex items-center px-4 py-2.5 hover:bg-sidebarBg/20 transition-colors">
|
||||
<i class="fa fa-file-text w-5 text-center"></i>
|
||||
<span class="ml-2">数据集管理</span>
|
||||
</a>
|
||||
<a href="main.html?page=data-generate" 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>
|
||||
</a>
|
||||
|
||||
<!-- 第三分区:系统设置 -->
|
||||
<div class="sidebar-section-title mt-6">系统设置</div>
|
||||
<a href="main.html?page=config" data-page="config" class="nav-link flex items-center px-4 py-2.5 hover:bg-sidebarBg/20 transition-colors">
|
||||
<i class="fa fa-bar-chart w-5 text-center"></i>
|
||||
<span class="ml-2">平台性能</span>
|
||||
</a>
|
||||
</nav>
|
||||
|
||||
<!-- 底部信息区域 -->
|
||||
<div class="p-4 border-t border-sidebarBg/30 text-xs mt-auto">
|
||||
<div class="mb-2 text-sidebarText/80">默认业务空间</div>
|
||||
<div class="flex items-center justify-between">
|
||||
<span class="text-sidebarText">版本 v1.0.0</span>
|
||||
<i class="fa fa-question-circle-o text-sidebarText/70"></i>
|
||||
</div>
|
||||
</div>
|
||||
</aside>
|
||||
|
||||
<!-- 主内容区 -->
|
||||
<div class="flex-1 flex flex-col overflow-hidden">
|
||||
<!-- 顶部导航 -->
|
||||
<header class="bg-headerBg 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-4">
|
||||
<a href="main.html?page=data-generate" class="text-gray-500 hover:text-gray-700 flex items-center">
|
||||
<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-2 bg-white rounded shadow-lg py-1 hidden group-hover:block border border-gray-100 min-w-[140px]">
|
||||
<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 class="bg-white rounded-lg shadow-sm p-4 border-b border-gray-100 mb-4">
|
||||
<div class="flex items-center text-sm">
|
||||
<span class="text-primary cursor-pointer hover:underline" onclick="window.location.href='main.html?page=data-generate'">其他工具</span>
|
||||
<span class="mx-2 text-gray-300">/</span>
|
||||
<span class="text-gray-800 font-medium" id="pageTitle">添加自定义工具</span>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- 表单内容 -->
|
||||
<div class="bg-white rounded-lg shadow-sm">
|
||||
<div class="p-6 max-w-2xl">
|
||||
<form id="toolForm">
|
||||
<!-- 工具名称 -->
|
||||
<div class="mb-6">
|
||||
<label class="form-label">
|
||||
<span class="text-red-500 mr-1">*</span>工具名称
|
||||
</label>
|
||||
<input type="text" name="name" class="form-input" placeholder="请输入工具名称" maxlength="30">
|
||||
<p class="text-xs text-gray-400 mt-1">支持中文、英文、数字,最多30个字符</p>
|
||||
</div>
|
||||
|
||||
<!-- 工具描述 -->
|
||||
<div class="mb-6">
|
||||
<label class="form-label">工具描述</label>
|
||||
<textarea name="description" rows="3" class="form-input resize-none" placeholder="请输入工具描述" maxlength="100"></textarea>
|
||||
<p class="text-xs text-gray-400 mt-1"><span id="descCount">0</span> / 100</p>
|
||||
</div>
|
||||
|
||||
<!-- 跳转地址 -->
|
||||
<div class="mb-6">
|
||||
<label class="form-label">
|
||||
<span class="text-red-500 mr-1">*</span>跳转地址
|
||||
</label>
|
||||
<input type="text" name="url" class="form-input" placeholder="如:custom-tool.html 或 https://example.com">
|
||||
<p class="text-xs text-gray-400 mt-1">输入工具页面的相对路径或完整URL</p>
|
||||
</div>
|
||||
|
||||
<!-- 图标选择 -->
|
||||
<div class="mb-6">
|
||||
<label class="form-label">选择图标</label>
|
||||
<div class="grid grid-cols-8 gap-2" id="iconGrid"></div>
|
||||
<input type="hidden" id="selectedIcon" value="fa-cog" name="icon">
|
||||
</div>
|
||||
|
||||
<!-- 底部按钮 -->
|
||||
<div class="flex items-center justify-between pt-6 border-t border-gray-100">
|
||||
<div class="flex items-center space-x-3">
|
||||
<button type="button" onclick="submitForm()" class="px-4 py-2 bg-primary text-white rounded-lg text-sm hover:bg-primary/90 transition-colors">
|
||||
<i class="fa fa-check mr-2"></i>保存
|
||||
</button>
|
||||
<a href="main.html?page=data-generate" class="px-4 py-2 bg-gray-200 text-gray-700 rounded-lg text-sm hover:bg-gray-300 transition-colors">
|
||||
<i class="fa fa-times mr-2"></i>取消
|
||||
</a>
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
</main>
|
||||
</div>
|
||||
|
||||
<script>
|
||||
// API 基础地址
|
||||
const getApiBase = () => {
|
||||
const protocol = window.location.protocol;
|
||||
const hostname = window.location.hostname;
|
||||
return `${protocol}//${hostname}:8080/api`;
|
||||
};
|
||||
const API_BASE = getApiBase();
|
||||
|
||||
// 当前是否为编辑模式
|
||||
let isEditMode = false;
|
||||
let editToolId = null;
|
||||
|
||||
// 可选图标列表
|
||||
function getIconOptions() {
|
||||
return [
|
||||
'fa-cog', 'fa-cogs', 'fa-database', 'fa-code', 'fa-file-text',
|
||||
'fa-file-code', 'fa-file-excel', 'fa-file', 'fa-folder',
|
||||
'fa-wrench', 'fa-tools', 'fa-magic', 'fa-puzzle-piece',
|
||||
'fa-plug', 'fa-cube', 'fa-cubes', 'fa-gear', 'fa-sliders',
|
||||
'fa-filter', 'fa-refresh', 'fa-exchange', 'fa-arrows-alt',
|
||||
'fa-random', 'fa-random', 'fa-link', 'fa-chain',
|
||||
'fa-edit', 'fa-pencil', 'fa-pen', 'fa-plus-circle',
|
||||
'fa-star', 'fa-heart', 'fa-bookmark', 'fa-tag'
|
||||
];
|
||||
}
|
||||
|
||||
// 页面加载完成后初始化
|
||||
document.addEventListener('DOMContentLoaded', function() {
|
||||
// 检查是否为编辑模式
|
||||
const urlParams = new URLSearchParams(window.location.search);
|
||||
isEditMode = urlParams.get('edit') === 'true';
|
||||
|
||||
// 渲染图标选择
|
||||
renderIconGrid();
|
||||
|
||||
// 如果是编辑模式,加载工具数据
|
||||
if (isEditMode) {
|
||||
loadToolForEdit();
|
||||
}
|
||||
|
||||
// 描述字数统计
|
||||
const descInput = document.querySelector('textarea[name="description"]');
|
||||
if (descInput) {
|
||||
descInput.addEventListener('input', () => {
|
||||
document.getElementById('descCount').textContent = descInput.value.length;
|
||||
});
|
||||
}
|
||||
|
||||
// 绑定导航点击事件
|
||||
document.querySelectorAll('.nav-link').forEach(link => {
|
||||
link.addEventListener('click', function(e) {
|
||||
if (!this.href.includes('custom-tool-create')) {
|
||||
e.preventDefault();
|
||||
window.location.href = this.href;
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
// 加载工具数据进行编辑
|
||||
function loadToolForEdit() {
|
||||
const editToolStr = localStorage.getItem('editTool');
|
||||
if (editToolStr) {
|
||||
const tool = JSON.parse(editToolStr);
|
||||
editToolId = tool.id;
|
||||
|
||||
// 更新页面标题
|
||||
document.getElementById('pageTitle').textContent = '修改自定义工具';
|
||||
document.title = '修改自定义工具 / 远光软件微调平台';
|
||||
|
||||
// 填充表单
|
||||
document.querySelector('input[name="name"]').value = tool.name || '';
|
||||
document.querySelector('textarea[name="description"]').value = tool.description || '';
|
||||
document.querySelector('input[name="url"]').value = tool.url || '';
|
||||
|
||||
// 选中图标
|
||||
const icon = tool.icon || 'fa-cog';
|
||||
setSelectedIcon(icon);
|
||||
|
||||
// 更新字数统计
|
||||
document.getElementById('descCount').textContent = (tool.description || '').length;
|
||||
}
|
||||
}
|
||||
|
||||
// 设置选中的图标
|
||||
function setSelectedIcon(iconClass) {
|
||||
document.querySelectorAll('.icon-option').forEach(item => {
|
||||
item.classList.remove('selected');
|
||||
if (item.dataset.icon === iconClass) {
|
||||
item.classList.add('selected');
|
||||
}
|
||||
});
|
||||
document.querySelector('input[name="icon"]').value = iconClass;
|
||||
}
|
||||
|
||||
// 渲染图标选择网格
|
||||
function renderIconGrid() {
|
||||
const iconGrid = document.getElementById('iconGrid');
|
||||
const icons = getIconOptions();
|
||||
iconGrid.innerHTML = icons.map((icon, idx) => `
|
||||
<div class="icon-option ${idx === 0 ? 'selected' : ''}" data-icon="${icon}" onclick="selectIcon(this)">
|
||||
<i class="fa ${icon} text-lg text-gray-600"></i>
|
||||
</div>
|
||||
`).join('');
|
||||
}
|
||||
|
||||
// 选择图标
|
||||
function selectIcon(el) {
|
||||
document.querySelectorAll('.icon-option').forEach(item => {
|
||||
item.classList.remove('selected');
|
||||
});
|
||||
el.classList.add('selected');
|
||||
document.querySelector('input[name="icon"]').value = el.dataset.icon;
|
||||
}
|
||||
|
||||
// 提交表单
|
||||
function submitForm() {
|
||||
console.log('submitForm called');
|
||||
const form = document.getElementById('toolForm');
|
||||
const formData = new FormData(form);
|
||||
const name = formData.get('name').trim();
|
||||
const url = formData.get('url').trim();
|
||||
const icon = formData.get('icon');
|
||||
const description = formData.get('description').trim();
|
||||
|
||||
if (!name) {
|
||||
showMessage('提示', '请输入工具名称', 'warning');
|
||||
return;
|
||||
}
|
||||
if (!url) {
|
||||
showMessage('提示', '请输入跳转地址', 'warning');
|
||||
return;
|
||||
}
|
||||
|
||||
if (isEditMode && editToolId) {
|
||||
// 编辑模式:更新现有工具
|
||||
updateCustomTool(editToolId, name, description, icon, url);
|
||||
} else {
|
||||
// 新增模式:创建新工具
|
||||
const toolId = 'custom_' + Date.now();
|
||||
const newTool = {
|
||||
id: toolId,
|
||||
name: name,
|
||||
description: description || '自定义工具',
|
||||
icon: icon,
|
||||
url: url
|
||||
};
|
||||
saveCustomTool(newTool);
|
||||
showMessage('成功', '自定义工具添加成功!', 'success', () => {
|
||||
window.location.href = 'main.html?page=data-generate';
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
// 更新自定义工具
|
||||
function updateCustomTool(toolId, name, description, icon, url) {
|
||||
let customTools = JSON.parse(localStorage.getItem('customTools') || '[]');
|
||||
const index = customTools.findIndex(t => t.id === toolId);
|
||||
if (index !== -1) {
|
||||
customTools[index] = {
|
||||
...customTools[index],
|
||||
name: name,
|
||||
description: description || '自定义工具',
|
||||
icon: icon,
|
||||
url: url
|
||||
};
|
||||
localStorage.setItem('customTools', JSON.stringify(customTools));
|
||||
// 清除编辑数据
|
||||
localStorage.removeItem('editTool');
|
||||
showMessage('成功', '自定义工具修改成功!', 'success', () => {
|
||||
window.location.href = 'main.html?page=data-generate';
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
// 保存自定义工具
|
||||
function saveCustomTool(tool) {
|
||||
let customTools = JSON.parse(localStorage.getItem('customTools') || '[]');
|
||||
customTools.push(tool);
|
||||
localStorage.setItem('customTools', JSON.stringify(customTools));
|
||||
}
|
||||
|
||||
// ============ 自定义消息弹窗 ============
|
||||
function showMessage(title, message, type = 'info', onConfirm) {
|
||||
const modal = document.getElementById('customModal');
|
||||
const modalTitle = document.getElementById('modalTitle');
|
||||
const modalMessage = document.getElementById('modalMessage');
|
||||
const modalIcon = document.getElementById('modalIcon');
|
||||
const modalConfirmBtn = document.getElementById('modalConfirmBtn2');
|
||||
const modalBtnGroup = document.getElementById('modalBtnGroup');
|
||||
const modalSingleBtnGroup = document.getElementById('modalSingleBtnGroup');
|
||||
|
||||
modalTitle.textContent = title;
|
||||
modalMessage.innerHTML = message;
|
||||
|
||||
if (type === 'success') {
|
||||
modalIcon.innerHTML = '<div class="w-12 h-12 mx-auto mb-4 rounded-full bg-green-100 flex items-center justify-center"><i class="fa fa-check text-xl text-green-600"></i></div>';
|
||||
} else if (type === 'error') {
|
||||
modalIcon.innerHTML = '<div class="w-12 h-12 mx-auto mb-4 rounded-full bg-red-100 flex items-center justify-center"><i class="fa fa-times text-xl text-red-600"></i></div>';
|
||||
} else if (type === 'warning') {
|
||||
modalIcon.innerHTML = '<div class="w-12 h-12 mx-auto mb-4 rounded-full bg-yellow-100 flex items-center justify-center"><i class="fa fa-exclamation text-xl text-yellow-600"></i></div>';
|
||||
} else {
|
||||
modalIcon.innerHTML = '<div class="w-12 h-12 mx-auto mb-4 rounded-full bg-blue-100 flex items-center justify-center"><i class="fa fa-info text-xl text-blue-600"></i></div>';
|
||||
}
|
||||
|
||||
modalBtnGroup.classList.add('hidden');
|
||||
modalSingleBtnGroup.classList.remove('hidden');
|
||||
modalConfirmBtn.className = type === 'error' ? 'px-6 py-2 bg-danger text-white rounded-lg hover:bg-danger/90 transition-colors' : 'px-6 py-2 bg-primary text-white rounded-lg hover:bg-primary/90 transition-colors';
|
||||
|
||||
modal.classList.remove('hidden');
|
||||
document.body.style.overflow = 'hidden';
|
||||
|
||||
modalConfirmBtn.onclick = () => {
|
||||
modal.classList.add('hidden');
|
||||
document.body.style.overflow = '';
|
||||
if (onConfirm) onConfirm();
|
||||
};
|
||||
}
|
||||
</script>
|
||||
|
||||
<!-- 自定义消息弹窗 -->
|
||||
<div id="customModal" class="hidden fixed inset-0 bg-black/50 z-50 flex items-center justify-center">
|
||||
<div class="bg-white rounded-xl shadow-xl max-w-md w-full mx-4 overflow-hidden">
|
||||
<div class="p-6 text-center">
|
||||
<div id="modalIcon"></div>
|
||||
<h3 id="modalTitle" class="text-lg 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">
|
||||
<button id="modalConfirmBtn" class="px-4 py-2 bg-primary text-white rounded-lg w-full hover:bg-primary/90 transition-colors">
|
||||
确定
|
||||
</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>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
||||
@@ -101,7 +101,7 @@
|
||||
</a>
|
||||
<a href="main.html?page=data-generate" 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>
|
||||
|
||||
<!-- 第三分区:系统设置 -->
|
||||
|
||||
@@ -87,7 +87,7 @@
|
||||
</a>
|
||||
<a href="main.html?page=data-generate" 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>
|
||||
|
||||
<!-- 第三分区:系统设置 -->
|
||||
|
||||
@@ -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>
|
||||
|
||||
@@ -86,7 +86,7 @@
|
||||
</a>
|
||||
<a href="main.html?page=data-generate" 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>
|
||||
|
||||
<!-- 第三分区:系统设置 -->
|
||||
|
||||
@@ -84,7 +84,7 @@
|
||||
</a>
|
||||
<a href="main.html?page=data-generate" 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>
|
||||
|
||||
<!-- 第三分区:系统设置 -->
|
||||
|
||||
Reference in New Issue
Block a user