Gem2a / app /static /js /main.js
misonL's picture
Fallback to transparent GIF for failed image proxy
224e82b
Raw
History Blame Contribute Delete
2.37 kB
// app/static/js/main.js - 主入口文件
import { checkAuthAndRedirect, setupLoginForm, setupLogoutButton } from './auth.js';
import { setupSendButton, setupPasteImage } from './chat.js';
import { loadMetrics } from './metrics.js';
import { loadRecords } from './records.js';
import { initTabbedSessionManagement, loadSessions } from './session.js';
import { AUTH_TOKEN_STORAGE_KEY } from './constants.js';
document.addEventListener('DOMContentLoaded', async () => {
const loginForm = document.getElementById('login-form');
const authTokenInput = document.getElementById('api-key');
const errorMessage = document.getElementById('error-message');
const logoutButton = document.getElementById('logout-button');
const chatWindow = document.getElementById('chat-window');
const userInput = document.getElementById('user-input');
const imageUpload = document.getElementById('image-upload');
const sendButton = document.getElementById('send-button');
const callRecordsTableBody = document.querySelector('#call-records-table tbody');
const modelSelect = document.getElementById('model-select');
// 检查认证状态并重定向
checkAuthAndRedirect();
// 设置登录表单和登出按钮
setupLoginForm(loginForm, authTokenInput, errorMessage);
setupLogoutButton(logoutButton);
// 调试信息:确认登录表单设置完成 (已移除,避免重复日志)
// 如果在主页面,初始化其他功能
// 确保在主页面或 /static/index.html 页面初始化会话管理UI
if (window.location.pathname === '/' || window.location.pathname === '/static/index.html') {
// 初始化会话管理UI并确保创建默认会话
await initTabbedSessionManagement(chatWindow);
// 设置发送消息和粘贴图片功能
setupSendButton(sendButton, userInput, imageUpload, modelSelect);
setupPasteImage(userInput, imageUpload);
// 加载会话列表(在初始化UI后调用)
loadSessions();
// 加载服务指标和调用记录
loadMetrics();
loadRecords(callRecordsTableBody);
// 定时刷新指标和记录
setInterval(loadMetrics, 15000); // 每15秒刷新一次指标
setInterval(() => loadRecords(callRecordsTableBody), 30000); // 每30秒刷新一次记录
}
});