From 369e61404ece45c075ffde28a5ca87e1614edfde Mon Sep 17 00:00:00 2001 From: Jeason <1710884619@qq.com> Date: Thu, 2 Apr 2026 23:16:45 +0800 Subject: [PATCH] =?UTF-8?q?refactor:=20=E6=A8=A1=E5=9D=97=E6=9D=83?= =?UTF-8?q?=E9=99=90=E4=BB=8E=E7=A7=9F=E6=88=B7=E7=AE=A1=E7=90=86=E7=A7=BB?= =?UTF-8?q?=E5=88=B0=E7=B3=BB=E7=BB=9F=E8=AE=BE=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 模块权限 checkbox 从租户编辑弹窗移除 - 系统设置页面新增'模块权限'配置区(14个模块独立开关) - 权限保存到 system_settings.json 的 modules 字段 - applyModulePermissions 改为从系统设置读取(不再从租户配置读取) - 加载系统设置时自动同步 checkbox 状态 - 租户管理只保留:名称、描述、飞书群绑定、系统提示词 --- data/tsp_assistant.db | Bin 217088 -> 217088 bytes src/web/static/js/dashboard.js | 11 ++++-- src/web/static/js/modules/system.js | 29 ++++++++++++++ src/web/static/js/modules/tenants.js | 13 ------- src/web/templates/dashboard.html | 54 ++++++++++++++++----------- src/web/templates/login.html | 5 --- 6 files changed, 69 insertions(+), 43 deletions(-) diff --git a/data/tsp_assistant.db b/data/tsp_assistant.db index 3ed182e9c95fd79ba41c2c34ee80c6584d75f3a8..2a20173037bbecbd4054d5894b869665aa66a201 100644 GIT binary patch delta 965 zcmd5)O;5r=5N+v2sipBq@X+AZHhh$iHkb(f5m&mD4ec&=7YP~y2{9f#pr>B>3&sN% ze*!1}4HtEbA?<;SCp^x~n>X{`%xtO5mdZ;`T)&>R#r50u^CDBW3w7Hp8m3vc3f6qH zc-kz))n<`88ptQ#LP~B4nTFhYKh>(TGPhG{A)8f>o6Sc*{LDy2wZsW5yHqiXwQ{{| zh99b=g(X!wpI&HrpEyGg(!8xbj_PzD@=V`RE?*2pU`PpC2LM#U Q9QsG}KmEw+OO;YrKe@CybpQYW delta 162 zcmZozz}v8ZcY-wIiHS1Kj3+iGbocWaS(zGJnHcLC8=G4g7&ZUwZ~xiPxcz586Gs6z ze;5N3-%$qs48EhA1r>Jk@iy`?aWP0r@^U&lHi}O7=VmsXp2p40KYaopv%>WC+|0@f zwG0dlLJZQXhF~QrscDI&jiQWP4APR45KTP1%$7h)P0XxJ4D}4mO-(EfLE4?S|L13B GbN~SDTPkk= 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 @@ - - + +
+
+
+
+
模块权限
+ +
+
+

取消勾选可隐藏对应功能模块,刷新页面后生效

+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+