重构代码结构并添加完整功能
主要改动: - 重构目录结构:合并子目录到根目录,简化项目结构 - 添加完整的查询 API:支持复杂条件查询、字段选择、游标模式 - 实现 LSM-Tree Compaction:7层结构、Score-based策略、后台异步合并 - 添加 Web UI:基于 Lit 的现代化管理界面,支持数据浏览和 Manifest 查看 - 完善文档:添加 README.md 和 examples/webui/README.md 新增功能: - Query Builder:链式查询 API,支持 Eq/Lt/Gt/In/Between/Contains 等操作符 - Web UI 组件:srdb-app、srdb-table-list、srdb-data-view、srdb-manifest-view 等 - 列选择持久化:自动保存到 localStorage - 刷新按钮:一键刷新当前视图 - 主题切换:深色/浅色主题支持 代码优化: - 使用 Go 1.24 新特性:range 7、min()、maps.Copy()、slices.Sort() - 统一组件命名:所有 Web Components 使用 srdb-* 前缀 - CSS 优化:提取共享样式,减少重复代码 - 清理遗留代码:删除未使用的方法和样式
This commit is contained in:
123
webui/static/js/components/theme-toggle.js
Normal file
123
webui/static/js/components/theme-toggle.js
Normal file
@@ -0,0 +1,123 @@
|
||||
import { LitElement, html, css } from 'https://cdn.jsdelivr.net/gh/lit/dist@3/core/lit-core.min.js';
|
||||
import { sharedStyles } from '../styles/shared-styles.js';
|
||||
|
||||
export class ThemeToggle extends LitElement {
|
||||
static properties = {
|
||||
theme: { type: String }
|
||||
};
|
||||
|
||||
static styles = [
|
||||
sharedStyles,
|
||||
css`
|
||||
:host {
|
||||
display: inline-block;
|
||||
}
|
||||
|
||||
.theme-toggle {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 8px;
|
||||
padding: 8px 12px;
|
||||
background: var(--bg-elevated);
|
||||
border: 1px solid var(--border-color);
|
||||
border-radius: var(--radius-md);
|
||||
cursor: pointer;
|
||||
transition: var(--transition);
|
||||
font-size: 14px;
|
||||
color: var(--text-primary);
|
||||
}
|
||||
|
||||
.theme-toggle:hover {
|
||||
background: var(--bg-hover);
|
||||
border-color: var(--border-hover);
|
||||
}
|
||||
|
||||
.icon {
|
||||
font-size: 18px;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
}
|
||||
|
||||
.label {
|
||||
font-weight: 500;
|
||||
}
|
||||
`
|
||||
];
|
||||
|
||||
constructor() {
|
||||
super();
|
||||
// 从 localStorage 读取主题,默认为 dark
|
||||
this.theme = localStorage.getItem('srdb-theme') || 'dark';
|
||||
this.applyTheme();
|
||||
}
|
||||
|
||||
toggleTheme() {
|
||||
this.theme = this.theme === 'dark' ? 'light' : 'dark';
|
||||
localStorage.setItem('srdb-theme', this.theme);
|
||||
this.applyTheme();
|
||||
|
||||
// 触发主题变化事件
|
||||
this.dispatchEvent(new CustomEvent('theme-changed', {
|
||||
detail: { theme: this.theme },
|
||||
bubbles: true,
|
||||
composed: true
|
||||
}));
|
||||
}
|
||||
|
||||
applyTheme() {
|
||||
const root = document.documentElement;
|
||||
|
||||
if (this.theme === 'light') {
|
||||
// 浅色主题
|
||||
root.style.setProperty('--srdb-bg-main', '#ffffff');
|
||||
root.style.setProperty('--srdb-bg-surface', '#f5f5f5');
|
||||
root.style.setProperty('--srdb-bg-elevated', '#e5e5e5');
|
||||
root.style.setProperty('--srdb-bg-hover', '#d4d4d4');
|
||||
|
||||
root.style.setProperty('--srdb-text-primary', '#1a1a1a');
|
||||
root.style.setProperty('--srdb-text-secondary', '#666666');
|
||||
root.style.setProperty('--srdb-text-tertiary', '#999999');
|
||||
|
||||
root.style.setProperty('--srdb-border-color', 'rgba(0, 0, 0, 0.1)');
|
||||
root.style.setProperty('--srdb-border-hover', 'rgba(0, 0, 0, 0.2)');
|
||||
|
||||
root.style.setProperty('--srdb-shadow-sm', '0 1px 2px 0 rgba(0, 0, 0, 0.05)');
|
||||
root.style.setProperty('--srdb-shadow-md', '0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06)');
|
||||
root.style.setProperty('--srdb-shadow-lg', '0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05)');
|
||||
root.style.setProperty('--srdb-shadow-xl', '0 20px 25px -5px rgba(0, 0, 0, 0.1), 0 10px 10px -5px rgba(0, 0, 0, 0.04)');
|
||||
} else {
|
||||
// 深色主题(默认值)
|
||||
root.style.setProperty('--srdb-bg-main', '#0f0f1a');
|
||||
root.style.setProperty('--srdb-bg-surface', '#1a1a2e');
|
||||
root.style.setProperty('--srdb-bg-elevated', '#222236');
|
||||
root.style.setProperty('--srdb-bg-hover', '#2a2a3e');
|
||||
|
||||
root.style.setProperty('--srdb-text-primary', '#ffffff');
|
||||
root.style.setProperty('--srdb-text-secondary', '#a0a0b0');
|
||||
root.style.setProperty('--srdb-text-tertiary', '#6b6b7b');
|
||||
|
||||
root.style.setProperty('--srdb-border-color', 'rgba(255, 255, 255, 0.1)');
|
||||
root.style.setProperty('--srdb-border-hover', 'rgba(255, 255, 255, 0.2)');
|
||||
|
||||
root.style.setProperty('--srdb-shadow-sm', '0 1px 2px 0 rgba(0, 0, 0, 0.3)');
|
||||
root.style.setProperty('--srdb-shadow-md', '0 4px 6px -1px rgba(0, 0, 0, 0.4), 0 2px 4px -1px rgba(0, 0, 0, 0.3)');
|
||||
root.style.setProperty('--srdb-shadow-lg', '0 10px 15px -3px rgba(0, 0, 0, 0.5), 0 4px 6px -2px rgba(0, 0, 0, 0.3)');
|
||||
root.style.setProperty('--srdb-shadow-xl', '0 20px 25px -5px rgba(0, 0, 0, 0.5), 0 10px 10px -5px rgba(0, 0, 0, 0.3)');
|
||||
}
|
||||
}
|
||||
|
||||
render() {
|
||||
return html`
|
||||
<button class="theme-toggle" @click=${this.toggleTheme}>
|
||||
<span class="icon">
|
||||
${this.theme === 'dark' ? '🌙' : '☀️'}
|
||||
</span>
|
||||
<span class="label">
|
||||
${this.theme === 'dark' ? 'Dark' : 'Light'}
|
||||
</span>
|
||||
</button>
|
||||
`;
|
||||
}
|
||||
}
|
||||
|
||||
customElements.define('srdb-theme-toggle', ThemeToggle);
|
||||
Reference in New Issue
Block a user