修改样式与lint

This commit is contained in:
2025-08-09 22:28:29 +08:00
parent 046b0ef674
commit 0e380b34a3
5 changed files with 42 additions and 154 deletions

View File

@@ -41,7 +41,7 @@
* </template>
* ```
*/
import { ref, watch } from 'vue'
import { ref, watch, getCurrentInstance, onMounted } from 'vue'
// 定义各种选项
const themes = [
@@ -224,18 +224,34 @@ export function useTheme() {
}
}
// 确保在客户端时立即初始化
// 确保在客户端时初始化
if (import.meta.client) {
// 立即初始化,避免闪烁
initializeTheme()
// 确保在DOM准备好后再次应用
onMounted(() => {
applyThemeVariables()
if (selectedThemeColor.value === 'custom') {
applyCustomColor()
const instance = getCurrentInstance()
if (instance) {
// 在组件 setup 上下文中,安全使用 onMounted
onMounted(() => {
applyThemeVariables()
if (selectedThemeColor.value === 'custom') {
applyCustomColor()
}
})
} else {
// 非组件上下文(如插件)中,等待文档就绪后应用
const run = () => {
applyThemeVariables()
if (selectedThemeColor.value === 'custom') {
applyCustomColor()
}
}
})
if (document.readyState === 'loading') {
window.addEventListener('DOMContentLoaded', () => run(), { once: true })
} else {
run()
}
}
}
const resetSettings = () => {