e5d6d843c3
修复: - 环路检测正则 \s+(Onu\S+)\s+ → \s+(Onu\S+) (splitlines移除换行后尾随\s无法匹配) - 权限中间件 Header(...) → Header(None) 避免缺失Auth头返回422而非401 - 环路检测请求超时30s→120s (SSH连接30+台OLT实测需58秒) 重构 (ssh_service.py): - 提取 _send_and_wait 为私有方法,消除3处重复内部函数 - 添加 __enter__/__exit__ 上下文管理器支持 - 加固 execute_command prompt检测 (按行匹配<DEVICE_NAME>) - 移除未使用的settings import - olt.py/devices.py 调用方改用 with 语法 新功能: - 侧边栏退出登录上方显示当前用户名和角色 - 版本号从VERSION文件自动读取 (后端/health返回,前端动态显示) - 基于广西南宁经纬度计算日落时间,自动切换深色/浅色主题 - /api/olt/loopback-detection 响应增加raw字段便于排查 基础设施: - CLAUDE.md 加入 .gitignore - 新增 .claude/rules/07-remote-operations.md (远程部署操作) - 新增 .claude/rules/08-frp-notes.md (frp隧道注意事项) - 新增 VERSION 文件 (版本号 0.10.0) - 新增环路检测解析测试用例 (5个) Co-Authored-By: Claude <noreply@anthropic.com>
45 lines
1.3 KiB
JavaScript
45 lines
1.3 KiB
JavaScript
import { defineStore } from 'pinia'
|
|
import { ref, watch } from 'vue'
|
|
import { isAfterSunset, getMsUntilNextSwitch } from '../utils/sunset'
|
|
|
|
export const useThemeStore = defineStore('theme', () => {
|
|
const STORAGE_KEY = 'onu-theme'
|
|
const savedTheme = localStorage.getItem(STORAGE_KEY)
|
|
// 无手动偏好时,根据广西日落时间自动选择
|
|
const theme = ref(savedTheme || (isAfterSunset() ? 'dark' : 'light'))
|
|
|
|
const applyTheme = (t) => {
|
|
document.documentElement.setAttribute('data-theme', t)
|
|
}
|
|
|
|
let switchTimer = null
|
|
|
|
// 初始化时立即应用
|
|
applyTheme(theme.value)
|
|
|
|
// 设置日落/日出自动切换定时器,仅在用户未手动选择时生效
|
|
const scheduleAutoSwitch = () => {
|
|
if (switchTimer) clearTimeout(switchTimer)
|
|
// 始终在日落/日出时自动切换
|
|
const delay = getMsUntilNextSwitch()
|
|
switchTimer = setTimeout(() => {
|
|
theme.value = isAfterSunset() ? 'dark' : 'light'
|
|
scheduleAutoSwitch() // 递归调度下一次
|
|
}, delay + 60000) // 加 1 分钟余量
|
|
}
|
|
scheduleAutoSwitch()
|
|
|
|
// 切换
|
|
const toggle = () => {
|
|
theme.value = theme.value === 'dark' ? 'light' : 'dark'
|
|
}
|
|
|
|
// 监听变化:同步到 DOM + localStorage
|
|
watch(theme, (t) => {
|
|
applyTheme(t)
|
|
localStorage.setItem(STORAGE_KEY, t)
|
|
})
|
|
|
|
return { theme, toggle }
|
|
})
|