mirror of
https://github.com/qingchencloud/clawpanel.git
synced 2026-06-06 00:00:06 +08:00
fix: 修复路由竞态、删除确认、输入同步等交互问题
- router.js 添加竞态防护和页面清理钩子 - logs.js 切换 Tab 时清空搜索框 - models.js 删除 Provider 添加确认提示,输入框改 oninput 实时同步 - mcp.js 删除 Server 添加确认提示 - gateway.js Tailscale 地址为空时保留原配置
This commit is contained in:
@@ -3,6 +3,8 @@
|
||||
*/
|
||||
const routes = {}
|
||||
let _contentEl = null
|
||||
let _loadId = 0
|
||||
let _currentCleanup = null
|
||||
|
||||
export function registerRoute(path, loader) {
|
||||
routes[path] = loader
|
||||
@@ -23,16 +25,33 @@ async function loadRoute() {
|
||||
const loader = routes[hash]
|
||||
if (!loader || !_contentEl) return
|
||||
|
||||
// 竞态防护:记录本次加载 ID
|
||||
const thisLoad = ++_loadId
|
||||
|
||||
// 清理上一个页面
|
||||
if (_currentCleanup) {
|
||||
try { _currentCleanup() } catch (_) {}
|
||||
_currentCleanup = null
|
||||
}
|
||||
|
||||
_contentEl.innerHTML = ''
|
||||
const mod = await loader()
|
||||
// 动态 import 返回模块对象,调用 render() 获取页面元素
|
||||
|
||||
// 如果加载期间路由又变了,丢弃本次结果
|
||||
if (thisLoad !== _loadId) return
|
||||
|
||||
const page = mod.render ? await mod.render() : mod.default ? await mod.default() : mod
|
||||
if (thisLoad !== _loadId) return
|
||||
|
||||
if (typeof page === 'string') {
|
||||
_contentEl.innerHTML = page
|
||||
} else if (page instanceof HTMLElement) {
|
||||
_contentEl.appendChild(page)
|
||||
}
|
||||
|
||||
// 保存页面清理函数
|
||||
_currentCleanup = mod.cleanup || null
|
||||
|
||||
// 更新侧边栏激活状态
|
||||
document.querySelectorAll('.nav-item').forEach(item => {
|
||||
item.classList.toggle('active', item.dataset.route === hash)
|
||||
|
||||
Reference in New Issue
Block a user