diff --git a/data/tsp_assistant.db b/data/tsp_assistant.db index 3ed182e..2a20173 100644 Binary files a/data/tsp_assistant.db and b/data/tsp_assistant.db differ diff --git a/src/web/static/js/dashboard.js b/src/web/static/js/dashboard.js index 28f83cb..d323abf 100644 --- a/src/web/static/js/dashboard.js +++ b/src/web/static/js/dashboard.js @@ -118,10 +118,9 @@ class TSPDashboard { async applyModulePermissions() { try { - const resp = await fetch('/api/tenants/my-modules'); - const data = await resp.json(); - if (!data.success) return; - const modules = data.modules || {}; + const resp = await fetch('/api/settings'); + const settings = await resp.json(); + const modules = settings.modules || {}; // 隐藏无权限的侧边栏标签和对应内容区 document.querySelectorAll('[data-tab]').forEach(link => { const tabName = link.dataset.tab; @@ -131,6 +130,10 @@ class TSPDashboard { if (tabContent) tabContent.style.display = 'none'; } }); + // 同步系统设置页面的 checkbox 状态 + document.querySelectorAll('.sys-module-cb').forEach(cb => { + cb.checked = modules[cb.value] !== false; + }); } catch (e) { /* 权限加载失败不影响使用 */ } } diff --git a/src/web/static/js/modules/system.js b/src/web/static/js/modules/system.js index 771d556..3692548 100644 --- a/src/web/static/js/modules/system.js +++ b/src/web/static/js/modules/system.js @@ -1384,5 +1384,34 @@ Object.assign(TSPDashboard.prototype, { 内存使用: ${info.memory_usage || '0'} MB `; + }, + + async saveModulePermissions() { + try { + // 读取当前设置 + const resp = await fetch('/api/settings'); + const settings = await resp.json(); + // 收集 checkbox 状态 + const modules = {}; + document.querySelectorAll('.sys-module-cb').forEach(cb => { + modules[cb.value] = cb.checked; + }); + settings.modules = modules; + // 保存 + const saveResp = await fetch('/api/settings', { + method: 'POST', + headers: { 'Content-Type': 'application/json' }, + body: JSON.stringify(settings) + }); + const result = await saveResp.json(); + if (result.success) { + this.showNotification('模块权限已保存,刷新页面后生效', 'success'); + } else { + this.showNotification('保存失败: ' + (result.error || ''), 'error'); + } + } catch (error) { + console.error('保存模块权限失败:', error); + this.showNotification('保存模块权限失败', 'error'); + } } }); diff --git a/src/web/static/js/modules/tenants.js b/src/web/static/js/modules/tenants.js index 5e6614a..7aaf828 100644 --- a/src/web/static/js/modules/tenants.js +++ b/src/web/static/js/modules/tenants.js @@ -45,7 +45,6 @@ Object.assign(TSPDashboard.prototype, { document.getElementById('tenant-desc-input').value = ''; document.getElementById('tenant-feishu-chatgroups').value = ''; document.getElementById('tenant-system-prompt').value = ''; - document.querySelectorAll('.tenant-module-cb').forEach(cb => cb.checked = true); document.getElementById('feishu-groups-list').innerHTML = '点击"刷新群列表"从飞书拉取机器人所在的群'; new bootstrap.Modal(document.getElementById('tenantModal')).show(); }, @@ -66,11 +65,6 @@ Object.assign(TSPDashboard.prototype, { document.getElementById('tenant-feishu-chatgroups').value = (tenant.config?.feishu?.chat_groups || []).join('\n'); // 系统提示词 document.getElementById('tenant-system-prompt').value = tenant.config?.system_prompt || ''; - // 模块权限 - document.querySelectorAll('.tenant-module-cb').forEach(cb => { - const mod = cb.value; - cb.checked = tenant.config?.modules?.[mod] !== false; // 默认开启 - }); } } catch (e) { console.warn('加载租户数据失败:', e); } // 自动加载飞书群列表 @@ -169,13 +163,6 @@ Object.assign(TSPDashboard.prototype, { delete config.system_prompt; } - // 模块权限 - const modules = {}; - document.querySelectorAll('.tenant-module-cb').forEach(cb => { - modules[cb.value] = cb.checked; - }); - config.modules = modules; - if (!name) { this.showNotification('租户名称不能为空', 'error'); return; } try { diff --git a/src/web/templates/dashboard.html b/src/web/templates/dashboard.html index 6dd8b0f..d1df5b1 100644 --- a/src/web/templates/dashboard.html +++ b/src/web/templates/dashboard.html @@ -2197,9 +2197,40 @@ - - + +
取消勾选可隐藏对应功能模块,刷新页面后生效
+