Files
netdisk-fast-download/web-front/src/components/DarkMode.vue
T
yukaidi 17460ff271 fix(security): 安全漏洞修复与依赖升级
- 升级 Vert.x 4.5.24 → 4.5.27, postgresql 42.7.3 → 42.7.11, logback 1.5.18 → 1.5.32, axios 1.13.5 → 1.16.1
- 修复 JWT 签名验证和密码比较的时序攻击漏洞 (MessageDigest.isEqual)
- 修复 AESUtils 使用不安全 Random 改为 SecureRandom
- 修复登录用户枚举和异常信息泄露,统一错误提示
- 修复 RateLimiter count++ 非原子操作 (AtomicInteger)
- 修复 JsParserExecutor DCL 模式缺少 volatile
- 修复 Token 日志泄露,仅打印前8字符
- 修复 Playground 密码时序攻击和堆栈泄露
- 所有 window.open 添加 noopener,noreferrer
- LocalConstant 改用 ConcurrentHashMap 保证线程安全
- Dockerfile 添加非 root 用户运行,secret.yml 加入 .gitignore
2026-05-29 14:20:54 +08:00

71 lines
1.6 KiB
Vue

<template>
<el-switch
v-model="darkMode"
size="large"
style="--el-switch-on-color: #4882f8; --el-switch-off-color: #ff8000"
inline-prompt
:active-icon="Moon"
:inactive-icon="Sunny"
@change="toggleDark"
/>
</template>
<script setup>
import { ref, watch, onMounted } from 'vue'
import { useDark, useToggle } from '@vueuse/core'
/** 引入Element-Plus图标 */
import { Sunny, Moon } from '@element-plus/icons-vue'
defineOptions({
name: 'DarkMode'
})
// 定义事件
const emit = defineEmits(['theme-change'])
/** 切换模式 */
const isDark = useDark({})
const toggleDark = useToggle(isDark)
let item = window.localStorage.getItem("darkMode");
if (item) {
item = (item === 'true');
}
/** 是否切换为暗黑模式 */
const darkMode = ref(item)
watch(darkMode, (newValue) => {
window.localStorage.setItem("darkMode", newValue);
// 发射主题变化事件
emit('theme-change', newValue)
// 应用主题到body
const html = document.documentElement;
const body = document.body;
if (html && body && html.classList && body.classList) {
if (newValue) {
body.classList.add('dark-theme')
html.classList.add('dark-theme')
} else {
body.classList.remove('dark-theme')
html.classList.remove('dark-theme')
}
}
})
onMounted(() => {
// 初始化时发射当前主题状态
emit('theme-change', darkMode.value)
// 应用初始主题
const html = document.documentElement;
const body = document.body;
if (html && body && html.classList && body.classList && darkMode.value) {
body.classList.add('dark-theme')
html.classList.add('dark-theme')
}
})
</script>