mirror of
https://github.com/YuleBest/LuminPro.git
synced 2026-12-04 00:54:42 +08:00
feat(webui):导出日志和复制日志功能
This commit is contained in:
1 parent
21f6cb2744
commit
a61c845323
3 files changed
+106
-21
No files matched your search
+18
-2
@@ -343,7 +343,7 @@
|
||||
<section class="card" id="log-section" data-nav-group="log">
|
||||
<div class="card-header">
|
||||
<h2>运行日志</h2>
|
||||
<div class="header-actions">
|
||||
<div class="header-actions dropdown-container">
|
||||
<select id="log-level-filter" class="log-filter-select">
|
||||
<option value="">全部等级</option>
|
||||
<option value="INFO">INFO</option>
|
||||
@@ -351,7 +351,23 @@
|
||||
<option value="ERROR">ERROR</option>
|
||||
<option value="SUCCESS">SUCCESS</option>
|
||||
</select>
|
||||
<button class="btn-text-s" id="btn-clear-logs">清空日志</button>
|
||||
<button class="btn-icon-only" id="btn-log-menu">
|
||||
<i data-lucide="more-vertical"></i>
|
||||
</button>
|
||||
<div class="dropdown-menu" id="log-dropdown-menu">
|
||||
<div class="dropdown-item" id="btn-copy-log">
|
||||
<svg xmlns="http://www.w3.org/2000/svg" width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><rect width="14" height="14" x="8" y="8" rx="2" ry="2"></rect><path d="M4 16c-1.1 0-2-.9-2-2V4c0-1.1.9-2 2-2h10c1.1 0 2 .9 2 2"></path></svg>
|
||||
<span>复制日志</span>
|
||||
</div>
|
||||
<div class="dropdown-item" id="btn-export-log">
|
||||
<svg xmlns="http://www.w3.org/2000/svg" width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4"></path><polyline points="7 10 12 15 17 10"></polyline><line x1="12" x2="12" y1="15" y2="3"></line></svg>
|
||||
<span>导出日志</span>
|
||||
</div>
|
||||
<div class="dropdown-item" id="btn-clear-logs">
|
||||
<svg xmlns="http://www.w3.org/2000/svg" width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M18 6 6 18"></path><path d="m6 6 12 12"></path></svg>
|
||||
<span>清空日志</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<pre class="log-output" id="log-output">加载中...</pre>
|
||||
|
||||
+79
-18
@@ -1,5 +1,5 @@
|
||||
import { exec, listPackages, getPackagesInfo } from 'kernelsu';
|
||||
import { createIcons, Sun, Settings, Settings2, Save, Activity, RefreshCw, FileText, Smartphone, MoreVertical, Eye, EyeOff, CheckSquare, CheckCheck, Square, Search, Sparkles, Plus, ShieldCheck, Moon, Play, RotateCcw, Monitor, Info, Code, User, BookOpen, X, Globe, Minus } from 'lucide';
|
||||
import { createIcons, Sun, Settings, Settings2, Save, Activity, RefreshCw, FileText, Smartphone, MoreVertical, Eye, EyeOff, CheckSquare, CheckCheck, Square, Search, Sparkles, Plus, ShieldCheck, Moon, Play, RotateCcw, Monitor, Info, Code, User, BookOpen, X, Globe, Minus, Copy, Download } from 'lucide';
|
||||
import MarkdownIt from 'markdown-it';
|
||||
import PinyinMatch from 'pinyin-match';
|
||||
|
||||
@@ -650,40 +650,68 @@ let clearLogsTimer = null;
|
||||
|
||||
async function handleClearLogs() {
|
||||
const btn = document.getElementById('btn-clear-logs');
|
||||
|
||||
const btnSpan = btn ? btn.querySelector('span') : null;
|
||||
|
||||
if (!clearLogsConfirming) {
|
||||
// 进入确认状态
|
||||
clearLogsConfirming = true;
|
||||
btn.textContent = '确认清空';
|
||||
btn.classList.add('btn-danger');
|
||||
|
||||
// 5秒后自动重置回原来状态
|
||||
if (btnSpan) btnSpan.textContent = '确认清空?';
|
||||
if (btn) btn.classList.add('dropdown-item-danger');
|
||||
clearLogsTimer = setTimeout(() => {
|
||||
clearLogsConfirming = false;
|
||||
btn.textContent = '清空日志';
|
||||
btn.classList.remove('btn-danger');
|
||||
if (btnSpan) btnSpan.textContent = '清空日志';
|
||||
if (btn) btn.classList.remove('dropdown-item-danger');
|
||||
}, 5000);
|
||||
return;
|
||||
}
|
||||
|
||||
// 执行清空动作
|
||||
clearLogsConfirming = false;
|
||||
btn.textContent = '清空日志';
|
||||
btn.classList.remove('btn-danger');
|
||||
if (btnSpan) btnSpan.textContent = '清空日志';
|
||||
if (btn) btn.classList.remove('dropdown-item-danger');
|
||||
clearTimeout(clearLogsTimer);
|
||||
|
||||
showToast('正在清空日志...');
|
||||
const res = await runCmd(`> "${LOG_FILE}"`);
|
||||
|
||||
if (res.errno === 0) {
|
||||
fullLogContent = '';
|
||||
showToast('日志已清空');
|
||||
await loadLogs(); // 刷新显示
|
||||
await loadLogs();
|
||||
} else {
|
||||
showToast('清空失败: ' + (res.stderr || '未知错误'));
|
||||
}
|
||||
}
|
||||
|
||||
async function handleCopyLog() {
|
||||
const res = await runCmd(`tail -n 50 "${LOG_FILE}"`);
|
||||
if (res.errno !== 0 || !res.stdout.trim()) {
|
||||
showToast('暂无日志内容');
|
||||
return;
|
||||
}
|
||||
const text = res.stdout.trim();
|
||||
try {
|
||||
await navigator.clipboard.writeText(text);
|
||||
showToast('已复制最新 50 条日志');
|
||||
} catch {
|
||||
const ta = document.createElement('textarea');
|
||||
ta.value = text;
|
||||
ta.style.cssText = 'position:fixed;opacity:0;pointer-events:none';
|
||||
document.body.appendChild(ta);
|
||||
ta.select();
|
||||
document.execCommand('copy');
|
||||
document.body.removeChild(ta);
|
||||
showToast('已复制最新 50 条日志');
|
||||
}
|
||||
}
|
||||
|
||||
async function handleExportLog() {
|
||||
showToast('正在导出...');
|
||||
const res = await runCmd(`cp "${LOG_FILE}" "/sdcard/LuminPro_$(date '+%Y%m%d_%H%M%S').log"`);
|
||||
if (res.errno === 0) {
|
||||
showToast('日志已导出到 /sdcard');
|
||||
} else {
|
||||
showToast('导出失败: ' + (res.stderr || '未知错误'));
|
||||
}
|
||||
}
|
||||
|
||||
// 自动刷新循环
|
||||
function stopAutoRefresh() {
|
||||
if (autoRefreshStatusLogTimer) {
|
||||
@@ -1166,15 +1194,48 @@ async function init() {
|
||||
// 绑定日志控件事件
|
||||
const logLevelFilter = document.getElementById('log-level-filter');
|
||||
const btnClearLogs = document.getElementById('btn-clear-logs');
|
||||
|
||||
const btnLogMenu = document.getElementById('btn-log-menu');
|
||||
const logDropdownMenu = document.getElementById('log-dropdown-menu');
|
||||
const btnCopyLog = document.getElementById('btn-copy-log');
|
||||
const btnExportLog = document.getElementById('btn-export-log');
|
||||
|
||||
if (logLevelFilter) {
|
||||
logLevelFilter.addEventListener('change', async () => {
|
||||
await applyLogFilter(); // 改变筛选等级时应用筛选
|
||||
await applyLogFilter();
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
if (btnLogMenu && logDropdownMenu) {
|
||||
btnLogMenu.addEventListener('click', (e) => {
|
||||
e.stopPropagation();
|
||||
logDropdownMenu.classList.toggle('show');
|
||||
});
|
||||
document.addEventListener('click', (e) => {
|
||||
if (!btnLogMenu.contains(e.target) && !logDropdownMenu.contains(e.target)) {
|
||||
logDropdownMenu.classList.remove('show');
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
if (btnClearLogs) {
|
||||
btnClearLogs.addEventListener('click', handleClearLogs);
|
||||
btnClearLogs.addEventListener('click', (e) => {
|
||||
e.stopPropagation();
|
||||
handleClearLogs();
|
||||
});
|
||||
}
|
||||
|
||||
if (btnCopyLog) {
|
||||
btnCopyLog.addEventListener('click', () => {
|
||||
logDropdownMenu && logDropdownMenu.classList.remove('show');
|
||||
handleCopyLog();
|
||||
});
|
||||
}
|
||||
|
||||
if (btnExportLog) {
|
||||
btnExportLog.addEventListener('click', () => {
|
||||
logDropdownMenu && logDropdownMenu.classList.remove('show');
|
||||
handleExportLog();
|
||||
});
|
||||
}
|
||||
|
||||
// 绑定查看支持事件按钮
|
||||
|
||||
+9
-1
@@ -1004,7 +1004,7 @@ input:checked + .slider:before {
|
||||
/* Logs */
|
||||
.log-output {
|
||||
font-family: 'Google Sans Code', 'JetBrains Mono', 'Consolas', monospace;
|
||||
font-size: 0.8125rem;
|
||||
font-size: 0.6875rem;
|
||||
padding: var(--spacing-m);
|
||||
background-color: #0d0e12;
|
||||
color: #e3e3e3;
|
||||
@@ -1258,6 +1258,14 @@ input:checked + .slider:before {
|
||||
height: 18px;
|
||||
}
|
||||
|
||||
.dropdown-item-danger {
|
||||
color: var(--md-sys-color-error, #cf6679);
|
||||
}
|
||||
|
||||
.dropdown-item-danger svg {
|
||||
color: var(--md-sys-color-error, #cf6679);
|
||||
}
|
||||
|
||||
.app-list-hint {
|
||||
font-size: 0.8125rem;
|
||||
color: var(--md-sys-color-on-surface-variant);
|
||||
|
||||
Reference in new issue
Block a user