mirror of
https://gitee.com/xiarenalofs/squad-rain-ops-mini.git
synced 2026-08-05 21:15:52 +08:00
536 lines
17 KiB
HTML
536 lines
17 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>服务器配置文件管理 - RainOps Mini</title>
|
|
<link rel="stylesheet" href="/lib/css/bootstrap.min.css">
|
|
<link rel="stylesheet" href="/lib/css/font-awesome.min.css">
|
|
<style>
|
|
:root {
|
|
--primary-color: #0056b3;
|
|
--bg-color: #f0f2f5;
|
|
--card-bg: #ffffff;
|
|
--text-color: #2c3e50;
|
|
--border-color: #d1d5db;
|
|
--secondary-color: #6c757d;
|
|
}
|
|
|
|
body {
|
|
font-family: 'Segoe UI', system-ui, sans-serif;
|
|
background-color: var(--bg-color);
|
|
color: var(--text-color);
|
|
margin: 0;
|
|
padding: 0;
|
|
height: 100vh;
|
|
display: flex;
|
|
flex-direction: column;
|
|
}
|
|
|
|
.navbar {
|
|
background-color: var(--card-bg);
|
|
padding: 0 20px;
|
|
height: 50px;
|
|
display: flex;
|
|
align-items: center;
|
|
justify-content: space-between;
|
|
box-shadow: 0 2px 4px rgba(0, 0, 0, 0.05);
|
|
z-index: 100;
|
|
}
|
|
|
|
.navbar-brand {
|
|
font-weight: 600;
|
|
font-size: 1.1rem;
|
|
color: var(--primary-color);
|
|
text-decoration: none;
|
|
display: flex;
|
|
align-items: center;
|
|
gap: 10px;
|
|
}
|
|
|
|
.navbar-links a {
|
|
color: #666;
|
|
text-decoration: none;
|
|
font-size: 0.9rem;
|
|
cursor: pointer;
|
|
}
|
|
|
|
.navbar-links a:hover {
|
|
color: var(--primary-color);
|
|
}
|
|
|
|
.main-container {
|
|
flex: 1;
|
|
display: flex;
|
|
overflow: hidden;
|
|
padding: 20px;
|
|
gap: 20px;
|
|
}
|
|
|
|
.file-list-panel {
|
|
width: 300px;
|
|
background: var(--card-bg);
|
|
border-radius: 4px;
|
|
box-shadow: 0 2px 8px rgba(0, 0, 0, 0.05);
|
|
display: flex;
|
|
flex-direction: column;
|
|
overflow: hidden;
|
|
}
|
|
|
|
.panel-header {
|
|
padding: 15px;
|
|
border-bottom: 1px solid var(--border-color);
|
|
font-weight: 600;
|
|
background: #f8f9fa;
|
|
}
|
|
|
|
.file-list {
|
|
flex: 1;
|
|
overflow-y: auto;
|
|
padding: 10px 0;
|
|
}
|
|
|
|
.file-item {
|
|
padding: 10px 20px;
|
|
cursor: pointer;
|
|
display: flex;
|
|
align-items: center;
|
|
gap: 8px;
|
|
transition: background 0.2s;
|
|
font-size: 0.9rem;
|
|
}
|
|
|
|
.file-item:hover {
|
|
background-color: #f0f0f0;
|
|
}
|
|
|
|
.file-item.active {
|
|
background-color: #e6f2fa;
|
|
color: var(--primary-color);
|
|
border-left: 3px solid var(--primary-color);
|
|
}
|
|
|
|
.editor-panel {
|
|
flex: 1;
|
|
background: var(--card-bg);
|
|
border-radius: 4px;
|
|
box-shadow: 0 2px 8px rgba(0, 0, 0, 0.05);
|
|
display: flex;
|
|
flex-direction: column;
|
|
overflow: hidden;
|
|
}
|
|
|
|
.editor-toolbar {
|
|
padding: 10px 20px;
|
|
border-bottom: 1px solid var(--border-color);
|
|
display: flex;
|
|
justify-content: space-between;
|
|
align-items: center;
|
|
background: #f8f9fa;
|
|
}
|
|
|
|
.current-file-name {
|
|
font-weight: 600;
|
|
color: var(--text-color);
|
|
}
|
|
|
|
.editor-content {
|
|
flex: 1;
|
|
padding: 0;
|
|
position: relative;
|
|
}
|
|
|
|
#file-editor {
|
|
width: 100%;
|
|
height: 100%;
|
|
border: none;
|
|
resize: none;
|
|
padding: 15px;
|
|
font-family: 'Consolas', 'Monaco', monospace;
|
|
font-size: 14px;
|
|
line-height: 1.5;
|
|
background: #fafafa;
|
|
color: #333;
|
|
box-sizing: border-box;
|
|
outline: none;
|
|
}
|
|
|
|
.btn {
|
|
padding: 6px 16px;
|
|
border-radius: 4px;
|
|
border: none;
|
|
cursor: pointer;
|
|
font-size: 0.9rem;
|
|
transition: opacity 0.2s;
|
|
}
|
|
|
|
.btn-primary {
|
|
background-color: var(--primary-color);
|
|
color: white;
|
|
}
|
|
|
|
.btn-primary:hover {
|
|
opacity: 0.9;
|
|
}
|
|
|
|
.btn-secondary {
|
|
background-color: #e1dfdd;
|
|
color: #333;
|
|
margin-right: 10px;
|
|
}
|
|
|
|
.status-message {
|
|
margin-right: 15px;
|
|
font-size: 0.85rem;
|
|
color: #666;
|
|
}
|
|
|
|
.empty-state {
|
|
display: flex;
|
|
flex-direction: column;
|
|
align-items: center;
|
|
justify-content: center;
|
|
height: 100%;
|
|
color: #999;
|
|
}
|
|
|
|
.empty-icon {
|
|
font-size: 48px;
|
|
margin-bottom: 10px;
|
|
}
|
|
|
|
/* 简单的加载动画 */
|
|
.spinner {
|
|
display: inline-block;
|
|
width: 16px;
|
|
height: 16px;
|
|
border: 2px solid rgba(0, 0, 0, 0.1);
|
|
border-radius: 50%;
|
|
border-top-color: var(--primary-color);
|
|
animation: spin 1s ease-in-out infinite;
|
|
margin-right: 8px;
|
|
vertical-align: middle;
|
|
}
|
|
|
|
@keyframes spin {
|
|
to {
|
|
transform: rotate(360deg);
|
|
}
|
|
}
|
|
|
|
/* 悬浮助手样式 */
|
|
.help-fab-container {
|
|
position: fixed;
|
|
bottom: 30px;
|
|
right: 30px;
|
|
z-index: 1000;
|
|
display: flex;
|
|
flex-direction: column;
|
|
align-items: flex-end;
|
|
}
|
|
|
|
.help-fab {
|
|
width: 50px;
|
|
height: 50px;
|
|
border-radius: 50%;
|
|
background-color: var(--primary-color);
|
|
color: white;
|
|
border: none;
|
|
box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
|
|
font-size: 24px;
|
|
font-weight: bold;
|
|
cursor: pointer;
|
|
display: flex;
|
|
align-items: center;
|
|
justify-content: center;
|
|
transition: transform 0.2s, background-color 0.2s;
|
|
}
|
|
|
|
.help-fab:hover {
|
|
transform: scale(1.1);
|
|
background-color: #005a9e;
|
|
}
|
|
|
|
.help-menu {
|
|
background: white;
|
|
border-radius: 8px;
|
|
box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
|
|
margin-bottom: 15px;
|
|
overflow: hidden;
|
|
opacity: 0;
|
|
transform: translateY(20px) scale(0.9);
|
|
transform-origin: bottom right;
|
|
transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
|
|
pointer-events: none;
|
|
display: flex;
|
|
flex-direction: column;
|
|
min-width: 220px;
|
|
}
|
|
|
|
.help-menu.active {
|
|
opacity: 1;
|
|
transform: translateY(0) scale(1);
|
|
pointer-events: all;
|
|
}
|
|
|
|
.help-item {
|
|
padding: 12px 16px;
|
|
text-decoration: none;
|
|
color: var(--text-color);
|
|
display: flex;
|
|
align-items: center;
|
|
gap: 10px;
|
|
transition: background-color 0.1s;
|
|
font-size: 14px;
|
|
border-bottom: 1px solid #f3f2f1;
|
|
}
|
|
|
|
.help-item:last-child {
|
|
border-bottom: none;
|
|
}
|
|
|
|
.help-item:hover {
|
|
background-color: #f3f2f1;
|
|
color: var(--primary-color);
|
|
}
|
|
</style>
|
|
</head>
|
|
|
|
<body>
|
|
<div style="padding: 10px 20px; background: var(--bg-color); display: flex; align-items: center; gap: 10px;">
|
|
<a href="/" class="btn btn-secondary" style="text-decoration: none; display: inline-flex; align-items: center; gap: 5px; height: 32px; box-sizing: border-box;"><i class="fas fa-arrow-left"></i> 返回</a>
|
|
<h2 style="margin: 0; font-size: 1.2rem; display: flex; align-items: center; gap: 10px;"><i class="fas fa-cogs"></i> 配置文件管理</h2>
|
|
</div>
|
|
|
|
<div class="main-container">
|
|
<div class="file-list-panel">
|
|
<div class="panel-header">
|
|
<i class="fas fa-list"></i> 文件列表
|
|
</div>
|
|
<div id="file-list" class="file-list">
|
|
<div style="padding: 20px; text-align: center; color: #999;">正在加载...</div>
|
|
</div>
|
|
</div>
|
|
|
|
<div class="editor-panel">
|
|
<div class="editor-toolbar">
|
|
<div class="current-file-name" id="current-filename">未选择文件</div>
|
|
<div style="display: flex; align-items: center;">
|
|
<span id="status-msg" class="status-message"></span>
|
|
<button id="save-btn" class="btn btn-primary" onclick="saveCurrentFile()" disabled><i class="fas fa-save"></i> 保存修改</button>
|
|
</div>
|
|
</div>
|
|
<div class="editor-content">
|
|
<textarea id="file-editor" spellcheck="false" disabled></textarea>
|
|
<div id="empty-state" class="empty-state">
|
|
<div class="empty-icon"><i class="fas fa-file-code"></i></div>
|
|
<div>请从左侧选择一个文件进行编辑</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<!-- 悬浮助手 -->
|
|
<div class="help-fab-container">
|
|
<div class="help-menu" id="help-menu">
|
|
<a href="https://docs.qq.com/doc/DZkdDU0pETlNSRU5t" target="_blank" class="help-item">
|
|
<i class="fas fa-book"></i> Squad Config 学习手册
|
|
</a>
|
|
<a href="https://www.deepseek.com/" target="_blank" class="help-item">
|
|
<i class="fas fa-fish"></i> DeepSeek 官网
|
|
</a>
|
|
</div>
|
|
<button class="help-fab" onclick="toggleHelpMenu()" title="获取帮助">
|
|
<i class="fas fa-question"></i>
|
|
</button>
|
|
</div>
|
|
|
|
<script>
|
|
// Permission Check
|
|
(function() {
|
|
const required = 'configs';
|
|
const permsStr = localStorage.getItem('permissions');
|
|
const isSuper = localStorage.getItem('isSuperAdmin') === 'true';
|
|
|
|
if (isSuper) return;
|
|
|
|
if (!permsStr) {
|
|
document.body.innerHTML = '<div style="display:flex;justify-content:center;align-items:center;height:100vh;color:red;font-size:1.5rem;">Access Denied: Not logged in.</div>';
|
|
throw new Error("Access Denied");
|
|
}
|
|
|
|
try {
|
|
const perms = JSON.parse(permsStr);
|
|
if (!perms.includes('all') && !perms.includes(required)) {
|
|
document.body.innerHTML = '<div style="display:flex;justify-content:center;align-items:center;height:100vh;color:red;font-size:1.5rem;">Access Denied: Permission "config" required.</div>';
|
|
throw new Error("Access Denied");
|
|
}
|
|
} catch(e) {
|
|
if(e.message === "Access Denied") throw e;
|
|
console.error(e);
|
|
}
|
|
})();
|
|
|
|
let currentFile = null;
|
|
let originalContent = '';
|
|
|
|
// 页面加载完成后获取文件列表
|
|
document.addEventListener('DOMContentLoaded', loadFileList);
|
|
|
|
// 监听 Ctrl+S 保存
|
|
document.addEventListener('keydown', function (e) {
|
|
if ((e.ctrlKey || e.metaKey) && e.key === 's') {
|
|
e.preventDefault();
|
|
if (currentFile && !document.getElementById('save-btn').disabled) {
|
|
saveCurrentFile();
|
|
}
|
|
}
|
|
});
|
|
|
|
// 切换帮助菜单
|
|
function toggleHelpMenu() {
|
|
const menu = document.getElementById('help-menu');
|
|
menu.classList.toggle('active');
|
|
}
|
|
|
|
// 点击外部关闭帮助菜单
|
|
document.addEventListener('click', function (e) {
|
|
const container = document.querySelector('.help-fab-container');
|
|
const menu = document.getElementById('help-menu');
|
|
if (!container.contains(e.target) && menu.classList.contains('active')) {
|
|
menu.classList.remove('active');
|
|
}
|
|
});
|
|
|
|
async function loadFileList() {
|
|
const listContainer = document.getElementById('file-list');
|
|
|
|
try {
|
|
const response = await fetch('/api/config/files');
|
|
|
|
if (response.status === 404) {
|
|
listContainer.innerHTML = '<div style="padding: 20px; text-align: center; color: #d13438;">找不到 SquadGame/ServerConfig 目录</div>';
|
|
return;
|
|
}
|
|
|
|
if (!response.ok) throw new Error('加载失败');
|
|
|
|
const files = await response.json();
|
|
|
|
if (files.length === 0) {
|
|
listContainer.innerHTML = '<div style="padding: 20px; text-align: center; color: #999;">该目录下没有文件</div>';
|
|
return;
|
|
}
|
|
|
|
listContainer.innerHTML = '';
|
|
files.forEach(file => {
|
|
const item = document.createElement('div');
|
|
item.className = 'file-item';
|
|
item.innerHTML = `<i class="fas fa-file-alt"></i> ${file}`;
|
|
item.onclick = () => loadFileContent(file, item);
|
|
listContainer.appendChild(item);
|
|
});
|
|
|
|
} catch (error) {
|
|
console.error('Error:', error);
|
|
listContainer.innerHTML = '<div style="padding: 20px; text-align: center; color: #d13438;">加载文件列表失败</div>';
|
|
}
|
|
}
|
|
|
|
async function loadFileContent(filename, element) {
|
|
// 更新选中状态
|
|
document.querySelectorAll('.file-item').forEach(el => el.classList.remove('active'));
|
|
if (element) element.classList.add('active');
|
|
|
|
const editor = document.getElementById('file-editor');
|
|
const emptyState = document.getElementById('empty-state');
|
|
const saveBtn = document.getElementById('save-btn');
|
|
const filenameDisplay = document.getElementById('current-filename');
|
|
const statusMsg = document.getElementById('status-msg');
|
|
|
|
// 显示加载状态
|
|
statusMsg.textContent = '正在读取...';
|
|
editor.disabled = true;
|
|
|
|
try {
|
|
const response = await fetch(`/api/config/read?filename=${encodeURIComponent(filename)}`);
|
|
if (!response.ok) throw new Error('读取失败');
|
|
|
|
const content = await response.text();
|
|
|
|
// 更新编辑器
|
|
currentFile = filename;
|
|
originalContent = content;
|
|
editor.value = content;
|
|
|
|
// 切换显示
|
|
emptyState.style.display = 'none';
|
|
editor.style.display = 'block';
|
|
editor.disabled = false;
|
|
saveBtn.disabled = false;
|
|
filenameDisplay.textContent = filename;
|
|
statusMsg.textContent = '';
|
|
|
|
} catch (error) {
|
|
console.error('Error:', error);
|
|
statusMsg.textContent = '读取文件失败';
|
|
statusMsg.style.color = '#d13438';
|
|
}
|
|
}
|
|
|
|
async function saveCurrentFile() {
|
|
if (!currentFile) return;
|
|
|
|
const editor = document.getElementById('file-editor');
|
|
const saveBtn = document.getElementById('save-btn');
|
|
const statusMsg = document.getElementById('status-msg');
|
|
|
|
const content = editor.value;
|
|
|
|
statusMsg.textContent = '正在保存...';
|
|
statusMsg.style.color = '#666';
|
|
saveBtn.disabled = true;
|
|
editor.disabled = true;
|
|
|
|
try {
|
|
const response = await fetch('/api/config/save', {
|
|
method: 'POST',
|
|
headers: {
|
|
'Content-Type': 'application/json'
|
|
},
|
|
body: JSON.stringify({
|
|
filename: currentFile,
|
|
content: content
|
|
})
|
|
});
|
|
|
|
if (!response.ok) {
|
|
const err = await response.json();
|
|
throw new Error(err.error || '保存失败');
|
|
}
|
|
|
|
statusMsg.textContent = '保存成功!';
|
|
statusMsg.style.color = '#107c10';
|
|
originalContent = content;
|
|
|
|
setTimeout(() => {
|
|
if (statusMsg.textContent === '保存成功!') {
|
|
statusMsg.textContent = '';
|
|
}
|
|
}, 3000);
|
|
|
|
} catch (error) {
|
|
console.error('Error:', error);
|
|
statusMsg.textContent = '保存失败: ' + error.message;
|
|
statusMsg.style.color = '#d13438';
|
|
} finally {
|
|
saveBtn.disabled = false;
|
|
editor.disabled = false;
|
|
editor.focus();
|
|
}
|
|
}
|
|
</script>
|
|
</body>
|
|
|
|
</html> |