Files
everything-is-suitable/everything-is-suitable-uniapp/test-dark-mode.html
T
张翔 08ea5fbe98 feat(admin): 添加用户管理相关文件
添加用户管理视图、API和状态管理文件
2026-03-28 14:37:29 +08:00

308 lines
7.9 KiB
HTML

<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>暗黑模式切换测试</title>
<style>
body {
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
margin: 0;
padding: 20px;
transition: background-color 0.3s, color 0.3s;
}
.light-mode {
background-color: #F9FAFB;
color: #333333;
}
.dark-mode {
background-color: #1E1E1E;
color: #E0E0E0;
}
.container {
max-width: 800px;
margin: 0 auto;
}
.header {
display: flex;
justify-content: space-between;
align-items: center;
margin-bottom: 20px;
padding: 20px;
background: linear-gradient(135deg, #C7A27C 0%, #E8D5B5 100%);
border-radius: 12px;
color: #FFFFFF;
}
.dark-mode .header {
background: linear-gradient(135deg, #5B9BD5 0%, #2D2D2D 100%);
}
.card {
background-color: #FFFFFF;
border: 1px solid #E5E7EB;
border-radius: 12px;
padding: 20px;
margin-bottom: 16px;
transition: all 0.3s ease;
}
.dark-mode .card {
background-color: #2D2D2D;
border-color: #404040;
}
.card:hover {
box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
transform: translateY(-2px);
}
.dark-mode .card:hover {
box-shadow: 0 4px 6px rgba(0, 0, 0, 0.3);
}
.btn {
padding: 12px 24px;
border: none;
border-radius: 8px;
font-size: 14px;
cursor: pointer;
transition: all 0.2s ease;
font-weight: 500;
}
.btn-primary {
background-color: #C7A27C;
color: #FFFFFF;
}
.dark-mode .btn-primary {
background-color: #5B9BD5;
}
.btn-primary:hover {
transform: scale(1.02);
opacity: 0.9;
}
.btn-primary:active {
transform: scale(0.98);
}
.icon {
width: 48px;
height: 48px;
cursor: pointer;
transition: transform 0.2s ease;
}
.icon:hover {
transform: scale(1.1);
}
.icon:active {
transform: scale(0.9);
}
.status {
padding: 12px;
border-radius: 8px;
margin-bottom: 16px;
font-weight: 500;
}
.status-success {
background-color: #d4edda;
color: #155724;
border: 1px solid #c3e6cb;
}
.dark-mode .status-success {
background-color: #1e4620;
color: #d4edda;
border-color: #2d5a30;
}
.status-error {
background-color: #f8d7da;
color: #721c24;
border: 1px solid #f5c6cb;
}
.dark-mode .status-error {
background-color: #5a1e24;
color: #f8d7da;
border-color: #7a2a32;
}
.test-section {
margin-top: 20px;
}
.test-item {
display: flex;
justify-content: space-between;
align-items: center;
padding: 12px;
border-bottom: 1px solid #E5E7EB;
}
.dark-mode .test-item {
border-bottom-color: #404040;
}
.test-item:last-child {
border-bottom: none;
}
.color-swatch {
width: 40px;
height: 40px;
border-radius: 8px;
border: 2px solid #E5E7EB;
}
.dark-mode .color-swatch {
border-color: #404040;
}
</style>
</head>
<body class="light-mode">
<div class="container">
<div class="header">
<h1 style="margin: 0;">暗黑模式切换测试</h1>
<svg class="icon" @click="toggleTheme" id="theme-icon" viewBox="0 0 24 24" fill="currentColor">
<path d="M12 3c-4.97 0-9 4.03-9 9s4.03 9 9 9 9-4.03 9-9c0-.46-.04-.92-.1-1.36-.98 1.37-2.58 2.26-4.4 2.26-2.98 0-5.4-2.42-5.4-5.4 0-1.81.89-3.42 2.26-4.4-.44-.06-.9-.1-1.36-.1z"/>
</svg>
</div>
<div id="status" class="status status-success" style="display: none;">
主题切换成功!
</div>
<div class="card">
<h2>当前主题状态</h2>
<div class="test-section">
<div class="test-item">
<span>主题模式</span>
<strong id="current-theme">浅色模式</strong>
</div>
<div class="test-item">
<span>背景颜色</span>
<div class="color-swatch" id="bg-color"></div>
</div>
<div class="test-item">
<span>文字颜色</span>
<div class="color-swatch" id="text-color"></div>
</div>
<div class="test-item">
<span>卡片背景</span>
<div class="color-swatch" id="card-bg"></div>
</div>
</div>
</div>
<div class="card">
<h2>测试说明</h2>
<p>点击右上角的月亮图标可以切换暗黑模式。</p>
<p>切换后,页面的所有元素应该立即更新为暗黑主题。</p>
<p>主题设置会自动保存,下次打开时会恢复上次选择的主题。</p>
</div>
<div class="card">
<h2>功能测试</h2>
<div class="test-section">
<button class="btn btn-primary" onclick="testThemeSwitch()">测试主题切换</button>
<button class="btn btn-primary" onclick="testLocalStorage()">测试本地存储</button>
<button class="btn btn-primary" onclick="testCSSVariables()">测试CSS变量</button>
</div>
</div>
</div>
<script>
let currentTheme = 'light';
function toggleTheme() {
currentTheme = currentTheme === 'light' ? 'dark' : 'light';
applyTheme(currentTheme);
showStatus('success', `已切换到${currentTheme === 'dark' ? '深色' : '浅色'}模式`);
}
function applyTheme(theme) {
const body = document.body;
const themeIcon = document.getElementById('theme-icon');
const currentThemeText = document.getElementById('current-theme');
const bgColor = document.getElementById('bg-color');
const textColor = document.getElementById('text-color');
const cardBg = document.getElementById('card-bg');
if (theme === 'dark') {
body.classList.remove('light-mode');
body.classList.add('dark-mode');
currentThemeText.textContent = '深色模式';
bgColor.style.backgroundColor = '#1E1E1E';
textColor.style.backgroundColor = '#E0E0E0';
cardBg.style.backgroundColor = '#2D2D2D';
} else {
body.classList.remove('dark-mode');
body.classList.add('light-mode');
currentThemeText.textContent = '浅色模式';
bgColor.style.backgroundColor = '#F9FAFB';
textColor.style.backgroundColor = '#333333';
cardBg.style.backgroundColor = '#FFFFFF';
}
localStorage.setItem('theme-mode', theme);
}
function showStatus(type, message) {
const status = document.getElementById('status');
status.className = `status status-${type}`;
status.textContent = message;
status.style.display = 'block';
setTimeout(() => {
status.style.display = 'none';
}, 3000);
}
function testThemeSwitch() {
toggleTheme();
showStatus('success', '主题切换测试通过!');
}
function testLocalStorage() {
const savedTheme = localStorage.getItem('theme-mode');
if (savedTheme === currentTheme) {
showStatus('success', '本地存储测试通过!');
} else {
showStatus('error', '本地存储测试失败!');
}
}
function testCSSVariables() {
const computedStyle = getComputedStyle(document.body);
const bgColor = computedStyle.backgroundColor;
if (currentTheme === 'dark' && bgColor.includes('30') || currentTheme === 'light' && bgColor.includes('250')) {
showStatus('success', 'CSS变量测试通过!');
} else {
showStatus('error', 'CSS变量测试失败!');
}
}
document.getElementById('theme-icon').addEventListener('click', toggleTheme);
window.addEventListener('load', () => {
const savedTheme = localStorage.getItem('theme-mode') || 'light';
currentTheme = savedTheme;
applyTheme(savedTheme);
});
</script>
</body>
</html>