Compare commits

...

4 Commits

2 changed files with 70 additions and 11 deletions

View File

@@ -276,6 +276,20 @@ def init_db():
]
for key, value, desc in default_configs:
cursor.execute('INSERT INTO system_configs (key, value, description) VALUES (?, ?, ?)', (key, value, desc))
else:
# 检查并添加缺失的配置项(兼容旧数据库)
default_configs = [
('app_developer', 'OpenClaw Team', '开发者'),
('app_update_date', '2026-04-27', '更新日期'),
('app_technology', '智谱 GLM-4.5-Air 大模型', '技术基础'),
('app_description', '提供智能对话、多种智能体服务', '应用简介'),
('privacy_policy_url', '', '隐私政策链接'),
('user_agreement_url', '', '用户协议链接'),
]
for key, value, desc in default_configs:
cursor.execute('SELECT COUNT(*) FROM system_configs WHERE key=?', (key,))
if cursor.fetchone()[0] == 0:
cursor.execute('INSERT INTO system_configs (key, value, description) VALUES (?, ?, ?)', (key, value, desc))
# 初始化管理员账户
cursor.execute('SELECT COUNT(*) FROM admin_users')
@@ -487,8 +501,9 @@ def get_users():
@app.route('/api/admin/users/<int:id>', methods=['GET'])
@app.route('/api/user/<int:id>', methods=['GET'])
def get_user(id):
"""获取单个用户"""
"""获取单个用户信息"""
conn = get_db()
cursor = conn.cursor()
cursor.execute('SELECT * FROM users WHERE id = ?', (id,))

View File

@@ -124,6 +124,19 @@ async function loadBackendConfig() {
// 不加载默认启用的工具,所有工具默认未启用
// 将后台系统配置赋值到 CONFIG
if (backendConfig.system) {
CONFIG.system = backendConfig.system;
}
// 将后台 LLM 配置赋值到 CONFIG
if (backendConfig.llm) {
CONFIG.apiUrl = backendConfig.llm.api_url;
CONFIG.apiKey = backendConfig.llm.api_key;
CONFIG.model = backendConfig.llm.model;
CONFIG.maxTokens = backendConfig.llm.max_tokens || 2048;
}
updateAgentsDisplay();
console.log('后台配置已加载', backendConfig);
} catch (e) {
@@ -308,15 +321,41 @@ document.addEventListener('DOMContentLoaded', async () => {
// 初始化 appContainer
appContainer = document.getElementById('app');
// 加载后台配置(包含 LLM、智能体等
await loadBackendConfig();
// 加载用户登录状态(优先检查)
const savedUser = localStorage.getItem('currentUser');
if (savedUser) {
currentUser = JSON.parse(savedUser);
}
// 如果用户已登录且有ID从 backend 加载对话数据
// 如果用户已登录且有ID从 backend 加载最新用户信息和对话数据
if (currentUser && currentUser.id) {
try {
// 从后台获取最新用户信息(包括头像)
const userRes = await fetch(`/api/user/${currentUser.id}`);
if (userRes.ok) {
const userData = await userRes.json();
if (userData && userData.id) {
// 更新 currentUser 为后台最新数据
currentUser = {
id: userData.id,
username: userData.username,
phone: userData.phone || '',
email: userData.email || '',
avatar: userData.avatar || '👤',
signature: userData.signature || '',
gender: userData.gender || '',
age: userData.age || '',
region: userData.region || '',
registeredAt: Date.now()
};
saveCurrentUser();
}
}
// 从 backend 加载对话数据
const res = await fetch(`/api/user/${currentUser.id}/conversations`);
const data = await res.json();
if (Array.isArray(data) && data.length > 0) {
@@ -424,13 +463,8 @@ document.addEventListener('DOMContentLoaded', async () => {
currentPage = savedPage;
}
// 加载后台配置并显示主页
loadBackendConfig().then(() => {
showMainPage();
}).catch(() => {
// 即使加载失败也显示主页
showMainPage();
});
// 显示主页
showMainPage();
});
// 根据用户配置更新显示的智能体
@@ -2613,7 +2647,12 @@ function showAboutPage() {
const privacyPolicyBtn = document.getElementById('privacyPolicyBtn');
if (privacyPolicyBtn) {
privacyPolicyBtn.addEventListener('click', () => {
showToast('隐私政策页面待完善');
const privacyUrl = CONFIG?.system?.privacyPolicyUrl;
if (privacyUrl) {
window.open(privacyUrl, '_blank');
} else {
showToast('隐私政策链接未配置');
}
});
}
@@ -2621,7 +2660,12 @@ function showAboutPage() {
const userAgreementBtn = document.getElementById('userAgreementBtn');
if (userAgreementBtn) {
userAgreementBtn.addEventListener('click', () => {
showToast('用户协议页面待完善');
const agreementUrl = CONFIG?.system?.userAgreementUrl;
if (agreementUrl) {
window.open(agreementUrl, '_blank');
} else {
showToast('用户协议链接未配置');
}
});
}
}