mirror of
https://github.com/YuleBest/LuminPro.git
synced 2026-12-04 00:54:42 +08:00
- 组件层改为 Material Web Components:按钮/输入/开关/滑条/复选/下拉/对话框/ 菜单/导航栏/过滤芯片,移除 shadcn 风格组件与 Tailwind 全家桶 - 新增完整 MD3 token 体系(颜色全角色、字阶、形状、动效、状态层), 颜色沿用既有 Google Blue;字体保持 Geist 不变 - 壳层重构:M3 固定顶栏(滚动加容器色)+ 标准导航栏(去掉拖拽手势)、 toast 改为 M3 snackbar、原生 confirm/prompt 改为 md-dialog - 数据层改走 Go JSON API(status/oplock/brightness/config/log/focus), 一次调用取代多条 shell 命令;命令参数统一 shellQuote,不再拼接未校验输入 - 懒加载 markdown-it 与拼音库;删除 apps.js 等死代码 - 体积:JS 454KB(gzip 115KB) + CSS 30KB(原 318KB+58KB),懒加载分块另计
69 lines
1.7 KiB
JavaScript
69 lines
1.7 KiB
JavaScript
import { ref, computed } from 'vue'
|
|
import { fetchLog, clearLog, exportLog } from '../api/luminpro.js'
|
|
|
|
const LEVELS = ['', 'INFO', 'WARN', 'ERROR', 'SUCCESS']
|
|
|
|
/** 日志:数据来自 Go 侧 `luminpro log tail`,等级过滤在前端进行 */
|
|
export function useLog() {
|
|
const entries = ref([])
|
|
const level = ref('')
|
|
const error = ref('')
|
|
const loading = ref(false)
|
|
|
|
const levels = LEVELS
|
|
const filtered = computed(() =>
|
|
level.value ? entries.value.filter((e) => e.level === level.value) : entries.value,
|
|
)
|
|
|
|
const asText = (list = filtered.value) =>
|
|
list.map((e) => `[${e.time}] [${e.tag}] [${e.level}] ${e.message}`.trim()).join('\n')
|
|
|
|
async function load() {
|
|
loading.value = true
|
|
try {
|
|
const page = await fetchLog(200)
|
|
entries.value = page.entries ?? []
|
|
error.value = ''
|
|
} catch (e) {
|
|
error.value = e.message
|
|
} finally {
|
|
loading.value = false
|
|
}
|
|
}
|
|
|
|
async function clear(snackbar) {
|
|
try {
|
|
await clearLog()
|
|
entries.value = []
|
|
snackbar?.('日志已清空')
|
|
} catch (e) {
|
|
snackbar?.(`清空失败: ${e.message}`)
|
|
}
|
|
}
|
|
|
|
async function exportTo(snackbar) {
|
|
try {
|
|
const res = await exportLog('/sdcard')
|
|
snackbar?.(`已导出到 ${res.path}`)
|
|
} catch (e) {
|
|
snackbar?.(`导出失败: ${e.message}`)
|
|
}
|
|
}
|
|
|
|
async function copy(snackbar) {
|
|
const text = asText()
|
|
if (!text) {
|
|
snackbar?.('暂无日志可复制')
|
|
return
|
|
}
|
|
try {
|
|
await navigator.clipboard.writeText(text)
|
|
snackbar?.('日志已复制到剪贴板')
|
|
} catch {
|
|
snackbar?.('复制失败,请手动选择文本')
|
|
}
|
|
}
|
|
|
|
return { entries, filtered, level, levels, error, loading, asText, load, clear, exportTo, copy }
|
|
}
|