feat: 暗色模式全站适配
- CSS变量体系 + dark class切换 - 全局Element Plus暗色覆盖 - 前台Home/后台AdminLayout/Login/404全部适配 - 日月图标切换按钮+localStorage持久化 - 手机端隐藏暗色开关
This commit is contained in:
@@ -0,0 +1,67 @@
|
|||||||
|
/* 暗色模式 CSS 变量体系 */
|
||||||
|
:root {
|
||||||
|
--bg-primary: #ffffff;
|
||||||
|
--bg-secondary: #f5f7fa;
|
||||||
|
--bg-card: #ffffff;
|
||||||
|
--text-primary: #333333;
|
||||||
|
--text-secondary: #888888;
|
||||||
|
--border-color: #e5e7eb;
|
||||||
|
--shadow-color: rgba(0,0,0,0.06);
|
||||||
|
--header-bg: #ffffff;
|
||||||
|
--sidebar-bg: #1e293b;
|
||||||
|
--sidebar-text: rgba(255,255,255,0.7);
|
||||||
|
--input-bg: #ffffff;
|
||||||
|
--hover-bg: rgba(0,0,0,0.04);
|
||||||
|
}
|
||||||
|
|
||||||
|
html.dark {
|
||||||
|
--bg-primary: #1a1a2e;
|
||||||
|
--bg-secondary: #16213e;
|
||||||
|
--bg-card: #1e293b;
|
||||||
|
--text-primary: #e2e8f0;
|
||||||
|
--text-secondary: #94a3b8;
|
||||||
|
--border-color: #334155;
|
||||||
|
--shadow-color: rgba(0,0,0,0.3);
|
||||||
|
--header-bg: #1e293b;
|
||||||
|
--sidebar-bg: #0f172a;
|
||||||
|
--sidebar-text: rgba(255,255,255,0.6);
|
||||||
|
--input-bg: #1e293b;
|
||||||
|
--hover-bg: rgba(255,255,255,0.05);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* 全局过渡 */
|
||||||
|
* { transition: background-color 0.3s, border-color 0.3s, color 0.3s; }
|
||||||
|
|
||||||
|
body {
|
||||||
|
background: var(--bg-secondary);
|
||||||
|
color: var(--text-primary);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Element Plus 暗色覆盖 */
|
||||||
|
html.dark .el-card { background: var(--bg-card) !important; border-color: var(--border-color) !important; }
|
||||||
|
html.dark .el-input__wrapper { background: var(--input-bg) !important; box-shadow: 0 0 0 1px var(--border-color) inset !important; }
|
||||||
|
html.dark .el-input__inner { color: var(--text-primary) !important; }
|
||||||
|
html.dark .el-select { width: 100%; }
|
||||||
|
html.dark .el-dialog { background: var(--bg-card) !important; }
|
||||||
|
html.dark .el-table { background: var(--bg-card) !important; color: var(--text-primary) !important; }
|
||||||
|
html.dark .el-table th.el-table__cell { background: var(--bg-secondary) !important; color: var(--text-primary) !important; }
|
||||||
|
html.dark .el-table__body tr:hover > td { background-color: var(--hover-bg) !important; }
|
||||||
|
html.dark .el-table--striped .el-table__body tr.el-table__row--striped td { background: var(--bg-secondary) !important; }
|
||||||
|
html.dark .el-pagination button, html.dark .el-pager li { background: transparent !important; color: var(--text-primary) !important; }
|
||||||
|
html.dark .el-pager li.is-active { color: #6366f1 !important; }
|
||||||
|
html.dark .el-breadcrumb__inner { color: var(--text-secondary) !important; }
|
||||||
|
html.dark .el-breadcrumb__inner.is-link { color: var(--text-primary) !important; }
|
||||||
|
html.dark .el-dialog__title { color: var(--text-primary) !important; }
|
||||||
|
html.dark .el-form-item__label { color: var(--text-secondary) !important; }
|
||||||
|
html.dark .el-message-box { background: var(--bg-card) !important; }
|
||||||
|
html.dark .el-message-box__title { color: var(--text-primary) !important; }
|
||||||
|
html.dark .el-message-box__message { color: var(--text-secondary) !important; }
|
||||||
|
html.dark .el-message { min-width: auto !important; }
|
||||||
|
html.dark .el-switch__core { border-color: var(--border-color) !important; }
|
||||||
|
html.dark .el-color-picker__trigger { border-color: var(--border-color) !important; }
|
||||||
|
html.dark .el-radio__label { color: var(--text-primary) !important; }
|
||||||
|
html.dark .el-select-dropdown { background: var(--bg-card) !important; border-color: var(--border-color) !important; }
|
||||||
|
html.dark .el-select-dropdown__item { color: var(--text-primary) !important; }
|
||||||
|
html.dark .el-select-dropdown__item.hover { background: var(--hover-bg) !important; }
|
||||||
|
html.dark .el-popper { background: var(--bg-card) !important; border-color: var(--border-color) !important; }
|
||||||
|
html.dark .el-input-number__decrease, html.dark .el-input-number__increase { background: var(--bg-secondary) !important; color: var(--text-primary) !important; }
|
||||||
@@ -0,0 +1,21 @@
|
|||||||
|
import { ref, watch } from 'vue'
|
||||||
|
|
||||||
|
const isDark = ref(localStorage.getItem('yx-nav-theme') === 'dark')
|
||||||
|
|
||||||
|
if (isDark.value) {
|
||||||
|
document.documentElement.classList.add('dark')
|
||||||
|
}
|
||||||
|
|
||||||
|
watch(isDark, (val) => {
|
||||||
|
if (val) {
|
||||||
|
document.documentElement.classList.add('dark')
|
||||||
|
} else {
|
||||||
|
document.documentElement.classList.remove('dark')
|
||||||
|
}
|
||||||
|
localStorage.setItem('yx-nav-theme', val ? 'dark' : 'light')
|
||||||
|
})
|
||||||
|
|
||||||
|
export function useDarkMode() {
|
||||||
|
function toggle() { isDark.value = !isDark.value }
|
||||||
|
return { isDark, toggle }
|
||||||
|
}
|
||||||
@@ -5,6 +5,7 @@ import router from './router'
|
|||||||
import ElementPlus from 'element-plus'
|
import ElementPlus from 'element-plus'
|
||||||
import 'element-plus/dist/index.css'
|
import 'element-plus/dist/index.css'
|
||||||
import './assets/styles/index.scss'
|
import './assets/styles/index.scss'
|
||||||
|
import './assets/styles/dark.scss'
|
||||||
|
|
||||||
const app = createApp(App)
|
const app = createApp(App)
|
||||||
app.use(createPinia())
|
app.use(createPinia())
|
||||||
|
|||||||
@@ -10,6 +10,7 @@
|
|||||||
<el-icon><Setting /></el-icon>
|
<el-icon><Setting /></el-icon>
|
||||||
后台管理
|
后台管理
|
||||||
</a>
|
</a>
|
||||||
|
<el-button class="dark-toggle" @click="darkToggle" :icon="isDark ? 'Sunny' : 'Moon'" circle size="small" />
|
||||||
<el-input
|
<el-input
|
||||||
v-model="search"
|
v-model="search"
|
||||||
placeholder="搜索网址..."
|
placeholder="搜索网址..."
|
||||||
@@ -70,6 +71,9 @@ import { ref, reactive, computed } from 'vue'
|
|||||||
import { Search, Setting } from '@element-plus/icons-vue'
|
import { Search, Setting } from '@element-plus/icons-vue'
|
||||||
import { ElMessage } from 'element-plus'
|
import { ElMessage } from 'element-plus'
|
||||||
import { siteApi } from '@/api'
|
import { siteApi } from '@/api'
|
||||||
|
import { useDarkMode } from '@/composables/useDarkMode'
|
||||||
|
|
||||||
|
const { isDark, toggle: darkToggle } = useDarkMode()
|
||||||
|
|
||||||
const data = reactive({ categories: [] as any[], settings: {} as any, links: [] as any[] })
|
const data = reactive({ categories: [] as any[], settings: {} as any, links: [] as any[] })
|
||||||
const search = ref('')
|
const search = ref('')
|
||||||
@@ -282,6 +286,7 @@ loadData()
|
|||||||
padding: 6px 12px;
|
padding: 6px 12px;
|
||||||
font-size: 13px;
|
font-size: 13px;
|
||||||
}
|
}
|
||||||
|
.dark-toggle { display: none; }
|
||||||
}
|
}
|
||||||
.main-content { padding: 16px; }
|
.main-content { padding: 16px; }
|
||||||
.links-grid { grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: 10px; }
|
.links-grid { grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: 10px; }
|
||||||
@@ -289,4 +294,15 @@ loadData()
|
|||||||
.category-header .name { font-size: 16px; }
|
.category-header .name { font-size: 16px; }
|
||||||
.category-section { margin-bottom: 24px; }
|
.category-section { margin-bottom: 24px; }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* 暗色模式 */
|
||||||
|
html.dark .home { background: linear-gradient(135deg, #1a1a2e 0%, #16213e 100%); }
|
||||||
|
html.dark .header { background: var(--header-bg); box-shadow: 0 2px 12px rgba(0,0,0,0.3); }
|
||||||
|
html.dark .link-card { background: var(--bg-card); box-shadow: 0 1px 4px rgba(0,0,0,0.2); }
|
||||||
|
html.dark .link-card:hover { box-shadow: 0 6px 16px rgba(99,102,241,0.3); }
|
||||||
|
html.dark .link-desc { color: #64748b; }
|
||||||
|
html.dark .category-header { border-bottom-color: var(--border-color); }
|
||||||
|
html.dark .category-header .count { background: #334155; color: #94a3b8; }
|
||||||
|
html.dark .footer { color: #475569; }
|
||||||
|
html.dark .dark-toggle { color: #fbbf24 !important; }
|
||||||
</style>
|
</style>
|
||||||
|
|||||||
@@ -16,6 +16,8 @@
|
|||||||
justify-content: center;
|
justify-content: center;
|
||||||
background: #f5f7fa;
|
background: #f5f7fa;
|
||||||
}
|
}
|
||||||
|
html.dark .not-found { background: var(--bg-secondary); }
|
||||||
|
html.dark .nf-card p { color: var(--text-secondary); }
|
||||||
.nf-card {
|
.nf-card {
|
||||||
text-align: center;
|
text-align: center;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -39,6 +39,10 @@
|
|||||||
</el-breadcrumb>
|
</el-breadcrumb>
|
||||||
</div>
|
</div>
|
||||||
<div class="user-area">
|
<div class="user-area">
|
||||||
|
<el-button class="dark-toggle" @click="darkToggle" circle size="small">
|
||||||
|
<el-icon v-if="isDark"><Sunny /></el-icon>
|
||||||
|
<el-icon v-else><Moon /></el-icon>
|
||||||
|
</el-button>
|
||||||
<span class="nickname">{{ store.user?.nickname || '管理员' }}</span>
|
<span class="nickname">{{ store.user?.nickname || '管理员' }}</span>
|
||||||
<el-button text @click="handleLogout">退出</el-button>
|
<el-button text @click="handleLogout">退出</el-button>
|
||||||
</div>
|
</div>
|
||||||
@@ -51,12 +55,14 @@
|
|||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import { ref, computed, onMounted, onUnmounted } from 'vue'
|
import { ref, computed, onMounted, onUnmounted } from 'vue'
|
||||||
import { useRoute } from 'vue-router'
|
import { useRoute } from 'vue-router'
|
||||||
import { DataBoard, Link, Folder, Setting } from '@element-plus/icons-vue'
|
import { DataBoard, Link, Folder, Setting, Sunny, Moon } from '@element-plus/icons-vue'
|
||||||
import { useUserStore } from '@/stores/user'
|
import { useUserStore } from '@/stores/user'
|
||||||
import router from '@/router'
|
import router from '@/router'
|
||||||
|
import { useDarkMode } from '@/composables/useDarkMode'
|
||||||
|
|
||||||
const route = useRoute()
|
const route = useRoute()
|
||||||
const store = useUserStore()
|
const store = useUserStore()
|
||||||
|
const { isDark, toggle: darkToggle } = useDarkMode()
|
||||||
const sidebarWidth = '200px'
|
const sidebarWidth = '200px'
|
||||||
const sidebarVisible = ref(false)
|
const sidebarVisible = ref(false)
|
||||||
const isMobile = ref(window.innerWidth < 768)
|
const isMobile = ref(window.innerWidth < 768)
|
||||||
@@ -169,8 +175,17 @@ function handleLogout() {
|
|||||||
.hamburger::after { top: 6px; }
|
.hamburger::after { top: 6px; }
|
||||||
.user-area { display: flex; align-items: center; gap: 12px; flex-shrink: 0; }
|
.user-area { display: flex; align-items: center; gap: 12px; flex-shrink: 0; }
|
||||||
.nickname { color: #555; font-weight: 500; white-space: nowrap; }
|
.nickname { color: #555; font-weight: 500; white-space: nowrap; }
|
||||||
|
.dark-toggle { border: none; font-size: 18px; }
|
||||||
.el-main { background: #f5f7fa; padding: 24px; overflow-y: auto; flex: 1; }
|
.el-main { background: #f5f7fa; padding: 24px; overflow-y: auto; flex: 1; }
|
||||||
|
|
||||||
|
/* 暗色模式 */
|
||||||
|
html.dark .el-main { background: var(--bg-secondary); }
|
||||||
|
html.dark .admin-header { border-bottom-color: var(--border-color); }
|
||||||
|
html.dark .nickname { color: var(--text-secondary); }
|
||||||
|
html.dark .el-breadcrumb__inner { color: var(--text-secondary) !important; }
|
||||||
|
html.dark .el-breadcrumb__inner.is-link { color: var(--text-primary) !important; }
|
||||||
|
html.dark .dark-toggle { color: #fbbf24; }
|
||||||
|
|
||||||
@media (max-width: 767px) {
|
@media (max-width: 767px) {
|
||||||
.sidebar {
|
.sidebar {
|
||||||
position: fixed;
|
position: fixed;
|
||||||
|
|||||||
@@ -81,6 +81,10 @@ async function handleLogin() {
|
|||||||
.subtitle { color: #888; margin: 8px 0 24px; }
|
.subtitle { color: #888; margin: 8px 0 24px; }
|
||||||
.login-btn { width: 100%; margin-top: 8px; }
|
.login-btn { width: 100%; margin-top: 8px; }
|
||||||
|
|
||||||
|
html.dark .login-card { background: var(--bg-card); }
|
||||||
|
html.dark .login-card h2 { color: var(--text-primary); }
|
||||||
|
html.dark .subtitle { color: var(--text-secondary); }
|
||||||
|
|
||||||
@media (max-width: 480px) {
|
@media (max-width: 480px) {
|
||||||
.login-card { padding: 32px 24px; }
|
.login-card { padding: 32px 24px; }
|
||||||
.login-card h2 { font-size: 20px; }
|
.login-card h2 { font-size: 20px; }
|
||||||
|
|||||||
Reference in New Issue
Block a user