Phase C3: Site Settings Refactoring with horizontal sub-tabs and Logo upload

- Replaced vertical card layout with 5 horizontal tabs: 基础设置/Logo设置/邮件配置/短信配置/注册设置
- Added Logo upload tab with drag-drop preview and file upload
- Added Registration Settings tab (allow_register, email/phone verify, default role, welcome message)
- Added logo upload backend endpoint (POST /admin/settings/logo/upload)
- Added modal sub-component CSS classes for dark theme
- Fixed all hardcoded white backgrounds for dark theme
- Added uploadLogo method to adminAPI
This commit is contained in:
qyyfw committed 2026-07-05 19:28:49 +08:00
1 parent 35a8d727e0
commit 5828728f00
4 files changed
+682 -223

No files matched your search

+71
View File
@@ -267,6 +267,77 @@ async def update_sms_config(
return {"message": "短信配置已更新"}
# ============================================================
# Logo 上传
# ============================================================
from fastapi import UploadFile, File
@router.post("/logo/upload")
async def upload_logo(
file: UploadFile = File(...),
admin_user=Depends(get_current_admin),
db: Session = Depends(get_db),
):
"""上传平台Logo,保存到本地data目录,返回访问URL"""
import os as _os
import shutil as _shutil
# Validate file type
allowed_types = ['image/png', 'image/jpeg', 'image/svg+xml', 'image/webp']
if file.content_type not in allowed_types:
raise HTTPException(status_code=400, detail=f"不支持的文件类型: {file.content_type},仅支持 PNG/JPG/SVG/WEBP")
# Validate size (max 2MB)
contents = await file.read()
if len(contents) > 2 * 1024 * 1024:
raise HTTPException(status_code=400, detail="文件大小不能超过 2MB")
# Save to /app/data/uploads/logos/
upload_dir = "/app/data/uploads/logos"
_os.makedirs(upload_dir, exist_ok=True)
# Generate unique filename
ext = file.filename.split('.')[-1] if '.' in (file.filename or '') else 'png'
filename = f"{uuid.uuid4()}.{ext}"
filepath = _os.path.join(upload_dir, filename)
with open(filepath, 'wb') as f:
f.write(contents)
# Build URL
logo_url = f"/data/uploads/logos/{filename}"
# Update site setting
existing = db.query(SiteSetting).filter(SiteSetting.key == "logo").first()
if existing:
existing.value = logo_url
existing.updated_at = datetime.now()
else:
new_setting = SiteSetting(
id=str(uuid.uuid4()),
key="logo",
value=logo_url,
)
db.add(new_setting)
db.commit()
LogService.log_audit(
admin_id=admin_user.id,
admin_name=admin_user.username,
action="upload_logo",
target_type="site_settings",
detail=f"上传Logo: {filename}",
)
return {
"code": 0,
"data": {"url": logo_url, "filename": filename},
"message": "Logo 上传成功",
}
# ============================================================
# 邮件测试
# ============================================================