mirror of
https://github.com/qingchencloud/clawpanel.git
synced 2026-05-30 12:50:14 +08:00
feat: ClawPanel v0.1.0 项目骨架
- Tauri v2 + Vanilla JS + Vite 技术栈 - 9 个页面: 仪表盘/服务管理/日志/模型配置/Agent配置/Gateway/MCP工具/记忆文件/部署 - Rust 后端: 配置读写/服务管理(launchd)/日志读取/记忆文件管理 - 暗色主题 + 玻璃拟态 UI - Mock 数据支持纯浏览器开发调试
This commit is contained in:
44
src/router.js
Normal file
44
src/router.js
Normal file
@@ -0,0 +1,44 @@
|
||||
/**
|
||||
* 极简 hash 路由
|
||||
*/
|
||||
const routes = {}
|
||||
let _contentEl = null
|
||||
|
||||
export function registerRoute(path, loader) {
|
||||
routes[path] = loader
|
||||
}
|
||||
|
||||
export function navigate(path) {
|
||||
window.location.hash = path
|
||||
}
|
||||
|
||||
export function initRouter(contentEl) {
|
||||
_contentEl = contentEl
|
||||
window.addEventListener('hashchange', () => loadRoute())
|
||||
loadRoute()
|
||||
}
|
||||
|
||||
async function loadRoute() {
|
||||
const hash = window.location.hash.slice(1) || '/dashboard'
|
||||
const loader = routes[hash]
|
||||
if (!loader || !_contentEl) return
|
||||
|
||||
_contentEl.innerHTML = ''
|
||||
const mod = await loader()
|
||||
// 动态 import 返回模块对象,调用 render() 获取页面元素
|
||||
const page = mod.render ? await mod.render() : mod.default ? await mod.default() : mod
|
||||
if (typeof page === 'string') {
|
||||
_contentEl.innerHTML = page
|
||||
} else if (page instanceof HTMLElement) {
|
||||
_contentEl.appendChild(page)
|
||||
}
|
||||
|
||||
// 更新侧边栏激活状态
|
||||
document.querySelectorAll('.nav-item').forEach(item => {
|
||||
item.classList.toggle('active', item.dataset.route === hash)
|
||||
})
|
||||
}
|
||||
|
||||
export function getCurrentRoute() {
|
||||
return window.location.hash.slice(1) || '/dashboard'
|
||||
}
|
||||
Reference in New Issue
Block a user