优化登录界面

This commit is contained in:
zhinianboke 2025-08-15 16:19:44 +08:00
parent a9302527f8
commit e49f45ba6e
5 changed files with 179 additions and 2 deletions

View File

@ -407,6 +407,7 @@ class DBManager:
INSERT OR IGNORE INTO system_settings (key, value, description) VALUES
('theme_color', 'blue', '主题颜色'),
('registration_enabled', 'true', '是否开启用户注册'),
('show_default_login_info', 'true', '是否显示默认登录信息'),
('smtp_server', '', 'SMTP服务器地址'),
('smtp_port', '587', 'SMTP端口'),
('smtp_user', '', 'SMTP登录用户名发件邮箱'),

View File

@ -1502,10 +1502,35 @@ def get_registration_status():
return {'enabled': True, 'message': '注册功能已开启'} # 出错时默认开启
@app.get('/login-info-status')
def get_login_info_status():
"""获取默认登录信息显示状态(公开接口,无需认证)"""
from db_manager import db_manager
try:
enabled_str = db_manager.get_system_setting('show_default_login_info')
logger.debug(f"从数据库获取的登录信息显示设置值: '{enabled_str}'")
# 如果设置不存在,默认为开启
if enabled_str is None:
enabled_bool = True
else:
enabled_bool = enabled_str == 'true'
return {"enabled": enabled_bool}
except Exception as e:
logger.error(f"获取登录信息显示状态失败: {e}")
# 出错时默认为开启
return {"enabled": True}
class RegistrationSettingUpdate(BaseModel):
enabled: bool
class LoginInfoSettingUpdate(BaseModel):
enabled: bool
@app.put('/registration-settings')
def update_registration_settings(setting_data: RegistrationSettingUpdate, admin_user: Dict[str, Any] = Depends(require_admin)):
"""更新注册开关设置(仅管理员)"""
@ -1532,6 +1557,31 @@ def update_registration_settings(setting_data: RegistrationSettingUpdate, admin_
logger.error(f"更新注册设置失败: {e}")
raise HTTPException(status_code=500, detail=str(e))
@app.put('/login-info-settings')
def update_login_info_settings(setting_data: LoginInfoSettingUpdate, admin_user: Dict[str, Any] = Depends(require_admin)):
"""更新默认登录信息显示设置(仅管理员)"""
from db_manager import db_manager
try:
enabled = setting_data.enabled
success = db_manager.set_system_setting(
'show_default_login_info',
'true' if enabled else 'false',
'是否显示默认登录信息'
)
if success:
log_with_user('info', f"更新登录信息显示设置: {'开启' if enabled else '关闭'}", admin_user)
return {
'success': True,
'enabled': enabled,
'message': f"默认登录信息显示已{'开启' if enabled else '关闭'}"
}
else:
raise HTTPException(status_code=500, detail='更新登录信息显示设置失败')
except HTTPException:
raise
except Exception as e:
logger.error(f"更新登录信息显示设置失败: {e}")
raise HTTPException(status_code=500, detail=str(e))

View File

@ -1568,6 +1568,39 @@
</div>
</div>
</div>
<!-- 默认登录信息设置 -->
<div class="col-md-6">
<div class="card">
<div class="card-header">
<i class="bi bi-info-circle me-2"></i>登录信息设置
<span class="badge bg-warning ms-2">管理员专用</span>
</div>
<div class="card-body">
<div class="mb-3">
<div class="form-check form-switch">
<input class="form-check-input" type="checkbox" id="showDefaultLoginInfo">
<label class="form-check-label" for="showDefaultLoginInfo">
<strong>显示默认登录信息</strong>
</label>
</div>
<div class="form-text">
<i class="bi bi-info-circle me-1"></i>
开启后,登录页面将显示默认的用户名和密码信息,方便用户快速登录
</div>
</div>
<button type="button" class="btn btn-primary" onclick="updateLoginInfoSettings()">
<i class="bi bi-check-circle me-1"></i>保存设置
</button>
<div id="loginInfoStatus" class="mt-3" style="display: none;">
<div class="alert alert-info mb-0">
<i class="bi bi-info-circle me-2"></i>
<span id="loginInfoStatusText"></span>
</div>
</div>
</div>
</div>
</div>
</div>
<!-- 外发配置 (仅管理员可见) -->

View File

@ -7674,9 +7674,10 @@ async function loadSystemSettings() {
outgoingConfigs.style.display = isAdmin ? 'block' : 'none';
}
// 如果是管理员,加载注册设置和外发配置
// 如果是管理员,加载注册设置、登录信息设置和外发配置
if (isAdmin) {
await loadRegistrationSettings();
await loadLoginInfoSettings();
await loadOutgoingConfigs();
}
}
@ -7897,6 +7898,76 @@ async function updateRegistrationSettings() {
}
}
// 加载默认登录信息设置
async function loadLoginInfoSettings() {
try {
const response = await fetch('/system-settings', {
headers: {
'Authorization': `Bearer ${authToken}`
}
});
if (response.ok) {
const settings = await response.json();
const checkbox = document.getElementById('showDefaultLoginInfo');
if (checkbox && settings.show_default_login_info !== undefined) {
checkbox.checked = settings.show_default_login_info === 'true';
}
}
} catch (error) {
console.error('加载登录信息设置失败:', error);
showToast('加载登录信息设置失败', 'danger');
}
}
// 更新默认登录信息设置
async function updateLoginInfoSettings() {
const checkbox = document.getElementById('showDefaultLoginInfo');
const statusDiv = document.getElementById('loginInfoStatus');
const statusText = document.getElementById('loginInfoStatusText');
if (!checkbox) return;
const enabled = checkbox.checked;
try {
const response = await fetch('/login-info-settings', {
method: 'PUT',
headers: {
'Content-Type': 'application/json',
'Authorization': `Bearer ${authToken}`
},
body: JSON.stringify({
enabled: enabled
})
});
if (response.ok) {
const data = await response.json();
const message = enabled ? '默认登录信息显示已开启' : '默认登录信息显示已关闭';
showToast(message, 'success');
// 显示状态信息
if (statusDiv && statusText) {
statusText.textContent = message;
statusDiv.style.display = 'block';
// 3秒后隐藏状态信息
setTimeout(() => {
statusDiv.style.display = 'none';
}, 3000);
}
} else {
const errorData = await response.json();
showToast(`更新失败: ${errorData.detail || '未知错误'}`, 'danger');
}
} catch (error) {
console.error('更新登录信息设置失败:', error);
showToast('更新登录信息设置失败', 'danger');
}
}
// ================================
// 订单管理功能
// ================================

View File

@ -226,7 +226,7 @@
</div>
<!-- 默认账号提示 -->
<div class="mt-4 p-3 bg-light rounded-3">
<div id="defaultLoginInfo" class="mt-4 p-3 bg-light rounded-3">
<div class="text-center">
<small class="text-muted">
<i class="bi bi-info-circle me-1"></i>
@ -659,11 +659,33 @@
}
}
// 检查默认登录信息显示状态
async function checkLoginInfoStatus() {
try {
const response = await fetch('/login-info-status');
const result = await response.json();
const defaultLoginInfo = document.getElementById('defaultLoginInfo');
if (result.enabled) {
defaultLoginInfo.style.display = 'block';
} else {
defaultLoginInfo.style.display = 'none';
}
} catch (error) {
console.error('检查登录信息显示状态失败:', error);
// 出错时默认显示
document.getElementById('defaultLoginInfo').style.display = 'block';
}
}
// 事件监听器
document.addEventListener('DOMContentLoaded', function() {
// 检查注册状态
checkRegistrationStatus();
// 检查默认登录信息显示状态
checkLoginInfoStatus();
// 登录方式切换
document.querySelectorAll('input[name="loginType"]').forEach(radio => {
radio.addEventListener('change', switchLoginType);