- 修复Redis认证 (配置密码) - 启动Python管理后台 (端口9531, 15个功能开关) - 统一版本号 0.2.7 - 更新docker-compose.yml (镜像版本/Redis URL/Admin服务)
197 lines
9.7 KiB
HTML
197 lines
9.7 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>功能开关 - CloudSearch</title>
|
|
<style>
|
|
:root {
|
|
--bg: #f5f7fa; --card-bg: #fff; --text: #303133; --muted: #909399;
|
|
--border: #e4e7ed; --primary: #409eff; --success: #67c23a; --danger: #f56c6c;
|
|
--warning: #e6a23c;
|
|
}
|
|
* { margin:0; padding:0; box-sizing:border-box; }
|
|
body { font-family: -apple-system, 'Helvetica Neue', sans-serif; background: var(--bg); color: var(--text); min-height: 100vh; }
|
|
.nav { background: var(--card-bg); border-bottom: 1px solid var(--border); padding: 0 24px; height: 56px; display: flex; align-items: center; justify-content: space-between; }
|
|
.nav h2 { font-size: 18px; font-weight: 600; display: flex; align-items: center; gap: 8px; }
|
|
.nav .badge { font-size: 11px; background: var(--primary); color: #fff; padding: 2px 8px; border-radius: 10px; }
|
|
.nav a { color: var(--primary); text-decoration: none; font-size: 13px; }
|
|
.container { max-width: 800px; margin: 0 auto; padding: 24px 16px; }
|
|
.group { margin-bottom: 24px; }
|
|
.group-title { font-size: 13px; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: 1px; padding: 8px 0; border-bottom: 1px solid var(--border); margin-bottom: 12px; }
|
|
.card { background: var(--card-bg); border: 1px solid var(--border); border-radius: 8px; padding: 16px 20px; margin-bottom: 8px; display: flex; align-items: center; justify-content: space-between; transition: box-shadow .15s; }
|
|
.card:hover { box-shadow: 0 2px 8px rgba(0,0,0,.06); }
|
|
.card-info h3 { font-size: 14px; font-weight: 500; }
|
|
.card-info .key { font-size: 11px; color: var(--muted); font-family: 'SF Mono', Monaco, monospace; margin-top: 2px; }
|
|
.toggle-wrap { display: flex; align-items: center; gap: 10px; flex-shrink: 0; }
|
|
.toggle { position: relative; width: 44px; height: 24px; border-radius: 24px; border: none; cursor: pointer; transition: background .2s; outline: none; }
|
|
.toggle:focus-visible { box-shadow: 0 0 0 2px rgba(64,158,255,.4); }
|
|
.toggle.off { background: #c0c4cc; }
|
|
.toggle.on { background: var(--success); }
|
|
.toggle::after { content: ''; position: absolute; top: 2px; left: 2px; width: 20px; height: 20px; border-radius: 50%; background: #fff; transition: transform .2s ease; box-shadow: 0 1px 2px rgba(0,0,0,.15); }
|
|
.toggle.on::after { transform: translateX(20px); }
|
|
.toggle:disabled { opacity: .4; cursor: not-allowed; }
|
|
.status { font-size: 12px; min-width: 36px; text-align: center; }
|
|
.status.on { color: var(--success); }
|
|
.status.off { color: var(--muted); }
|
|
.actions { display: flex; gap: 12px; justify-content: flex-end; margin-top: 24px; }
|
|
.btn { padding: 8px 20px; border: 1px solid var(--border); border-radius: 6px; background: var(--card-bg); color: var(--text); cursor: pointer; font-size: 13px; transition: .15s; }
|
|
.btn:hover { border-color: var(--primary); color: var(--primary); }
|
|
.btn.primary { background: var(--primary); border-color: var(--primary); color: #fff; }
|
|
.btn.primary:hover { opacity: .85; }
|
|
.toast { position: fixed; top: 20px; left: 50%; transform: translateX(-50%); background: var(--card-bg); border: 1px solid var(--border); border-radius: 8px; padding: 10px 24px; font-size: 14px; box-shadow: 0 4px 12px rgba(0,0,0,.1); z-index: 999; opacity: 0; transition: opacity .25s; }
|
|
.toast.show { opacity: 1; }
|
|
.toast.ok { border-color: var(--success); }
|
|
.toast.err { border-color: var(--danger); }
|
|
.loading-overlay { text-align: center; padding: 60px; color: var(--muted); font-size: 14px; }
|
|
</style>
|
|
</head>
|
|
<body>
|
|
<div class="nav">
|
|
<h2>🔧 功能开关 <span class="badge">v2.2</span></h2>
|
|
<a href="/admin">← 返回管理后台</a>
|
|
</div>
|
|
<div class="container" id="app">
|
|
<div class="loading-overlay">加载中…</div>
|
|
</div>
|
|
<div class="toast" id="toast"></div>
|
|
|
|
<script>
|
|
// ========== Feature Definitions ==========
|
|
const FEATURES = [
|
|
// 核心功能
|
|
{ key: 'feature_quark_pid', name: '夸克推广PID', group: '核心功能', default: true },
|
|
{ key: 'feature_seo', name: 'SEO / Sitemap', group: '核心功能', default: true },
|
|
{ key: 'feature_link_monitor', name: '失效链接监控', group: '核心功能', default: true },
|
|
// 增强功能
|
|
{ key: 'feature_tmdb', name: 'TMDB影视刮削', group: '增强功能', default: true },
|
|
{ key: 'feature_telegram_bot', name: 'Telegram Bot', group: '增强功能', default: false },
|
|
{ key: 'feature_subscription', name: '关键词订阅通知', group: '增强功能', default: false },
|
|
{ key: 'feature_alist', name: 'AList打通', group: '增强功能', default: false },
|
|
// 网盘转存
|
|
{ key: 'feature_transfer_quark', name: '夸克转存', group: '网盘转存', default: true },
|
|
{ key: 'feature_transfer_baidu', name: '百度转存', group: '网盘转存', default: false },
|
|
{ key: 'feature_transfer_aliyun', name: '阿里转存', group: '网盘转存', default: false },
|
|
{ key: 'feature_transfer_uc', name: 'UC转存', group: '网盘转存', default: false },
|
|
{ key: 'feature_transfer_xunlei', name: '迅雷转存', group: '网盘转存', default: false },
|
|
{ key: 'feature_transfer_115', name: '115转存', group: '网盘转存', default: false },
|
|
{ key: 'feature_transfer_123', name: '123转存', group: '网盘转存', default: false },
|
|
{ key: 'feature_transfer_cloud189',name: '天翼转存', group: '网盘转存', default: false },
|
|
];
|
|
|
|
// ========== API helpers ==========
|
|
const BASE = '';
|
|
function token() { return localStorage.getItem('admin_token') || ''; }
|
|
function headers() { const h = {'Content-Type':'application/json'}; const t=token(); if(t) h['Authorization']='Bearer '+t; return h; }
|
|
|
|
async function apiGet(url) {
|
|
const res = await fetch(BASE + url, { headers: headers() });
|
|
if (res.status === 401) { alert('登录已过期,请重新登录'); location.href = '/admin'; return null; }
|
|
if (!res.ok) throw new Error('HTTP ' + res.status);
|
|
return res.json();
|
|
}
|
|
async function apiPut(url, body) {
|
|
const res = await fetch(BASE + url, { method:'PUT', headers:headers(), body:JSON.stringify(body) });
|
|
if (res.status === 401) { alert('登录已过期,请重新登录'); location.href = '/admin'; return null; }
|
|
if (!res.ok) throw new Error('HTTP ' + res.status);
|
|
return res.json();
|
|
}
|
|
|
|
// ========== State ==========
|
|
let configs = {}; // key -> value from system_configs
|
|
|
|
// ========== Toast ==========
|
|
function toast(msg, type) {
|
|
const el = document.getElementById('toast');
|
|
el.textContent = msg; el.className = 'toast ' + (type||'ok') + ' show';
|
|
clearTimeout(el._t); el._t = setTimeout(() => el.classList.remove('show'), 2500);
|
|
}
|
|
|
|
// ========== Toggle ==========
|
|
async function toggleFeature(key, currentVal) {
|
|
const newVal = !currentVal;
|
|
// Optimistic UI update
|
|
configs[key] = String(newVal);
|
|
render();
|
|
|
|
try {
|
|
await apiPut('/api/admin/system-configs', {
|
|
entries: [{ key, value: newVal ? 'true' : 'false' }]
|
|
});
|
|
toast(newVal ? `✅ ${key.replace('feature_','')} 已开启` : `❌ ${key.replace('feature_','')} 已关闭`, 'ok');
|
|
} catch(e) {
|
|
// Revert
|
|
configs[key] = String(currentVal);
|
|
render();
|
|
toast('切换失败: ' + e.message, 'err');
|
|
}
|
|
}
|
|
|
|
async function toggleAll(groupKeys, enable) {
|
|
const entries = groupKeys.map(k => ({ key: k, value: enable ? 'true' : 'false' }));
|
|
for (const e of entries) configs[e.key] = e.value;
|
|
render();
|
|
try {
|
|
await apiPut('/api/admin/system-configs', { entries });
|
|
toast(`${enable ? '✅' : '❌'} 已${enable ? '开启' : '关闭'} ${entries.length} 个开关`, 'ok');
|
|
} catch(e) {
|
|
await load(); // revert
|
|
toast('批量操作失败: ' + e.message, 'err');
|
|
}
|
|
}
|
|
|
|
// ========== Load ==========
|
|
async function load() {
|
|
try {
|
|
const data = await apiGet('/api/admin/system-configs');
|
|
if (!data) return;
|
|
configs = {};
|
|
for (const row of data) { configs[row.key] = row.value; }
|
|
render();
|
|
} catch(e) {
|
|
document.getElementById('app').innerHTML =
|
|
'<div class="loading-overlay" style="color:var(--danger)">加载失败: ' + e.message + '</div>';
|
|
}
|
|
}
|
|
|
|
// ========== Render ==========
|
|
function render() {
|
|
const groups = {};
|
|
for (const f of FEATURES) {
|
|
(groups[f.group] || (groups[f.group] = [])).push(f);
|
|
}
|
|
|
|
let html = '';
|
|
for (const [group, items] of Object.entries(groups)) {
|
|
const keys = items.map(f => f.key);
|
|
const allOn = keys.every(k => configs[k] === 'true');
|
|
const allOff = keys.every(k => configs[k] !== 'true');
|
|
html += '<div class="group">';
|
|
html += '<div class="group-title" style="display:flex;justify-content:space-between;align-items:center">';
|
|
html += '<span>' + group + '</span>';
|
|
html += '<span style="font-weight:400;font-size:12px">';
|
|
html += '<a href="#" onclick="toggleAll(' + JSON.stringify(keys) + ',true);return false" style="margin-right:8px">全部开启</a>';
|
|
html += '<a href="#" onclick="toggleAll(' + JSON.stringify(keys) + ',false);return false">全部关闭</a>';
|
|
html += '</span></div>';
|
|
for (const f of items) {
|
|
const val = configs[f.key] === 'true';
|
|
html += '<div class="card">';
|
|
html += '<div class="card-info"><h3>' + f.name + '</h3><div class="key">' + f.key + '</div></div>';
|
|
html += '<div class="toggle-wrap">';
|
|
html += '<span class="status ' + (val ? 'on' : 'off') + '">' + (val ? '开' : '关') + '</span>';
|
|
html += '<button class="toggle ' + (val ? 'on' : 'off') + '" onclick="toggleFeature(\'' + f.key + '\',' + val + ')" title="点击切换"></button>';
|
|
html += '</div></div>';
|
|
}
|
|
html += '</div>';
|
|
}
|
|
|
|
html += '<div class="actions"><button class="btn" onclick="load()">🔄 刷新状态</button></div>';
|
|
document.getElementById('app').innerHTML = html;
|
|
}
|
|
|
|
// ========== Init ==========
|
|
load();
|
|
</script>
|
|
</body>
|
|
</html>
|