减少不必要模块,增加中英文切换
This commit is contained in:
@@ -1,5 +1,137 @@
|
||||
// TSP智能助手综合管理平台前端脚本
|
||||
|
||||
// 多语言支持
|
||||
const translations = {
|
||||
zh: {
|
||||
// 导航栏
|
||||
'nav-title': 'TSP智能助手',
|
||||
'nav-health-checking': '检查中...',
|
||||
'nav-health-normal': '系统正常',
|
||||
'nav-health-warning': '系统警告',
|
||||
'nav-health-error': '系统错误',
|
||||
|
||||
// 侧边栏
|
||||
'sidebar-dashboard': '仪表板',
|
||||
'sidebar-workorders': '工单管理',
|
||||
'sidebar-conversations': '智能对话',
|
||||
'sidebar-agent': 'Agent管理',
|
||||
'sidebar-alerts': '预警管理',
|
||||
'sidebar-knowledge': '知识库',
|
||||
'sidebar-analytics': '数据分析',
|
||||
'sidebar-feishu-sync': '飞书同步',
|
||||
'sidebar-system': '系统设置',
|
||||
|
||||
// 设置页面
|
||||
'settings-title': '系统设置',
|
||||
'settings-basic': '基础设置',
|
||||
'settings-system-info': '系统信息',
|
||||
'settings-log-config': '日志配置',
|
||||
'settings-current-port': '当前服务端口',
|
||||
'settings-websocket-port': 'WebSocket端口',
|
||||
'settings-log-level': '日志级别',
|
||||
'settings-save': '保存设置',
|
||||
'settings-save-success': '设置保存成功',
|
||||
'settings-save-failed': '保存设置失败',
|
||||
'settings-port-note': '服务端口配置需要在配置文件中修改,前端页面仅显示当前状态。',
|
||||
'settings-log-note': '调整系统日志的详细程度'
|
||||
},
|
||||
en: {
|
||||
// Navigation
|
||||
'nav-title': 'TSP Intelligent Assistant',
|
||||
'nav-health-checking': 'Checking...',
|
||||
'nav-health-normal': 'System Normal',
|
||||
'nav-health-warning': 'System Warning',
|
||||
'nav-health-error': 'System Error',
|
||||
|
||||
// Sidebar
|
||||
'sidebar-dashboard': 'Dashboard',
|
||||
'sidebar-workorders': 'Work Orders',
|
||||
'sidebar-conversations': 'Smart Chat',
|
||||
'sidebar-agent': 'Agent Management',
|
||||
'sidebar-alerts': 'Alert Management',
|
||||
'sidebar-knowledge': 'Knowledge Base',
|
||||
'sidebar-analytics': 'Analytics',
|
||||
'sidebar-feishu-sync': 'Feishu Sync',
|
||||
'sidebar-system': 'System Settings',
|
||||
|
||||
// Settings page
|
||||
'settings-title': 'System Settings',
|
||||
'settings-basic': 'Basic Settings',
|
||||
'settings-system-info': 'System Information',
|
||||
'settings-log-config': 'Log Configuration',
|
||||
'settings-current-port': 'Current Service Port',
|
||||
'settings-websocket-port': 'WebSocket Port',
|
||||
'settings-log-level': 'Log Level',
|
||||
'settings-save': 'Save Settings',
|
||||
'settings-save-success': 'Settings saved successfully',
|
||||
'settings-save-failed': 'Failed to save settings',
|
||||
'settings-port-note': 'Service port configuration needs to be modified in configuration files. Frontend only displays current status.',
|
||||
'settings-log-note': 'Adjust the detail level of system logs'
|
||||
}
|
||||
};
|
||||
|
||||
// 全局语言切换函数
|
||||
function switchLanguage(lang) {
|
||||
localStorage.setItem('preferred-language', lang);
|
||||
document.documentElement.lang = lang;
|
||||
|
||||
// 更新按钮状态
|
||||
document.getElementById('lang-zh').classList.toggle('active', lang === 'zh');
|
||||
document.getElementById('lang-en').classList.toggle('active', lang === 'en');
|
||||
|
||||
// 更新页面文本
|
||||
updatePageLanguage(lang);
|
||||
}
|
||||
|
||||
// 更新页面语言
|
||||
function updatePageLanguage(lang) {
|
||||
const t = translations[lang];
|
||||
if (!t) return;
|
||||
|
||||
// 更新导航栏
|
||||
document.querySelector('.navbar-brand').innerHTML = `<i class="fas fa-robot me-2"></i>${t['nav-title']}`;
|
||||
|
||||
// 更新侧边栏
|
||||
const sidebarItems = [
|
||||
{ selector: '[data-i18n="sidebar-dashboard"]', key: 'sidebar-dashboard' },
|
||||
{ selector: '[data-i18n="sidebar-conversations"]', key: 'sidebar-conversations' },
|
||||
{ selector: '[data-i18n="sidebar-agent"]', key: 'sidebar-agent' },
|
||||
{ selector: '[data-i18n="sidebar-alerts"]', key: 'sidebar-alerts' },
|
||||
{ selector: '[data-i18n="sidebar-knowledge"]', key: 'sidebar-knowledge' },
|
||||
{ selector: '[data-i18n="sidebar-workorders"]', key: 'sidebar-workorders' },
|
||||
{ selector: '[data-i18n="sidebar-feishu-sync"]', key: 'sidebar-feishu-sync' },
|
||||
{ selector: '[data-i18n="sidebar-system"]', key: 'sidebar-system' }
|
||||
];
|
||||
|
||||
sidebarItems.forEach(item => {
|
||||
const element = document.querySelector(item.selector);
|
||||
if (element) {
|
||||
element.textContent = t[item.key];
|
||||
}
|
||||
});
|
||||
|
||||
// 更新设置页面
|
||||
const settingsElements = [
|
||||
{ selector: '[data-i18n="settings-title"]', key: 'settings-title' },
|
||||
{ selector: '[data-i18n="settings-basic"]', key: 'settings-basic' },
|
||||
{ selector: '[data-i18n="settings-system-info"]', key: 'settings-system-info' },
|
||||
{ selector: '[data-i18n="settings-log-config"]', key: 'settings-log-config' },
|
||||
{ selector: '[data-i18n="settings-current-port"]', key: 'settings-current-port' },
|
||||
{ selector: '[data-i18n="settings-websocket-port"]', key: 'settings-websocket-port' },
|
||||
{ selector: '[data-i18n="settings-log-level"]', key: 'settings-log-level' },
|
||||
{ selector: '[data-i18n="settings-save"]', key: 'settings-save' },
|
||||
{ selector: '[data-i18n="settings-port-note"]', key: 'settings-port-note' },
|
||||
{ selector: '[data-i18n="settings-log-note"]', key: 'settings-log-note' }
|
||||
];
|
||||
|
||||
settingsElements.forEach(item => {
|
||||
const element = document.querySelector(item.selector);
|
||||
if (element) {
|
||||
element.textContent = t[item.key];
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
class TSPDashboard {
|
||||
constructor() {
|
||||
this.currentTab = 'dashboard';
|
||||
@@ -8,6 +140,7 @@ class TSPDashboard {
|
||||
this.websocket = null;
|
||||
this.sessionId = null;
|
||||
this.isAgentMode = true;
|
||||
this.currentLanguage = localStorage.getItem('preferred-language') || 'zh';
|
||||
|
||||
// 优化:添加前端缓存
|
||||
this.cache = new Map();
|
||||
@@ -15,12 +148,21 @@ class TSPDashboard {
|
||||
|
||||
this.init();
|
||||
this.restorePageState();
|
||||
this.initLanguage();
|
||||
|
||||
// 添加页面卸载时的清理逻辑
|
||||
window.addEventListener('beforeunload', () => {
|
||||
this.destroyAllCharts();
|
||||
});
|
||||
}
|
||||
|
||||
initLanguage() {
|
||||
// 初始化语言设置
|
||||
document.documentElement.lang = this.currentLanguage;
|
||||
document.getElementById('lang-zh').classList.toggle('active', this.currentLanguage === 'zh');
|
||||
document.getElementById('lang-en').classList.toggle('active', this.currentLanguage === 'en');
|
||||
updatePageLanguage(this.currentLanguage);
|
||||
}
|
||||
|
||||
async generateAISuggestion(workorderId) {
|
||||
const button = document.querySelector(`button[onclick="dashboard.generateAISuggestion(${workorderId})"]`);
|
||||
|
||||
Reference in New Issue
Block a user