feat: 初始版本,支持 HTTP 代理和 SOCKS5 代理
This commit is contained in:
+596
@@ -0,0 +1,596 @@
|
||||
/**
|
||||
* 配置页面脚本:拉取状态 / 读写配置 / 展示日志。
|
||||
* 无框架依赖,直接使用原生 DOM 与 fetch。
|
||||
*/
|
||||
|
||||
(function () {
|
||||
'use strict';
|
||||
|
||||
/** 页面状态 */
|
||||
const state = {
|
||||
/** @type {object|null} 当前服务端配置 */
|
||||
config: null,
|
||||
/** @type {object|null} 最近一次状态快照 */
|
||||
status: null,
|
||||
/** 表单是否被用户改过(改过就不自动覆盖输入值) */
|
||||
dirty: false,
|
||||
};
|
||||
|
||||
/**
|
||||
* 简写选择器。
|
||||
* @param {string} selector CSS 选择器
|
||||
* @returns {HTMLElement}
|
||||
*/
|
||||
function $(selector) {
|
||||
const element = document.querySelector(selector);
|
||||
if (!element) throw new Error(`缺少元素:${selector}`);
|
||||
return /** @type {HTMLElement} */ (element);
|
||||
}
|
||||
|
||||
/**
|
||||
* 请求管理接口。
|
||||
* @param {string} path 接口路径
|
||||
* @param {RequestInit} [options] fetch 配置
|
||||
* @returns {Promise<any>} 解析后的 JSON
|
||||
*/
|
||||
async function api(path, options = {}) {
|
||||
const response = await fetch(path, {
|
||||
cache: 'no-store',
|
||||
...options,
|
||||
headers: { 'content-type': 'application/json', ...(options.headers || {}) },
|
||||
});
|
||||
const data = await response.json().catch(() => ({}));
|
||||
if (!response.ok) throw new Error(data.error || `请求失败(HTTP ${response.status})`);
|
||||
return data;
|
||||
}
|
||||
|
||||
/**
|
||||
* 速率格式化(字节/秒)。
|
||||
* @param {number} bytesPerSecond 每秒字节数
|
||||
* @returns {string} 例如 "1.24 MB/s"
|
||||
*/
|
||||
function formatRate(bytesPerSecond) {
|
||||
const value = Math.max(0, Number(bytesPerSecond) || 0);
|
||||
if (value < 1024) return `${Math.round(value)} B/s`;
|
||||
const units = ['KB/s', 'MB/s', 'GB/s'];
|
||||
let size = value / 1024;
|
||||
let index = 0;
|
||||
while (size >= 1024 && index < units.length - 1) {
|
||||
size /= 1024;
|
||||
index += 1;
|
||||
}
|
||||
return `${size.toFixed(size >= 100 ? 0 : size >= 10 ? 1 : 2)} ${units[index]}`;
|
||||
}
|
||||
|
||||
/**
|
||||
* 把最大值向上取整到 1/2/5×10^n,作为坐标轴上限。
|
||||
* @param {number} value 原始最大值
|
||||
* @returns {number} 规整后的上限
|
||||
*/
|
||||
function niceCeil(value) {
|
||||
if (!Number.isFinite(value) || value <= 0) return 1;
|
||||
const exponent = Math.floor(Math.log10(value));
|
||||
const base = Math.pow(10, exponent);
|
||||
const normalized = value / base;
|
||||
const step = normalized <= 1 ? 1 : normalized <= 2 ? 2 : normalized <= 5 ? 5 : 10;
|
||||
return step * base;
|
||||
}
|
||||
|
||||
/**
|
||||
* 绘制带宽趋势折线图(下载 / 上传双线)。
|
||||
* @param {{at: number, up: number, down: number}[]} history 采样历史
|
||||
*/
|
||||
function drawChart(history) {
|
||||
const canvas = /** @type {HTMLCanvasElement|null} */ (document.getElementById('bandwidth-chart'));
|
||||
if (!canvas) return;
|
||||
const context = canvas.getContext('2d');
|
||||
if (!context) return;
|
||||
|
||||
const dpr = window.devicePixelRatio || 1;
|
||||
const width = canvas.clientWidth || 640;
|
||||
const height = canvas.clientHeight || 170;
|
||||
const pixelWidth = Math.round(width * dpr);
|
||||
const pixelHeight = Math.round(height * dpr);
|
||||
if (canvas.width !== pixelWidth || canvas.height !== pixelHeight) {
|
||||
canvas.width = pixelWidth;
|
||||
canvas.height = pixelHeight;
|
||||
}
|
||||
context.setTransform(dpr, 0, 0, dpr, 0, 0);
|
||||
context.clearRect(0, 0, width, height);
|
||||
|
||||
const padding = { top: 14, right: 14, bottom: 20, left: 58 };
|
||||
const chartWidth = Math.max(1, width - padding.left - padding.right);
|
||||
const chartHeight = Math.max(1, height - padding.top - padding.bottom);
|
||||
const points = Array.isArray(history) ? history : [];
|
||||
|
||||
const maxValue = points.reduce((max, point) => Math.max(max, point.up || 0, point.down || 0), 0);
|
||||
const scaleMax = niceCeil(Math.max(maxValue, 1024));
|
||||
|
||||
// 横向网格与纵轴刻度
|
||||
context.font = '11px "Segoe UI", "PingFang SC", sans-serif';
|
||||
context.strokeStyle = '#eef2f8';
|
||||
context.fillStyle = '#98a2b3';
|
||||
context.lineWidth = 1;
|
||||
context.textAlign = 'right';
|
||||
context.textBaseline = 'middle';
|
||||
|
||||
for (let i = 0; i <= 4; i += 1) {
|
||||
const y = padding.top + (chartHeight / 4) * i;
|
||||
context.beginPath();
|
||||
context.moveTo(padding.left, y);
|
||||
context.lineTo(padding.left + chartWidth, y);
|
||||
context.stroke();
|
||||
const label = formatRate((scaleMax * (4 - i)) / 4).replace('/s', '');
|
||||
context.fillText(label, padding.left - 8, y);
|
||||
}
|
||||
|
||||
if (points.length < 2) {
|
||||
context.fillStyle = '#98a2b3';
|
||||
context.textAlign = 'center';
|
||||
context.textBaseline = 'middle';
|
||||
context.fillText('正在采集数据…', width / 2, height / 2);
|
||||
return;
|
||||
}
|
||||
|
||||
// 横轴时间说明
|
||||
const startSeconds = Math.round((points[points.length - 1].at - points[0].at) / 1000);
|
||||
context.fillStyle = '#98a2b3';
|
||||
context.textBaseline = 'top';
|
||||
context.textAlign = 'left';
|
||||
context.fillText(`${startSeconds} 秒前`, padding.left, padding.top + chartHeight + 5);
|
||||
context.textAlign = 'right';
|
||||
context.fillText('现在', padding.left + chartWidth, padding.top + chartHeight + 5);
|
||||
|
||||
/**
|
||||
* 把采样点映射到画布坐标。
|
||||
* @param {number} index 序号
|
||||
* @param {number} value 速率
|
||||
* @returns {{x: number, y: number}}
|
||||
*/
|
||||
const toPoint = (index, value) => ({
|
||||
x: padding.left + (chartWidth * index) / (points.length - 1),
|
||||
y: padding.top + chartHeight - (chartHeight * Math.min(value, scaleMax)) / scaleMax,
|
||||
});
|
||||
|
||||
/**
|
||||
* 绘制一条速率曲线(可带渐变填充)。
|
||||
* @param {'up'|'down'} key 数据键
|
||||
* @param {string} stroke 线条颜色
|
||||
* @param {string} fill 填充颜色
|
||||
*/
|
||||
const drawSeries = (key, stroke, fill) => {
|
||||
context.beginPath();
|
||||
points.forEach((point, index) => {
|
||||
const position = toPoint(index, point[key] || 0);
|
||||
if (index === 0) context.moveTo(position.x, position.y);
|
||||
else context.lineTo(position.x, position.y);
|
||||
});
|
||||
context.strokeStyle = stroke;
|
||||
context.lineWidth = 1.6;
|
||||
context.lineJoin = 'round';
|
||||
context.lineCap = 'round';
|
||||
context.stroke();
|
||||
|
||||
// 填充到基线的浅色区域,便于区分上下行
|
||||
context.lineTo(padding.left + chartWidth, padding.top + chartHeight);
|
||||
context.lineTo(padding.left, padding.top + chartHeight);
|
||||
context.closePath();
|
||||
context.fillStyle = fill;
|
||||
context.fill();
|
||||
};
|
||||
|
||||
drawSeries('down', '#2563eb', 'rgba(37, 99, 235, 0.10)');
|
||||
drawSeries('up', '#0f9d63', 'rgba(15, 157, 99, 0.10)');
|
||||
}
|
||||
|
||||
function formatBytes(bytes) {
|
||||
const value = Number(bytes) || 0;
|
||||
if (value < 1024) return `${value} B`;
|
||||
const units = ['KB', 'MB', 'GB', 'TB'];
|
||||
let size = value / 1024;
|
||||
let index = 0;
|
||||
while (size >= 1024 && index < units.length - 1) {
|
||||
size /= 1024;
|
||||
index += 1;
|
||||
}
|
||||
return `${size.toFixed(size >= 100 ? 0 : size >= 10 ? 1 : 2)} ${units[index]}`;
|
||||
}
|
||||
|
||||
/**
|
||||
* 运行时长格式化。
|
||||
* @param {number} seconds 秒
|
||||
* @returns {string}
|
||||
*/
|
||||
function formatUptime(seconds) {
|
||||
const total = Math.max(0, Math.floor(Number(seconds) || 0));
|
||||
const day = Math.floor(total / 86400);
|
||||
const hour = Math.floor((total % 86400) / 3600);
|
||||
const minute = Math.floor((total % 3600) / 60);
|
||||
const second = total % 60;
|
||||
if (day > 0) return `${day} 天 ${hour} 小时 ${minute} 分`;
|
||||
if (hour > 0) return `${hour} 小时 ${minute} 分 ${second} 秒`;
|
||||
if (minute > 0) return `${minute} 分 ${second} 秒`;
|
||||
return `${second} 秒`;
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置状态标签的文字与样式。
|
||||
* @param {HTMLElement} element 标签元素
|
||||
* @param {string} text 文案
|
||||
* @param {'ok'|'off'|'bad'|'neutral'} [variant] 样式
|
||||
*/
|
||||
function setState(element, text, variant = 'ok') {
|
||||
element.textContent = text;
|
||||
element.className = `state ${variant === 'ok' ? '' : variant}`.trim();
|
||||
}
|
||||
|
||||
/**
|
||||
* 渲染实时状态。
|
||||
* @param {object} status 状态快照
|
||||
*/
|
||||
function renderStatus(status) {
|
||||
state.status = status;
|
||||
$('#uptime-pill').textContent = `运行时长 ${formatUptime(status.uptime)}`;
|
||||
|
||||
/**
|
||||
* 渲染单个代理卡片。
|
||||
* @param {'http'|'socks5'} key 协议
|
||||
*/
|
||||
const renderProxy = (key) => {
|
||||
const item = status[key];
|
||||
const prefix = key === 'http' ? 'http' : 'socks';
|
||||
const scheme = key === 'http' ? 'http' : 'socks5';
|
||||
|
||||
// 状态标签
|
||||
const stateEl = $(`#${prefix}-state`);
|
||||
if (item.error) setState(stateEl, '异常', 'bad');
|
||||
else if (item.listening) setState(stateEl, item.authEnabled ? '运行中 · 需认证' : '运行中', 'ok');
|
||||
else setState(stateEl, item.enabled ? '未监听' : '已停用', 'off');
|
||||
|
||||
// 地址
|
||||
const addrEl = $(`#${prefix}-addr`);
|
||||
if (item.listening) {
|
||||
addrEl.textContent = `${scheme}://${item.host}:${item.actualPort}`;
|
||||
addrEl.classList.remove('dim');
|
||||
} else {
|
||||
addrEl.textContent = item.enabled ? '等待监听…' : '未启用';
|
||||
addrEl.classList.add('dim');
|
||||
}
|
||||
|
||||
// 指标
|
||||
const bucket = status.stats[key] || {};
|
||||
const rate = (status.stats.rates && status.stats.rates[key]) || { up: 0, down: 0 };
|
||||
$(`#${prefix}-active`).textContent = String(bucket.active || 0);
|
||||
$(`#${prefix}-total`).textContent = String(bucket.total || 0);
|
||||
$(`#${prefix}-rate-down`).textContent = formatRate(rate.down);
|
||||
$(`#${prefix}-rate-up`).textContent = formatRate(rate.up);
|
||||
$(`#${prefix}-up`).textContent = formatBytes(bucket.bytesUp);
|
||||
$(`#${prefix}-down`).textContent = formatBytes(bucket.bytesDown);
|
||||
|
||||
// 错误信息
|
||||
const errorEl = $(`#${prefix}-error`);
|
||||
if (item.error) {
|
||||
errorEl.hidden = false;
|
||||
errorEl.textContent = item.error;
|
||||
} else {
|
||||
errorEl.hidden = true;
|
||||
errorEl.textContent = '';
|
||||
}
|
||||
};
|
||||
|
||||
renderProxy('http');
|
||||
renderProxy('socks5');
|
||||
|
||||
// 总览
|
||||
const total = status.stats.total || {};
|
||||
const totalRate = (status.stats.rates && status.stats.rates.total) || { up: 0, down: 0 };
|
||||
$('#total-active').textContent = String(total.active || 0);
|
||||
$('#total-total').textContent = String(total.total || 0);
|
||||
$('#total-rate-down').textContent = formatRate(totalRate.down);
|
||||
$('#total-rate-up').textContent = formatRate(totalRate.up);
|
||||
$('#total-up').textContent = formatBytes(total.bytesUp);
|
||||
$('#total-down').textContent = formatBytes(total.bytesDown);
|
||||
|
||||
// 实时网络状态面板
|
||||
const peak = status.stats.peak || { up: 0, down: 0 };
|
||||
$('#chart-down').textContent = formatRate(totalRate.down);
|
||||
$('#chart-up').textContent = formatRate(totalRate.up);
|
||||
$('#peak-down').textContent = formatRate(peak.down);
|
||||
$('#peak-up').textContent = formatRate(peak.up);
|
||||
$('#chart-active').textContent = String(total.active || 0);
|
||||
drawChart(status.stats.history || []);
|
||||
|
||||
const filter = status.targetFilter || {};
|
||||
const filterState = $('#filter-state');
|
||||
if (filter.mode === 'allowAll') {
|
||||
setState(filterState, '允许全部', 'neutral');
|
||||
$('#filter-desc').textContent = '未限制目标 IP,任何地址都可以通过代理访问';
|
||||
} else {
|
||||
setState(filterState, `白名单 ${filter.ruleCount || 0} 条`, 'neutral');
|
||||
$('#filter-desc').textContent = filter.ruleCount
|
||||
? `仅允许:${(filter.allowList || []).slice(0, 4).join('、')}${filter.ruleCount > 4 ? ' …' : ''}`
|
||||
: '白名单为空,所有请求都会被拒绝';
|
||||
}
|
||||
$('#filter-desc').classList.add('dim');
|
||||
}
|
||||
|
||||
/**
|
||||
* 把配置填充到表单。
|
||||
* @param {object} config 配置
|
||||
*/
|
||||
function fillForm(config) {
|
||||
state.config = config;
|
||||
|
||||
$('#http-enabled').checked = Boolean(config.http.enabled);
|
||||
$('#http-host').value = config.http.host || '';
|
||||
$('#http-port').value = String(config.http.port ?? '');
|
||||
$('#http-user').value = config.http.username || '';
|
||||
$('#http-pass').value = config.http.password || '';
|
||||
|
||||
$('#socks-enabled').checked = Boolean(config.socks5.enabled);
|
||||
$('#socks-host').value = config.socks5.host || '';
|
||||
$('#socks-port').value = String(config.socks5.port ?? '');
|
||||
$('#socks-user').value = config.socks5.username || '';
|
||||
$('#socks-pass').value = config.socks5.password || '';
|
||||
|
||||
$('#admin-host').value = config.admin.host || '';
|
||||
$('#admin-port').value = String(config.admin.port ?? '');
|
||||
$('#admin-user').value = config.admin.username || '';
|
||||
$('#admin-pass').value = config.admin.password || '';
|
||||
|
||||
const mode = config.targetFilter?.mode === 'allowList' ? 'allowList' : 'allowAll';
|
||||
document.querySelectorAll('input[name="filter-mode"]').forEach((input) => {
|
||||
input.checked = input.value === mode;
|
||||
});
|
||||
$('#filter-list').value = (config.targetFilter?.allowList || []).join('\n');
|
||||
|
||||
updateExamples(config);
|
||||
}
|
||||
|
||||
/**
|
||||
* 从表单收集配置对象。
|
||||
* @returns {object} 配置
|
||||
*/
|
||||
function collectForm() {
|
||||
const modeInput = document.querySelector('input[name="filter-mode"]:checked');
|
||||
const allowList = $('#filter-list')
|
||||
.value.split('\n')
|
||||
.map((line) => line.trim())
|
||||
.filter((line) => line.length > 0);
|
||||
|
||||
return {
|
||||
admin: {
|
||||
host: $('#admin-host').value.trim() || '127.0.0.1',
|
||||
port: Number($('#admin-port').value),
|
||||
username: $('#admin-user').value.trim(),
|
||||
password: $('#admin-pass').value,
|
||||
},
|
||||
http: {
|
||||
enabled: $('#http-enabled').checked,
|
||||
host: $('#http-host').value.trim() || '0.0.0.0',
|
||||
port: Number($('#http-port').value),
|
||||
username: $('#http-user').value.trim(),
|
||||
password: $('#http-pass').value,
|
||||
},
|
||||
socks5: {
|
||||
enabled: $('#socks-enabled').checked,
|
||||
host: $('#socks-host').value.trim() || '0.0.0.0',
|
||||
port: Number($('#socks-port').value),
|
||||
username: $('#socks-user').value.trim(),
|
||||
password: $('#socks-pass').value,
|
||||
},
|
||||
targetFilter: {
|
||||
mode: modeInput ? modeInput.value : 'allowAll',
|
||||
allowList,
|
||||
},
|
||||
logLevel: state.config?.logLevel || 'info',
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新接入示例文本。
|
||||
* @param {object} config 配置
|
||||
*/
|
||||
function updateExamples(config) {
|
||||
/**
|
||||
* 把监听地址转换为示例里可直接使用的地址。
|
||||
* @param {string} host 监听地址
|
||||
* @returns {string}
|
||||
*/
|
||||
const usableHost = (host) => {
|
||||
const value = String(host || '127.0.0.1');
|
||||
if (value === '0.0.0.0' || value === '::' || value === '[::]') return '127.0.0.1';
|
||||
return value.includes(':') ? `[${value.replace(/^\[|\]$/g, '')}]` : value;
|
||||
};
|
||||
|
||||
const httpAuth = config.http.username
|
||||
? `${encodeURIComponent(config.http.username)}:${encodeURIComponent(config.http.password || '')}@`
|
||||
: '';
|
||||
const socksAuth = config.socks5.username
|
||||
? `${encodeURIComponent(config.socks5.username)}:${encodeURIComponent(config.socks5.password || '')}@`
|
||||
: '';
|
||||
|
||||
const httpTarget = `http://${httpAuth}${usableHost(config.http.host)}:${config.http.port}`;
|
||||
const socksTarget = `socks5h://${socksAuth}${usableHost(config.socks5.host)}:${config.socks5.port}`;
|
||||
|
||||
$('#example-http').textContent = [
|
||||
'# HTTP 代理(curl)',
|
||||
`curl -x ${httpTarget} http://example.com`,
|
||||
'',
|
||||
'# HTTPS 走 HTTP 代理的 CONNECT 隧道',
|
||||
`curl -x ${httpTarget} https://example.com`,
|
||||
].join('\n');
|
||||
|
||||
$('#example-socks').textContent = [
|
||||
'# SOCKS5 代理(域名由代理解析)',
|
||||
`curl -x ${socksTarget} https://example.com`,
|
||||
'',
|
||||
'# 浏览器 / 系统代理设置',
|
||||
`协议:SOCKS5 地址:${usableHost(config.socks5.host)} 端口:${config.socks5.port}`,
|
||||
].join('\n');
|
||||
}
|
||||
|
||||
/**
|
||||
* 显示提示信息。
|
||||
* @param {string} message 文案
|
||||
* @param {'ok'|'err'|'info'} [tone] 语气
|
||||
*/
|
||||
function showMessage(message, tone = 'info') {
|
||||
const element = $('#save-msg');
|
||||
element.textContent = message;
|
||||
element.className = `msg ${tone === 'info' ? '' : tone}`.trim();
|
||||
}
|
||||
|
||||
/** 拉取状态并渲染 */
|
||||
async function refreshStatus() {
|
||||
try {
|
||||
const status = await api('/api/status');
|
||||
renderStatus(status);
|
||||
} catch (err) {
|
||||
$('#uptime-pill').textContent = '连接中断';
|
||||
setState($('#http-state'), '不可用', 'bad');
|
||||
setState($('#socks-state'), '不可用', 'bad');
|
||||
}
|
||||
}
|
||||
|
||||
/** 拉取配置并填充表单 */
|
||||
async function loadConfig() {
|
||||
const config = await api('/api/config');
|
||||
state.dirty = false;
|
||||
fillForm(config);
|
||||
}
|
||||
|
||||
/** 拉取日志并渲染 */
|
||||
async function refreshLogs() {
|
||||
try {
|
||||
const data = await api('/api/logs?limit=150');
|
||||
const container = $('#logs');
|
||||
if (!data.logs || data.logs.length === 0) {
|
||||
container.innerHTML = '<p class="muted">暂无日志</p>';
|
||||
return;
|
||||
}
|
||||
const html = data.logs
|
||||
.map((item) => {
|
||||
const time = new Date(item.time).toLocaleTimeString('zh-CN', { hour12: false });
|
||||
const safeMessage = escapeHtml(item.message);
|
||||
return `<div class="log-line"><span class="log-time">${time}</span><span class="log-level ${item.level}">${item.level}</span><span>${safeMessage}</span></div>`;
|
||||
})
|
||||
.join('');
|
||||
container.innerHTML = html;
|
||||
container.scrollTop = container.scrollHeight;
|
||||
} catch (err) {
|
||||
$('#logs').innerHTML = `<p class="muted">日志加载失败:${escapeHtml(err.message)}</p>`;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* HTML 转义,避免日志内容破坏页面结构。
|
||||
* @param {string} text 原文
|
||||
* @returns {string}
|
||||
*/
|
||||
function escapeHtml(text) {
|
||||
return String(text)
|
||||
.replace(/&/g, '&')
|
||||
.replace(/</g, '<')
|
||||
.replace(/>/g, '>')
|
||||
.replace(/"/g, '"');
|
||||
}
|
||||
|
||||
/** 保存配置 */
|
||||
async function saveConfig(event) {
|
||||
event.preventDefault();
|
||||
const button = $('#save-btn');
|
||||
const config = collectForm();
|
||||
|
||||
// 前端先做一次基础校验,减少无谓请求
|
||||
for (const [label, item] of [
|
||||
['HTTP 代理', config.http],
|
||||
['SOCKS5 代理', config.socks5],
|
||||
['配置页面', config.admin],
|
||||
]) {
|
||||
if (!Number.isInteger(item.port) || item.port < 1 || item.port > 65535) {
|
||||
showMessage(`${label}的端口必须是 1-65535 的整数`, 'err');
|
||||
return;
|
||||
}
|
||||
if (!item.username && item.password) {
|
||||
showMessage(`${label}填写了密码但没有用户名`, 'err');
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
button.disabled = true;
|
||||
showMessage('正在保存…');
|
||||
try {
|
||||
const result = await api('/api/config', { method: 'POST', body: JSON.stringify(config) });
|
||||
state.dirty = false;
|
||||
fillForm(result.config);
|
||||
renderStatus(result.status);
|
||||
if (result.restartRequired && result.adminAddress) {
|
||||
showMessage(`已保存。配置页面地址已变更为 ${result.adminAddress}`, 'ok');
|
||||
} else {
|
||||
showMessage('已保存并生效', 'ok');
|
||||
}
|
||||
await refreshLogs();
|
||||
} catch (err) {
|
||||
showMessage(err.message, 'err');
|
||||
} finally {
|
||||
button.disabled = false;
|
||||
}
|
||||
}
|
||||
|
||||
/** 绑定事件并初始化 */
|
||||
function init() {
|
||||
$('#config-form').addEventListener('submit', saveConfig);
|
||||
|
||||
// 表单被修改后不再被轮询结果覆盖
|
||||
$('#config-form').addEventListener('input', () => {
|
||||
state.dirty = true;
|
||||
});
|
||||
$('#config-form').addEventListener('change', () => {
|
||||
state.dirty = true;
|
||||
if (state.config) {
|
||||
// 端口 / 主机变化时即时更新接入示例
|
||||
updateExamples(collectForm());
|
||||
}
|
||||
});
|
||||
|
||||
$('#reload-btn').addEventListener('click', async () => {
|
||||
try {
|
||||
await loadConfig();
|
||||
showMessage('已重新读取配置文件', 'ok');
|
||||
} catch (err) {
|
||||
showMessage(err.message, 'err');
|
||||
}
|
||||
});
|
||||
|
||||
$('#logs-refresh').addEventListener('click', () => {
|
||||
void refreshLogs();
|
||||
});
|
||||
|
||||
// 窗口尺寸变化时按新的画布宽度重绘趋势图
|
||||
window.addEventListener('resize', () => {
|
||||
if (state.status && state.status.stats) drawChart(state.status.stats.history || []);
|
||||
});
|
||||
|
||||
// 初始化数据
|
||||
void (async () => {
|
||||
try {
|
||||
await loadConfig();
|
||||
await refreshStatus();
|
||||
await refreshLogs();
|
||||
} catch (err) {
|
||||
showMessage(`初始化失败:${err.message}`, 'err');
|
||||
}
|
||||
})();
|
||||
|
||||
// 定时刷新状态与日志
|
||||
setInterval(() => {
|
||||
void refreshStatus();
|
||||
}, 2000);
|
||||
setInterval(() => {
|
||||
void refreshLogs();
|
||||
}, 5000);
|
||||
}
|
||||
|
||||
document.addEventListener('DOMContentLoaded', init);
|
||||
})();
|
||||
@@ -0,0 +1,239 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="zh-CN">
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||
<title>Frost Network Proxy · 配置</title>
|
||||
<link rel="stylesheet" href="/style.css">
|
||||
</head>
|
||||
<body>
|
||||
<header class="topbar">
|
||||
<div class="brand">
|
||||
<span class="logo">FN</span>
|
||||
<div class="brand-text">
|
||||
<h1>Frost Network Proxy</h1>
|
||||
<p class="sub">HTTP / SOCKS5 代理控制台</p>
|
||||
</div>
|
||||
</div>
|
||||
<div class="topbar-right">
|
||||
<span class="pill" id="uptime-pill">运行时长 --</span>
|
||||
</div>
|
||||
</header>
|
||||
|
||||
<main>
|
||||
<!-- 实时状态 -->
|
||||
<section class="grid">
|
||||
<article class="card" id="card-http">
|
||||
<div class="card-head">
|
||||
<h2>HTTP 代理</h2>
|
||||
<span class="state" id="http-state">加载中</span>
|
||||
</div>
|
||||
<p class="addr" id="http-addr">--</p>
|
||||
<div class="metrics">
|
||||
<div><span class="label">活跃连接</span><strong id="http-active">0</strong></div>
|
||||
<div><span class="label">累计连接</span><strong id="http-total">0</strong></div>
|
||||
<div><span class="label">下载速率</span><strong id="http-rate-down" class="rate">0 B/s</strong></div>
|
||||
<div><span class="label">上传速率</span><strong id="http-rate-up" class="rate">0 B/s</strong></div>
|
||||
<div><span class="label">累计下载</span><strong id="http-down">0 B</strong></div>
|
||||
<div><span class="label">累计上传</span><strong id="http-up">0 B</strong></div>
|
||||
</div>
|
||||
<p class="error" id="http-error" hidden></p>
|
||||
</article>
|
||||
|
||||
<article class="card" id="card-socks5">
|
||||
<div class="card-head">
|
||||
<h2>SOCKS5 代理</h2>
|
||||
<span class="state" id="socks-state">加载中</span>
|
||||
</div>
|
||||
<p class="addr" id="socks-addr">--</p>
|
||||
<div class="metrics">
|
||||
<div><span class="label">活跃连接</span><strong id="socks-active">0</strong></div>
|
||||
<div><span class="label">累计连接</span><strong id="socks-total">0</strong></div>
|
||||
<div><span class="label">下载速率</span><strong id="socks-rate-down" class="rate">0 B/s</strong></div>
|
||||
<div><span class="label">上传速率</span><strong id="socks-rate-up" class="rate">0 B/s</strong></div>
|
||||
<div><span class="label">累计下载</span><strong id="socks-down">0 B</strong></div>
|
||||
<div><span class="label">累计上传</span><strong id="socks-up">0 B</strong></div>
|
||||
</div>
|
||||
<p class="error" id="socks-error" hidden></p>
|
||||
</article>
|
||||
|
||||
<article class="card" id="card-total">
|
||||
<div class="card-head">
|
||||
<h2>总览</h2>
|
||||
<span class="state neutral" id="filter-state">--</span>
|
||||
</div>
|
||||
<p class="addr" id="filter-desc">--</p>
|
||||
<div class="metrics">
|
||||
<div><span class="label">活跃连接</span><strong id="total-active">0</strong></div>
|
||||
<div><span class="label">累计连接</span><strong id="total-total">0</strong></div>
|
||||
<div><span class="label">下载速率</span><strong id="total-rate-down" class="rate">0 B/s</strong></div>
|
||||
<div><span class="label">上传速率</span><strong id="total-rate-up" class="rate">0 B/s</strong></div>
|
||||
<div><span class="label">累计下载</span><strong id="total-down">0 B</strong></div>
|
||||
<div><span class="label">累计上传</span><strong id="total-up">0 B</strong></div>
|
||||
</div>
|
||||
</article>
|
||||
</section>
|
||||
|
||||
<!-- 实时带宽趋势 -->
|
||||
<section class="panel">
|
||||
<header class="panel-head">
|
||||
<h2>实时网络状态</h2>
|
||||
<div class="legend">
|
||||
<span class="legend-item"><i class="dot down"></i>下载 <b id="chart-down">0 B/s</b></span>
|
||||
<span class="legend-item"><i class="dot up"></i>上传 <b id="chart-up">0 B/s</b></span>
|
||||
<span class="legend-item">峰值下载 <b id="peak-down">0 B/s</b></span>
|
||||
<span class="legend-item">峰值上传 <b id="peak-up">0 B/s</b></span>
|
||||
<span class="legend-item">连接数 <b id="chart-active">0</b></span>
|
||||
</div>
|
||||
</header>
|
||||
<canvas id="bandwidth-chart" class="chart" height="170"></canvas>
|
||||
<p class="muted chart-tip">最近 60 秒的上传 / 下载速率趋势,每 1 秒采样一次,纵轴为合计速率</p>
|
||||
</section>
|
||||
|
||||
<!-- 配置表单 -->
|
||||
<form id="config-form" autocomplete="off">
|
||||
<section class="panel">
|
||||
<header class="panel-head">
|
||||
<h2>HTTP 代理</h2>
|
||||
<label class="switch" title="启用 / 停用">
|
||||
<input type="checkbox" id="http-enabled">
|
||||
<span class="slider"></span>
|
||||
</label>
|
||||
</header>
|
||||
<div class="fields">
|
||||
<label class="field">
|
||||
<span>监听地址</span>
|
||||
<input type="text" id="http-host" placeholder="0.0.0.0">
|
||||
<em>0.0.0.0 表示所有网卡,127.0.0.1 仅本机可用</em>
|
||||
</label>
|
||||
<label class="field">
|
||||
<span>端口</span>
|
||||
<input type="number" id="http-port" min="1" max="65535" placeholder="8080">
|
||||
<em>客户端通过该端口访问 HTTP 代理</em>
|
||||
</label>
|
||||
<label class="field">
|
||||
<span>用户名</span>
|
||||
<input type="text" id="http-user" placeholder="留空表示不校验">
|
||||
<em>填写后客户端必须带代理认证</em>
|
||||
</label>
|
||||
<label class="field">
|
||||
<span>密码</span>
|
||||
<input type="text" id="http-pass" placeholder="留空表示不校验">
|
||||
<em>与用户名同时留空则无需认证</em>
|
||||
</label>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
<section class="panel">
|
||||
<header class="panel-head">
|
||||
<h2>SOCKS5 代理</h2>
|
||||
<label class="switch" title="启用 / 停用">
|
||||
<input type="checkbox" id="socks-enabled">
|
||||
<span class="slider"></span>
|
||||
</label>
|
||||
</header>
|
||||
<div class="fields">
|
||||
<label class="field">
|
||||
<span>监听地址</span>
|
||||
<input type="text" id="socks-host" placeholder="0.0.0.0">
|
||||
<em>0.0.0.0 表示所有网卡,127.0.0.1 仅本机可用</em>
|
||||
</label>
|
||||
<label class="field">
|
||||
<span>端口</span>
|
||||
<input type="number" id="socks-port" min="1" max="65535" placeholder="1080">
|
||||
<em>客户端通过该端口访问 SOCKS5 代理</em>
|
||||
</label>
|
||||
<label class="field">
|
||||
<span>用户名</span>
|
||||
<input type="text" id="socks-user" placeholder="留空表示不校验">
|
||||
<em>填写后启用 RFC 1929 用户名密码认证</em>
|
||||
</label>
|
||||
<label class="field">
|
||||
<span>密码</span>
|
||||
<input type="text" id="socks-pass" placeholder="留空表示不校验">
|
||||
<em>与用户名同时留空则无需认证</em>
|
||||
</label>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
<section class="panel">
|
||||
<header class="panel-head">
|
||||
<h2>目标 IP 限制</h2>
|
||||
<span class="hint-inline">决定允许代理到哪些目标地址</span>
|
||||
</header>
|
||||
<div class="radio-row">
|
||||
<label class="radio">
|
||||
<input type="radio" name="filter-mode" value="allowAll">
|
||||
<span>允许全部目标</span>
|
||||
</label>
|
||||
<label class="radio">
|
||||
<input type="radio" name="filter-mode" value="allowList">
|
||||
<span>仅允许列表内的 IP</span>
|
||||
</label>
|
||||
</div>
|
||||
<label class="field wide">
|
||||
<span>IP / 网段列表(每行一条)</span>
|
||||
<textarea id="filter-list" rows="6" placeholder="192.168.1.10 10.0.0.0/8 2001:db8::/32"></textarea>
|
||||
<em>支持单 IP 与 CIDR 网段;域名会先解析成 IP 再判断;白名单模式下留空表示全部拒绝</em>
|
||||
</label>
|
||||
</section>
|
||||
|
||||
<section class="panel">
|
||||
<header class="panel-head">
|
||||
<h2>配置页面</h2>
|
||||
<span class="hint-inline">修改监听地址或端口后需保存,页面会自动切换</span>
|
||||
</header>
|
||||
<div class="fields">
|
||||
<label class="field">
|
||||
<span>监听地址</span>
|
||||
<input type="text" id="admin-host" placeholder="127.0.0.1">
|
||||
<em>建议保持 127.0.0.1,仅本机可打开配置页面</em>
|
||||
</label>
|
||||
<label class="field">
|
||||
<span>端口</span>
|
||||
<input type="number" id="admin-port" min="1" max="65535" placeholder="8790">
|
||||
<em>浏览器访问 http://该地址:端口</em>
|
||||
</label>
|
||||
<label class="field">
|
||||
<span>用户名</span>
|
||||
<input type="text" id="admin-user" placeholder="留空表示不校验">
|
||||
<em>填写后打开配置页面需要登录</em>
|
||||
</label>
|
||||
<label class="field">
|
||||
<span>密码</span>
|
||||
<input type="text" id="admin-pass" placeholder="留空表示不校验">
|
||||
<em>与用户名同时留空则无需登录</em>
|
||||
</label>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
<div class="actions">
|
||||
<button class="primary" type="submit" id="save-btn">保存并应用</button>
|
||||
<button class="ghost" type="button" id="reload-btn">重新读取配置</button>
|
||||
<span class="msg" id="save-msg"></span>
|
||||
</div>
|
||||
</form>
|
||||
|
||||
<!-- 接入示例 -->
|
||||
<section class="panel">
|
||||
<header class="panel-head">
|
||||
<h2>接入示例</h2>
|
||||
<span class="hint-inline">复制后按需修改主机与端口</span>
|
||||
</header>
|
||||
<pre class="code" id="example-http">--</pre>
|
||||
<pre class="code" id="example-socks">--</pre>
|
||||
</section>
|
||||
|
||||
<!-- 日志 -->
|
||||
<section class="panel">
|
||||
<header class="panel-head">
|
||||
<h2>运行日志</h2>
|
||||
<button class="ghost small" type="button" id="logs-refresh">刷新</button>
|
||||
</header>
|
||||
<div class="logs" id="logs"><p class="muted">加载中…</p></div>
|
||||
</section>
|
||||
</main>
|
||||
|
||||
<script src="/app.js"></script>
|
||||
</body>
|
||||
</html>
|
||||
@@ -0,0 +1,623 @@
|
||||
/* ===== 全局变量与基础样式(浅色主题) ===== */
|
||||
:root {
|
||||
--bg: #f4f6fb;
|
||||
--bg-soft: #eef2f9;
|
||||
--panel: #ffffff;
|
||||
--panel-2: #fbfcfe;
|
||||
--border: #e2e8f2;
|
||||
--text: #1b2430;
|
||||
--muted: #6d7789;
|
||||
--accent: #2563eb;
|
||||
--accent-soft: rgba(37, 99, 235, 0.12);
|
||||
--ok: #0f9d63;
|
||||
--warn: #b25c00;
|
||||
--err: #d92d20;
|
||||
--radius: 14px;
|
||||
}
|
||||
|
||||
* {
|
||||
box-sizing: border-box;
|
||||
}
|
||||
|
||||
html,
|
||||
body {
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
}
|
||||
|
||||
body {
|
||||
background:
|
||||
radial-gradient(900px 500px at 12% -10%, rgba(37, 99, 235, 0.1), transparent 60%),
|
||||
radial-gradient(700px 420px at 92% 0%, rgba(16, 185, 129, 0.1), transparent 55%),
|
||||
var(--bg);
|
||||
color: var(--text);
|
||||
font-family: "Segoe UI", "PingFang SC", "Microsoft YaHei", system-ui, -apple-system, sans-serif;
|
||||
font-size: 14px;
|
||||
line-height: 1.6;
|
||||
min-height: 100vh;
|
||||
}
|
||||
|
||||
/* ===== 顶部栏 ===== */
|
||||
.topbar {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
gap: 16px;
|
||||
padding: 22px clamp(16px, 5vw, 48px) 10px;
|
||||
max-width: 1180px;
|
||||
margin: 0 auto;
|
||||
}
|
||||
|
||||
.brand {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 14px;
|
||||
}
|
||||
|
||||
.logo {
|
||||
display: grid;
|
||||
place-items: center;
|
||||
width: 42px;
|
||||
height: 42px;
|
||||
border-radius: 12px;
|
||||
background: linear-gradient(140deg, #3b82f6, #0ea5a4);
|
||||
color: #ffffff;
|
||||
font-weight: 800;
|
||||
letter-spacing: 0.5px;
|
||||
box-shadow: 0 6px 16px rgba(37, 99, 235, 0.22);
|
||||
}
|
||||
|
||||
.brand-text h1 {
|
||||
margin: 0;
|
||||
font-size: 17px;
|
||||
font-weight: 650;
|
||||
letter-spacing: 0.2px;
|
||||
color: var(--text);
|
||||
}
|
||||
|
||||
.brand-text .sub {
|
||||
margin: 0;
|
||||
font-size: 12px;
|
||||
color: var(--muted);
|
||||
}
|
||||
|
||||
.pill {
|
||||
padding: 6px 12px;
|
||||
border: 1px solid var(--border);
|
||||
border-radius: 999px;
|
||||
font-size: 12px;
|
||||
color: var(--muted);
|
||||
background: #ffffff;
|
||||
white-space: nowrap;
|
||||
box-shadow: 0 1px 2px rgba(16, 24, 40, 0.04);
|
||||
}
|
||||
|
||||
main {
|
||||
max-width: 1180px;
|
||||
margin: 0 auto;
|
||||
padding: 8px clamp(16px, 5vw, 48px) 64px;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 18px;
|
||||
}
|
||||
|
||||
/* ===== 状态卡片 ===== */
|
||||
.grid {
|
||||
display: grid;
|
||||
grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
|
||||
gap: 16px;
|
||||
}
|
||||
|
||||
.card {
|
||||
background: var(--panel);
|
||||
border: 1px solid var(--border);
|
||||
border-radius: var(--radius);
|
||||
padding: 16px 18px;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 10px;
|
||||
box-shadow: 0 1px 2px rgba(16, 24, 40, 0.04), 0 10px 24px rgba(16, 24, 40, 0.04);
|
||||
}
|
||||
|
||||
.card-head {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
gap: 10px;
|
||||
}
|
||||
|
||||
.card h2 {
|
||||
margin: 0;
|
||||
font-size: 14px;
|
||||
font-weight: 600;
|
||||
color: var(--text);
|
||||
}
|
||||
|
||||
.state {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
gap: 6px;
|
||||
font-size: 12px;
|
||||
padding: 3px 10px;
|
||||
border-radius: 999px;
|
||||
background: rgba(15, 157, 99, 0.1);
|
||||
color: #0b7d4f;
|
||||
border: 1px solid rgba(15, 157, 99, 0.25);
|
||||
white-space: nowrap;
|
||||
}
|
||||
|
||||
.state::before {
|
||||
content: "";
|
||||
width: 6px;
|
||||
height: 6px;
|
||||
border-radius: 50%;
|
||||
background: currentColor;
|
||||
}
|
||||
|
||||
.state.off {
|
||||
background: #f1f4f9;
|
||||
color: var(--muted);
|
||||
border-color: var(--border);
|
||||
}
|
||||
|
||||
.state.bad {
|
||||
background: rgba(217, 45, 32, 0.08);
|
||||
color: #b42318;
|
||||
border-color: rgba(217, 45, 32, 0.22);
|
||||
}
|
||||
|
||||
.state.neutral {
|
||||
background: rgba(37, 99, 235, 0.08);
|
||||
color: #1d4ed8;
|
||||
border-color: rgba(37, 99, 235, 0.2);
|
||||
}
|
||||
|
||||
.addr {
|
||||
margin: 0;
|
||||
font-family: "JetBrains Mono", "Cascadia Mono", Consolas, monospace;
|
||||
font-size: 13px;
|
||||
color: #1d4ed8;
|
||||
word-break: break-all;
|
||||
}
|
||||
|
||||
.addr.dim {
|
||||
color: var(--muted);
|
||||
}
|
||||
|
||||
.metrics {
|
||||
display: grid;
|
||||
grid-template-columns: repeat(2, minmax(0, 1fr));
|
||||
gap: 8px 14px;
|
||||
}
|
||||
|
||||
.metrics > div {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 2px;
|
||||
padding: 8px 10px;
|
||||
border-radius: 10px;
|
||||
background: #f7f9fd;
|
||||
border: 1px solid #eef2f8;
|
||||
}
|
||||
|
||||
.metrics .label {
|
||||
font-size: 11px;
|
||||
color: var(--muted);
|
||||
}
|
||||
|
||||
.metrics strong {
|
||||
font-size: 15px;
|
||||
font-weight: 600;
|
||||
font-variant-numeric: tabular-nums;
|
||||
color: #111a27;
|
||||
}
|
||||
|
||||
/* 速率数值用主色突出显示 */
|
||||
.metrics strong.rate {
|
||||
color: #1d4ed8;
|
||||
}
|
||||
|
||||
/* ===== 实时带宽趋势 ===== */
|
||||
.legend {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 16px;
|
||||
flex-wrap: wrap;
|
||||
font-size: 12px;
|
||||
color: var(--muted);
|
||||
}
|
||||
|
||||
.legend-item {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
gap: 6px;
|
||||
}
|
||||
|
||||
.legend-item b {
|
||||
color: #111a27;
|
||||
font-weight: 600;
|
||||
font-variant-numeric: tabular-nums;
|
||||
}
|
||||
|
||||
.dot {
|
||||
width: 8px;
|
||||
height: 8px;
|
||||
border-radius: 50%;
|
||||
display: inline-block;
|
||||
}
|
||||
|
||||
.dot.down {
|
||||
background: #2563eb;
|
||||
}
|
||||
|
||||
.dot.up {
|
||||
background: #0f9d63;
|
||||
}
|
||||
|
||||
.chart {
|
||||
width: 100%;
|
||||
height: 170px;
|
||||
display: block;
|
||||
border-radius: 10px;
|
||||
background: #fbfcfe;
|
||||
border: 1px solid #eef2f8;
|
||||
}
|
||||
|
||||
.chart-tip {
|
||||
margin: 0;
|
||||
}
|
||||
|
||||
.error {
|
||||
margin: 0;
|
||||
padding: 8px 10px;
|
||||
border-radius: 10px;
|
||||
font-size: 12px;
|
||||
color: #b42318;
|
||||
background: #fef3f2;
|
||||
border: 1px solid #fecdca;
|
||||
}
|
||||
|
||||
/* ===== 表单面板 ===== */
|
||||
form {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 16px;
|
||||
}
|
||||
|
||||
.panel {
|
||||
background: var(--panel);
|
||||
border: 1px solid var(--border);
|
||||
border-radius: var(--radius);
|
||||
padding: 18px;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 14px;
|
||||
box-shadow: 0 1px 2px rgba(16, 24, 40, 0.03), 0 10px 24px rgba(16, 24, 40, 0.03);
|
||||
}
|
||||
|
||||
.panel-head {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
gap: 12px;
|
||||
flex-wrap: wrap;
|
||||
}
|
||||
|
||||
.panel-head h2 {
|
||||
margin: 0;
|
||||
font-size: 14px;
|
||||
font-weight: 600;
|
||||
letter-spacing: 0.2px;
|
||||
color: var(--text);
|
||||
}
|
||||
|
||||
.hint-inline {
|
||||
font-size: 12px;
|
||||
color: var(--muted);
|
||||
}
|
||||
|
||||
.fields {
|
||||
display: grid;
|
||||
grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
|
||||
gap: 14px;
|
||||
}
|
||||
|
||||
.field {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 6px;
|
||||
}
|
||||
|
||||
.field.wide {
|
||||
grid-column: 1 / -1;
|
||||
}
|
||||
|
||||
.field > span {
|
||||
font-size: 12px;
|
||||
color: #44506a;
|
||||
}
|
||||
|
||||
.field > em {
|
||||
font-style: normal;
|
||||
font-size: 11px;
|
||||
color: var(--muted);
|
||||
line-height: 1.45;
|
||||
}
|
||||
|
||||
input[type="text"],
|
||||
input[type="number"],
|
||||
textarea {
|
||||
width: 100%;
|
||||
padding: 9px 12px;
|
||||
border-radius: 10px;
|
||||
border: 1px solid #dfe6f0;
|
||||
background: #ffffff;
|
||||
color: var(--text);
|
||||
font-size: 13px;
|
||||
font-family: inherit;
|
||||
outline: none;
|
||||
transition: border-color 0.15s ease, box-shadow 0.15s ease;
|
||||
}
|
||||
|
||||
input:hover,
|
||||
textarea:hover {
|
||||
border-color: #cbd6e6;
|
||||
}
|
||||
|
||||
input:focus,
|
||||
textarea:focus {
|
||||
border-color: rgba(37, 99, 235, 0.65);
|
||||
box-shadow: 0 0 0 3px var(--accent-soft);
|
||||
}
|
||||
|
||||
textarea {
|
||||
resize: vertical;
|
||||
font-family: "JetBrains Mono", "Cascadia Mono", Consolas, monospace;
|
||||
line-height: 1.6;
|
||||
}
|
||||
|
||||
input::placeholder,
|
||||
textarea::placeholder {
|
||||
color: #9aa4b5;
|
||||
}
|
||||
|
||||
/* 开关 */
|
||||
.switch {
|
||||
position: relative;
|
||||
display: inline-block;
|
||||
width: 44px;
|
||||
height: 24px;
|
||||
flex: 0 0 auto;
|
||||
}
|
||||
|
||||
.switch input {
|
||||
opacity: 0;
|
||||
width: 0;
|
||||
height: 0;
|
||||
}
|
||||
|
||||
.slider {
|
||||
position: absolute;
|
||||
inset: 0;
|
||||
border-radius: 999px;
|
||||
background: #e3e9f3;
|
||||
border: 1px solid var(--border);
|
||||
cursor: pointer;
|
||||
transition: background 0.18s ease, border-color 0.18s ease;
|
||||
}
|
||||
|
||||
.slider::before {
|
||||
content: "";
|
||||
position: absolute;
|
||||
width: 18px;
|
||||
height: 18px;
|
||||
left: 2px;
|
||||
top: 2px;
|
||||
border-radius: 50%;
|
||||
background: #ffffff;
|
||||
box-shadow: 0 1px 3px rgba(16, 24, 40, 0.22);
|
||||
transition: transform 0.18s ease;
|
||||
}
|
||||
|
||||
.switch input:checked + .slider {
|
||||
background: rgba(37, 99, 235, 0.28);
|
||||
border-color: rgba(37, 99, 235, 0.45);
|
||||
}
|
||||
|
||||
.switch input:checked + .slider::before {
|
||||
transform: translateX(20px);
|
||||
background: #ffffff;
|
||||
}
|
||||
|
||||
/* 单选 */
|
||||
.radio-row {
|
||||
display: flex;
|
||||
gap: 18px;
|
||||
flex-wrap: wrap;
|
||||
}
|
||||
|
||||
.radio {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
gap: 8px;
|
||||
font-size: 13px;
|
||||
cursor: pointer;
|
||||
color: #33415c;
|
||||
}
|
||||
|
||||
.radio input {
|
||||
accent-color: var(--accent);
|
||||
width: 15px;
|
||||
height: 15px;
|
||||
}
|
||||
|
||||
/* 按钮 */
|
||||
.actions {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 12px;
|
||||
flex-wrap: wrap;
|
||||
}
|
||||
|
||||
button {
|
||||
font-family: inherit;
|
||||
font-size: 13px;
|
||||
border-radius: 10px;
|
||||
padding: 9px 18px;
|
||||
border: 1px solid transparent;
|
||||
cursor: pointer;
|
||||
transition: transform 0.12s ease, background 0.15s ease, border-color 0.15s ease;
|
||||
}
|
||||
|
||||
button:active {
|
||||
transform: translateY(1px);
|
||||
}
|
||||
|
||||
.primary {
|
||||
background: linear-gradient(180deg, #3b82f6, #2563eb);
|
||||
color: #ffffff;
|
||||
font-weight: 600;
|
||||
box-shadow: 0 8px 18px rgba(37, 99, 235, 0.22);
|
||||
}
|
||||
|
||||
.primary:hover {
|
||||
background: linear-gradient(180deg, #4f8dfa, #2f6ff0);
|
||||
}
|
||||
|
||||
.primary:disabled {
|
||||
opacity: 0.6;
|
||||
cursor: not-allowed;
|
||||
}
|
||||
|
||||
.ghost {
|
||||
background: #ffffff;
|
||||
border-color: var(--border);
|
||||
color: #33415c;
|
||||
}
|
||||
|
||||
.ghost:hover {
|
||||
border-color: rgba(37, 99, 235, 0.45);
|
||||
color: var(--accent);
|
||||
background: #f7f9fd;
|
||||
}
|
||||
|
||||
button.small {
|
||||
padding: 5px 12px;
|
||||
font-size: 12px;
|
||||
}
|
||||
|
||||
.msg {
|
||||
font-size: 12px;
|
||||
color: var(--muted);
|
||||
min-height: 18px;
|
||||
}
|
||||
|
||||
.msg.ok {
|
||||
color: #0b7d4f;
|
||||
}
|
||||
|
||||
.msg.err {
|
||||
color: var(--err);
|
||||
}
|
||||
|
||||
/* ===== 示例代码 ===== */
|
||||
.code {
|
||||
margin: 0;
|
||||
padding: 12px 14px;
|
||||
border-radius: 10px;
|
||||
background: #f7f9fd;
|
||||
border: 1px solid #e6ecf5;
|
||||
color: #0b6b63;
|
||||
font-family: "JetBrains Mono", "Cascadia Mono", Consolas, monospace;
|
||||
font-size: 12px;
|
||||
line-height: 1.7;
|
||||
overflow-x: auto;
|
||||
white-space: pre-wrap;
|
||||
word-break: break-all;
|
||||
}
|
||||
|
||||
/* ===== 日志 ===== */
|
||||
.logs {
|
||||
max-height: 280px;
|
||||
overflow-y: auto;
|
||||
border-radius: 10px;
|
||||
border: 1px solid #e6ecf5;
|
||||
background: #fafbfd;
|
||||
padding: 10px 12px;
|
||||
font-family: "JetBrains Mono", "Cascadia Mono", Consolas, monospace;
|
||||
font-size: 12px;
|
||||
line-height: 1.7;
|
||||
}
|
||||
|
||||
.log-line {
|
||||
display: flex;
|
||||
gap: 10px;
|
||||
white-space: pre-wrap;
|
||||
word-break: break-all;
|
||||
}
|
||||
|
||||
.log-time {
|
||||
color: #98a2b3;
|
||||
flex: 0 0 auto;
|
||||
}
|
||||
|
||||
.log-level {
|
||||
flex: 0 0 auto;
|
||||
width: 46px;
|
||||
text-transform: uppercase;
|
||||
font-size: 11px;
|
||||
}
|
||||
|
||||
.log-level.info {
|
||||
color: #1d4ed8;
|
||||
}
|
||||
|
||||
.log-level.warn {
|
||||
color: var(--warn);
|
||||
}
|
||||
|
||||
.log-level.error {
|
||||
color: var(--err);
|
||||
}
|
||||
|
||||
.log-level.debug {
|
||||
color: #7c8699;
|
||||
}
|
||||
|
||||
.muted {
|
||||
color: var(--muted);
|
||||
font-size: 12px;
|
||||
}
|
||||
|
||||
/* ===== 滚动条 ===== */
|
||||
::-webkit-scrollbar {
|
||||
width: 10px;
|
||||
height: 10px;
|
||||
}
|
||||
|
||||
::-webkit-scrollbar-track {
|
||||
background: transparent;
|
||||
}
|
||||
|
||||
::-webkit-scrollbar-thumb {
|
||||
background: #d3dcea;
|
||||
border-radius: 999px;
|
||||
border: 2px solid transparent;
|
||||
background-clip: content-box;
|
||||
}
|
||||
|
||||
::-webkit-scrollbar-thumb:hover {
|
||||
background: #b7c4d8;
|
||||
background-clip: content-box;
|
||||
}
|
||||
|
||||
@media (max-width: 640px) {
|
||||
.topbar {
|
||||
flex-direction: column;
|
||||
align-items: flex-start;
|
||||
}
|
||||
|
||||
.metrics {
|
||||
grid-template-columns: repeat(2, minmax(0, 1fr));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user