443 lines
21 KiB
HTML
443 lines
21 KiB
HTML
<!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>
|