refactor: 模块权限从租户管理移到系统设置
- 模块权限 checkbox 从租户编辑弹窗移除 - 系统设置页面新增'模块权限'配置区(14个模块独立开关) - 权限保存到 system_settings.json 的 modules 字段 - applyModulePermissions 改为从系统设置读取(不再从租户配置读取) - 加载系统设置时自动同步 checkbox 状态 - 租户管理只保留:名称、描述、飞书群绑定、系统提示词
This commit is contained in:
Binary file not shown.
@@ -118,10 +118,9 @@ class TSPDashboard {
|
|||||||
|
|
||||||
async applyModulePermissions() {
|
async applyModulePermissions() {
|
||||||
try {
|
try {
|
||||||
const resp = await fetch('/api/tenants/my-modules');
|
const resp = await fetch('/api/settings');
|
||||||
const data = await resp.json();
|
const settings = await resp.json();
|
||||||
if (!data.success) return;
|
const modules = settings.modules || {};
|
||||||
const modules = data.modules || {};
|
|
||||||
// 隐藏无权限的侧边栏标签和对应内容区
|
// 隐藏无权限的侧边栏标签和对应内容区
|
||||||
document.querySelectorAll('[data-tab]').forEach(link => {
|
document.querySelectorAll('[data-tab]').forEach(link => {
|
||||||
const tabName = link.dataset.tab;
|
const tabName = link.dataset.tab;
|
||||||
@@ -131,6 +130,10 @@ class TSPDashboard {
|
|||||||
if (tabContent) tabContent.style.display = 'none';
|
if (tabContent) tabContent.style.display = 'none';
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
// 同步系统设置页面的 checkbox 状态
|
||||||
|
document.querySelectorAll('.sys-module-cb').forEach(cb => {
|
||||||
|
cb.checked = modules[cb.value] !== false;
|
||||||
|
});
|
||||||
} catch (e) { /* 权限加载失败不影响使用 */ }
|
} catch (e) { /* 权限加载失败不影响使用 */ }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1384,5 +1384,34 @@ Object.assign(TSPDashboard.prototype, {
|
|||||||
<strong>内存使用:</strong> ${info.memory_usage || '0'} MB
|
<strong>内存使用:</strong> ${info.memory_usage || '0'} MB
|
||||||
</div>
|
</div>
|
||||||
`;
|
`;
|
||||||
|
},
|
||||||
|
|
||||||
|
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');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -45,7 +45,6 @@ Object.assign(TSPDashboard.prototype, {
|
|||||||
document.getElementById('tenant-desc-input').value = '';
|
document.getElementById('tenant-desc-input').value = '';
|
||||||
document.getElementById('tenant-feishu-chatgroups').value = '';
|
document.getElementById('tenant-feishu-chatgroups').value = '';
|
||||||
document.getElementById('tenant-system-prompt').value = '';
|
document.getElementById('tenant-system-prompt').value = '';
|
||||||
document.querySelectorAll('.tenant-module-cb').forEach(cb => cb.checked = true);
|
|
||||||
document.getElementById('feishu-groups-list').innerHTML = '<small class="text-muted">点击"刷新群列表"从飞书拉取机器人所在的群</small>';
|
document.getElementById('feishu-groups-list').innerHTML = '<small class="text-muted">点击"刷新群列表"从飞书拉取机器人所在的群</small>';
|
||||||
new bootstrap.Modal(document.getElementById('tenantModal')).show();
|
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-feishu-chatgroups').value = (tenant.config?.feishu?.chat_groups || []).join('\n');
|
||||||
// 系统提示词
|
// 系统提示词
|
||||||
document.getElementById('tenant-system-prompt').value = tenant.config?.system_prompt || '';
|
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); }
|
} catch (e) { console.warn('加载租户数据失败:', e); }
|
||||||
// 自动加载飞书群列表
|
// 自动加载飞书群列表
|
||||||
@@ -169,13 +163,6 @@ Object.assign(TSPDashboard.prototype, {
|
|||||||
delete config.system_prompt;
|
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; }
|
if (!name) { this.showNotification('租户名称不能为空', 'error'); return; }
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
|||||||
@@ -2197,9 +2197,40 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
|
||||||
|
|
||||||
<!-- 租户管理标签页 -->
|
<!-- 模块权限配置 -->
|
||||||
|
<div class="row mt-4">
|
||||||
|
<div class="col-12">
|
||||||
|
<div class="card">
|
||||||
|
<div class="card-header d-flex justify-content-between align-items-center">
|
||||||
|
<h5><i class="fas fa-th-large me-2"></i>模块权限</h5>
|
||||||
|
<button class="btn btn-primary btn-sm" onclick="dashboard.saveModulePermissions()">
|
||||||
|
<i class="fas fa-save me-1"></i>保存
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
<div class="card-body">
|
||||||
|
<p class="text-muted small mb-3">取消勾选可隐藏对应功能模块,刷新页面后生效</p>
|
||||||
|
<div class="row" id="module-permissions-area">
|
||||||
|
<div class="col-md-3 col-6"><div class="form-check"><input class="form-check-input sys-module-cb" type="checkbox" value="dashboard" id="smod-dashboard" checked><label class="form-check-label" for="smod-dashboard">仪表板</label></div></div>
|
||||||
|
<div class="col-md-3 col-6"><div class="form-check"><input class="form-check-input sys-module-cb" type="checkbox" value="chat" id="smod-chat" checked><label class="form-check-label" for="smod-chat">智能对话</label></div></div>
|
||||||
|
<div class="col-md-3 col-6"><div class="form-check"><input class="form-check-input sys-module-cb" type="checkbox" value="knowledge" id="smod-knowledge" checked><label class="form-check-label" for="smod-knowledge">知识库</label></div></div>
|
||||||
|
<div class="col-md-3 col-6"><div class="form-check"><input class="form-check-input sys-module-cb" type="checkbox" value="workorders" id="smod-workorders" checked><label class="form-check-label" for="smod-workorders">工单管理</label></div></div>
|
||||||
|
<div class="col-md-3 col-6"><div class="form-check"><input class="form-check-input sys-module-cb" type="checkbox" value="conversation-history" id="smod-conversation-history" checked><label class="form-check-label" for="smod-conversation-history">对话历史</label></div></div>
|
||||||
|
<div class="col-md-3 col-6"><div class="form-check"><input class="form-check-input sys-module-cb" type="checkbox" value="alerts" id="smod-alerts" checked><label class="form-check-label" for="smod-alerts">预警管理</label></div></div>
|
||||||
|
<div class="col-md-3 col-6"><div class="form-check"><input class="form-check-input sys-module-cb" type="checkbox" value="feishu-sync" id="smod-feishu-sync" checked><label class="form-check-label" for="smod-feishu-sync">飞书同步</label></div></div>
|
||||||
|
<div class="col-md-3 col-6"><div class="form-check"><input class="form-check-input sys-module-cb" type="checkbox" value="agent" id="smod-agent" checked><label class="form-check-label" for="smod-agent">Agent管理</label></div></div>
|
||||||
|
<div class="col-md-3 col-6"><div class="form-check"><input class="form-check-input sys-module-cb" type="checkbox" value="token-monitor" id="smod-token-monitor" checked><label class="form-check-label" for="smod-token-monitor">Token监控</label></div></div>
|
||||||
|
<div class="col-md-3 col-6"><div class="form-check"><input class="form-check-input sys-module-cb" type="checkbox" value="ai-monitor" id="smod-ai-monitor" checked><label class="form-check-label" for="smod-ai-monitor">AI监控</label></div></div>
|
||||||
|
<div class="col-md-3 col-6"><div class="form-check"><input class="form-check-input sys-module-cb" type="checkbox" value="analytics" id="smod-analytics" checked><label class="form-check-label" for="smod-analytics">数据分析</label></div></div>
|
||||||
|
<div class="col-md-3 col-6"><div class="form-check"><input class="form-check-input sys-module-cb" type="checkbox" value="system-optimizer" id="smod-system-optimizer" checked><label class="form-check-label" for="smod-system-optimizer">系统优化</label></div></div>
|
||||||
|
<div class="col-md-3 col-6"><div class="form-check"><input class="form-check-input sys-module-cb" type="checkbox" value="settings" id="smod-settings" checked><label class="form-check-label" for="smod-settings">系统设置</label></div></div>
|
||||||
|
<div class="col-md-3 col-6"><div class="form-check"><input class="form-check-input sys-module-cb" type="checkbox" value="tenant-management" id="smod-tenant-management" checked><label class="form-check-label" for="smod-tenant-management">租户管理</label></div></div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
<div id="tenant-management-tab" class="tab-content" style="display: none;">
|
<div id="tenant-management-tab" class="tab-content" style="display: none;">
|
||||||
<div class="row mb-4">
|
<div class="row mb-4">
|
||||||
<div class="col-md-8">
|
<div class="col-md-8">
|
||||||
@@ -2279,25 +2310,6 @@
|
|||||||
<textarea class="form-control" id="tenant-system-prompt" rows="3" placeholder="如:你是XX品牌的客服助手,专注于为用户提供XX相关的服务...(留空使用默认通用提示词)"></textarea>
|
<textarea class="form-control" id="tenant-system-prompt" rows="3" placeholder="如:你是XX品牌的客服助手,专注于为用户提供XX相关的服务...(留空使用默认通用提示词)"></textarea>
|
||||||
<div class="form-text">机器人回复时使用的角色设定,不同租户可以有不同的品牌定位</div>
|
<div class="form-text">机器人回复时使用的角色设定,不同租户可以有不同的品牌定位</div>
|
||||||
</div>
|
</div>
|
||||||
<hr>
|
|
||||||
<h6 class="text-muted">模块权限 <small class="text-muted">(取消勾选可隐藏对应功能)</small></h6>
|
|
||||||
<div class="mb-3" id="tenant-modules-checkboxes">
|
|
||||||
<div class="row">
|
|
||||||
<div class="col-6"><div class="form-check"><input class="form-check-input tenant-module-cb" type="checkbox" value="dashboard" id="mod-dashboard" checked><label class="form-check-label" for="mod-dashboard">仪表板</label></div></div>
|
|
||||||
<div class="col-6"><div class="form-check"><input class="form-check-input tenant-module-cb" type="checkbox" value="chat" id="mod-chat" checked><label class="form-check-label" for="mod-chat">智能对话</label></div></div>
|
|
||||||
<div class="col-6"><div class="form-check"><input class="form-check-input tenant-module-cb" type="checkbox" value="knowledge" id="mod-knowledge" checked><label class="form-check-label" for="mod-knowledge">知识库</label></div></div>
|
|
||||||
<div class="col-6"><div class="form-check"><input class="form-check-input tenant-module-cb" type="checkbox" value="workorders" id="mod-workorders" checked><label class="form-check-label" for="mod-workorders">工单管理</label></div></div>
|
|
||||||
<div class="col-6"><div class="form-check"><input class="form-check-input tenant-module-cb" type="checkbox" value="conversation-history" id="mod-conversation-history" checked><label class="form-check-label" for="mod-conversation-history">对话历史</label></div></div>
|
|
||||||
<div class="col-6"><div class="form-check"><input class="form-check-input tenant-module-cb" type="checkbox" value="alerts" id="mod-alerts" checked><label class="form-check-label" for="mod-alerts">预警管理</label></div></div>
|
|
||||||
<div class="col-6"><div class="form-check"><input class="form-check-input tenant-module-cb" type="checkbox" value="feishu-sync" id="mod-feishu-sync" checked><label class="form-check-label" for="mod-feishu-sync">飞书同步</label></div></div>
|
|
||||||
<div class="col-6"><div class="form-check"><input class="form-check-input tenant-module-cb" type="checkbox" value="agent" id="mod-agent" checked><label class="form-check-label" for="mod-agent">Agent管理</label></div></div>
|
|
||||||
<div class="col-6"><div class="form-check"><input class="form-check-input tenant-module-cb" type="checkbox" value="token-monitor" id="mod-token-monitor" checked><label class="form-check-label" for="mod-token-monitor">Token监控</label></div></div>
|
|
||||||
<div class="col-6"><div class="form-check"><input class="form-check-input tenant-module-cb" type="checkbox" value="ai-monitor" id="mod-ai-monitor" checked><label class="form-check-label" for="mod-ai-monitor">AI监控</label></div></div>
|
|
||||||
<div class="col-6"><div class="form-check"><input class="form-check-input tenant-module-cb" type="checkbox" value="analytics" id="mod-analytics" checked><label class="form-check-label" for="mod-analytics">数据分析</label></div></div>
|
|
||||||
<div class="col-6"><div class="form-check"><input class="form-check-input tenant-module-cb" type="checkbox" value="system-optimizer" id="mod-system-optimizer" checked><label class="form-check-label" for="mod-system-optimizer">系统优化</label></div></div>
|
|
||||||
<div class="col-6"><div class="form-check"><input class="form-check-input tenant-module-cb" type="checkbox" value="settings" id="mod-settings" checked><label class="form-check-label" for="mod-settings">系统设置</label></div></div>
|
|
||||||
<div class="col-6"><div class="form-check"><input class="form-check-input tenant-module-cb" type="checkbox" value="tenant-management" id="mod-tenant-management" checked><label class="form-check-label" for="mod-tenant-management">租户管理</label></div></div>
|
|
||||||
</div>
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="modal-footer">
|
<div class="modal-footer">
|
||||||
|
|||||||
@@ -160,11 +160,6 @@
|
|||||||
</button>
|
</button>
|
||||||
</form>
|
</form>
|
||||||
|
|
||||||
<!-- 提示信息 -->
|
|
||||||
<div class="text-center mt-4" style="color: #6c757d; font-size: 13px;">
|
|
||||||
<p class="mb-0">默认账号: <strong>admin</strong></p>
|
|
||||||
<p>默认密码: <strong>admin123</strong></p>
|
|
||||||
</div>
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user