fix: 设置页面加载用户信息,支持本地存储备用

This commit is contained in:
菜鸟生产 2026-03-18 13:10:45 +08:00
parent 8fbd524a81
commit 57e2eec9a0
3 changed files with 37 additions and 14 deletions

View File

@ -41,29 +41,34 @@ def update_current_user(
db: Session = Depends(get_db) db: Session = Depends(get_db)
): ):
"""更新当前用户信息""" """更新当前用户信息"""
# 通过user_id重新获取用户确保在当前session中
user = db.query(User).filter(User.f99_90_id == current_user.f99_90_id).first()
if not user:
raise HTTPException(status_code=404, detail="用户不存在")
# 更新字段 # 更新字段
if username: if username:
current_user.username = username user.f01_01_name = username
if email: if email:
current_user.email = email user.email = email
if phone: if phone:
current_user.phone = phone user.phone = phone
if avatar: if avatar:
current_user.avatar = avatar user.avatar = avatar
if address: if address:
current_user.address = address user.address = address
if bio: if bio:
current_user.bio = bio user.bio = bio
db.commit() db.commit()
db.refresh(current_user) db.refresh(user)
return { return {
"id": current_user.f99_90_id, "id": user.f99_90_id,
"username": current_user.f01_01_name, "username": user.f01_01_name,
"email": current_user.email, "email": user.email,
"phone": current_user.phone, "phone": user.phone,
"role": current_user.role "role": user.role
} }
# ============ 管理员用户管理 ============ # ============ 管理员用户管理 ============

View File

@ -2,7 +2,7 @@
# Version Configuration for Zodiac Collection Management System # Version Configuration for Zodiac Collection Management System
# 当前版本号 (语义化版本:主版本。次版本.修订版) # 当前版本号 (语义化版本:主版本。次版本.修订版)
VERSION=1.0.9 VERSION=1.1.0
# 版本代号 (可选) # 版本代号 (可选)
VERSION_CODENAME="新生" VERSION_CODENAME="新生"

View File

@ -34,15 +34,33 @@ export default function Settings() {
}) })
if (res.ok) { if (res.ok) {
const data = await res.json() const data = await res.json()
console.log('用户信息:', data)
setForm({ setForm({
username: data.username || '', username: data.username || '',
email: data.email || '', email: data.email || '',
phone: data.phone || '', phone: data.phone || '',
bio: data.bio || '' bio: data.bio || ''
}) })
} else {
console.error('获取用户信息失败:', res.status)
} }
} catch (e) { } catch (e) {
setError('获取用户信息失败') console.error('获取用户信息异常:', e)
//
const userStr = localStorage.getItem('user')
if (userStr) {
try {
const user = JSON.parse(userStr)
setForm({
username: user.username || '',
email: user.email || '',
phone: user.phone || '',
bio: user.bio || ''
})
} catch (e2) {
setError('获取用户信息失败')
}
}
} finally { } finally {
setLoading(false) setLoading(false)
} }