From 28e90d2182b6cdc60c1a27bc5ec70055841f5dea Mon Sep 17 00:00:00 2001 From: Jeason <1710884619@qq.com> Date: Thu, 2 Apr 2026 15:25:50 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E9=A3=9E=E4=B9=A6=E7=BE=A4=E7=BB=91?= =?UTF-8?q?=E5=AE=9A=E7=A7=9F=E6=88=B7=E5=AE=8C=E5=96=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - tenants.js 去掉已删除的 appid/appsecret 元素引用 - showEditTenantModal 改为从 API 加载完整租户数据(不再传参拼接) - saveTenant 保留已有的非 feishu 配置,只更新 chat_groups - 租户列表显示绑定群数量或'未绑定飞书群' - 飞书 bot/longconn 复用已有会话时同步更新 tenant_id(群重新绑定后立即生效) - 删除租户后同步刷新租户选择器 --- data/tsp_assistant.db | Bin 204800 -> 204800 bytes src/integrations/feishu_longconn_service.py | 3 + src/web/blueprints/feishu_bot.py | 3 + src/web/static/js/modules/tenants.js | 71 ++++++++++---------- 4 files changed, 42 insertions(+), 35 deletions(-) diff --git a/data/tsp_assistant.db b/data/tsp_assistant.db index ebaa33277e53125f31853bfd5f3399bbf0dbf9c9..2df7fb7a576e60188caac719c6134da2cd2ab573 100644 GIT binary patch delta 1517 zcmbtUZ%i9y7=Q0=St%==9e)PWtp$c?lyZN1cNDXX+BjVTsNYPMtt;%75!^rvnCS<& zD$pSaq-^iT&;e#RXP_=!C@Te~IKDWInE1uP2g2P^7MI44elfmvfAd6dpMha3Xv%8m>>Nu4|Loh{l%`340LbGRAEiGC z8ZFD|Mkz;=0i64QGf!^@4hP6b#9f$0ax`t@X}ZNDzUQJS8ZB9f{5E%8bA7A$zF6yN ztZNXP8H(XcDO)MUSZJ;SmttuvCD_Ut`_mELO0yirm7f$(xm(_8mfnUWkcXJ#YOHfHH0$O?k*lj^Pukp+O>A@9Ii8{FXr8U5MP6{#G@cb* zv>?REavb|F(4COae8Q@~WPthJ<^w+RgUbV#sLcHYKt332E+ zNsOmy$a8?aOse@K*DhRx%R*LHADNlVn4*Y9@+J!$4c3d4^cd zh@@XN)b4&!KLv(UTXi4qYEJPF41AE|J*dwFN4<8lj&L~i`aB0n1-RR|u|E+SG*UoV zvXWbg8)oC|JmYs%?KhX(64Jc1CKEWlT(M4{l*Hd!we}c{y%MZ6P1zU$gU$PeN7$EP zCOG1CZo`gMKm2FxBTK!n5Sc*mx{IGA|Fa2Z`ybZK5r(*cT$2rt#}hNTjY}$(;1Zmz zJfIEbK1Uqc)kzUk6x5Cwv~Urm-%X39+=7d^Wm7P_qoH6A0M3ug9J-E!I$#F)W79Dc zGT(=~;vQwrr*_{|C(f_WTvol;mFaQyvupBnuRJ%u*6vk0f^zuN&DBAle+NtSI2ir% z3#BuNPTYstnportT3SvV-YOun(J20%t4v%{hOfsWJ<3ctIys5+My0{^;0$_W0hT_t z3a?vysaQMDhWZ!a>jcWGfqV7GDn}X$tAF|91{z&~``Qw-mXO_DZpj3I^d55P`i;7x zA}mNU=F@TN*Jfi8DH;fEpm@a%sY~&FBZoWXnRfZMPw5EBvwj@f7`qgUTvY>u%D7hv zbgqv`8(qEYvy*G>QuNli>I-cQO3LJr>boeYe!mxgemoi~wL*$O zXI5Y~lFDHI#lMJ@Lgpn);kzxOrx{-`TY@ { - const feishuCfg = t.config?.feishu || {}; - const groupCount = (feishuCfg.chat_groups || []).length; - const hasFeishu = feishuCfg.app_id || groupCount > 0; + const chatGroups = t.config?.feishu?.chat_groups || []; return `
@@ -26,10 +24,10 @@ Object.assign(TSPDashboard.prototype, { (${t.tenant_id}) ${t.description ? `
${t.description}` : ''} ${!t.is_active ? '已禁用' : ''} - ${hasFeishu ? `飞书${groupCount > 0 ? ` (${groupCount}群)` : ''}` : ''} + ${chatGroups.length > 0 ? `${chatGroups.length} 个飞书群` : '未绑定飞书群'}
- ${t.tenant_id !== 'default' ? ` @@ -54,33 +52,30 @@ Object.assign(TSPDashboard.prototype, { document.getElementById('tenant-id-group').style.display = ''; document.getElementById('tenant-name-input').value = ''; document.getElementById('tenant-desc-input').value = ''; - document.getElementById('tenant-feishu-appid').value = ''; - document.getElementById('tenant-feishu-appsecret').value = ''; document.getElementById('tenant-feishu-chatgroups').value = ''; new bootstrap.Modal(document.getElementById('tenantModal')).show(); }, - async showEditTenantModal(tenantId, name, description) { + async showEditTenantModal(tenantId) { document.getElementById('tenantModalTitle').textContent = '编辑租户'; document.getElementById('tenant-edit-id').value = tenantId; document.getElementById('tenant-id-input').value = tenantId; document.getElementById('tenant-id-input').disabled = true; - document.getElementById('tenant-name-input').value = name; - document.getElementById('tenant-desc-input').value = description; + document.getElementById('tenant-id-group').style.display = 'none'; - // 加载租户的飞书配置 + // 加载租户完整数据 try { const resp = await fetch('/api/tenants'); const tenants = await resp.json(); const tenant = tenants.find(t => t.tenant_id === tenantId); - const feishuCfg = tenant?.config?.feishu || {}; - document.getElementById('tenant-feishu-appid').value = feishuCfg.app_id || ''; - document.getElementById('tenant-feishu-appsecret').value = feishuCfg.app_secret || ''; - document.getElementById('tenant-feishu-chatgroups').value = (feishuCfg.chat_groups || []).join('\n'); + if (tenant) { + document.getElementById('tenant-name-input').value = tenant.name || ''; + document.getElementById('tenant-desc-input').value = tenant.description || ''; + const chatGroups = tenant.config?.feishu?.chat_groups || []; + document.getElementById('tenant-feishu-chatgroups').value = chatGroups.join('\n'); + } } catch (e) { - document.getElementById('tenant-feishu-appid').value = ''; - document.getElementById('tenant-feishu-appsecret').value = ''; - document.getElementById('tenant-feishu-chatgroups').value = ''; + console.warn('加载租户数据失败:', e); } new bootstrap.Modal(document.getElementById('tenantModal')).show(); @@ -92,24 +87,32 @@ Object.assign(TSPDashboard.prototype, { const name = document.getElementById('tenant-name-input').value.trim(); const description = document.getElementById('tenant-desc-input').value.trim(); - // 飞书配置 - const feishuAppId = document.getElementById('tenant-feishu-appid').value.trim(); - const feishuAppSecret = document.getElementById('tenant-feishu-appsecret').value.trim(); + // 飞书群绑定 const chatGroupsText = document.getElementById('tenant-feishu-chatgroups').value.trim(); const chatGroups = chatGroupsText ? chatGroupsText.split('\n').map(s => s.trim()).filter(Boolean) : []; - const config = {}; - if (feishuAppId || feishuAppSecret || chatGroups.length > 0) { - config.feishu = {}; - if (feishuAppId) config.feishu.app_id = feishuAppId; - if (feishuAppSecret) config.feishu.app_secret = feishuAppSecret; - if (chatGroups.length > 0) config.feishu.chat_groups = chatGroups; + // 构建 config,保留已有的非 feishu 配置 + let existingConfig = {}; + if (editId) { + try { + const resp = await fetch('/api/tenants'); + const tenants = await resp.json(); + const tenant = tenants.find(t => t.tenant_id === editId); + existingConfig = tenant?.config || {}; + } catch (e) {} + } + const config = { ...existingConfig }; + if (chatGroups.length > 0) { + config.feishu = { ...(config.feishu || {}), chat_groups: chatGroups }; + } else { + // 清空飞书群绑定 + if (config.feishu) { + delete config.feishu.chat_groups; + if (Object.keys(config.feishu).length === 0) delete config.feishu; + } } - if (!name) { - this.showNotification('租户名称不能为空', 'error'); - return; - } + if (!name) { this.showNotification('租户名称不能为空', 'error'); return; } try { let response; @@ -120,10 +123,7 @@ Object.assign(TSPDashboard.prototype, { body: JSON.stringify({ name, description, config }) }); } else { - if (!tenantId) { - this.showNotification('租户标识不能为空', 'error'); - return; - } + if (!tenantId) { this.showNotification('租户标识不能为空', 'error'); return; } response = await fetch('/api/tenants', { method: 'POST', headers: { 'Content-Type': 'application/json' }, @@ -154,6 +154,7 @@ Object.assign(TSPDashboard.prototype, { if (data.success) { this.showNotification('租户已删除', 'success'); this.loadTenantList(); + this.populateTenantSelectors(); } else { this.showNotification(data.error || '删除失败', 'error'); }