fix: 设置页面加载用户信息,支持本地存储备用
This commit is contained in:
parent
8fbd524a81
commit
57e2eec9a0
|
|
@ -41,29 +41,34 @@ def update_current_user(
|
|||
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:
|
||||
current_user.username = username
|
||||
user.f01_01_name = username
|
||||
if email:
|
||||
current_user.email = email
|
||||
user.email = email
|
||||
if phone:
|
||||
current_user.phone = phone
|
||||
user.phone = phone
|
||||
if avatar:
|
||||
current_user.avatar = avatar
|
||||
user.avatar = avatar
|
||||
if address:
|
||||
current_user.address = address
|
||||
user.address = address
|
||||
if bio:
|
||||
current_user.bio = bio
|
||||
user.bio = bio
|
||||
|
||||
db.commit()
|
||||
db.refresh(current_user)
|
||||
db.refresh(user)
|
||||
|
||||
return {
|
||||
"id": current_user.f99_90_id,
|
||||
"username": current_user.f01_01_name,
|
||||
"email": current_user.email,
|
||||
"phone": current_user.phone,
|
||||
"role": current_user.role
|
||||
"id": user.f99_90_id,
|
||||
"username": user.f01_01_name,
|
||||
"email": user.email,
|
||||
"phone": user.phone,
|
||||
"role": user.role
|
||||
}
|
||||
|
||||
# ============ 管理员用户管理 ============
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@
|
|||
# Version Configuration for Zodiac Collection Management System
|
||||
|
||||
# 当前版本号 (语义化版本:主版本。次版本.修订版)
|
||||
VERSION=1.0.9
|
||||
VERSION=1.1.0
|
||||
|
||||
# 版本代号 (可选)
|
||||
VERSION_CODENAME="新生"
|
||||
|
|
|
|||
|
|
@ -34,15 +34,33 @@ export default function Settings() {
|
|||
})
|
||||
if (res.ok) {
|
||||
const data = await res.json()
|
||||
console.log('用户信息:', data)
|
||||
setForm({
|
||||
username: data.username || '',
|
||||
email: data.email || '',
|
||||
phone: data.phone || '',
|
||||
bio: data.bio || ''
|
||||
})
|
||||
} else {
|
||||
console.error('获取用户信息失败:', res.status)
|
||||
}
|
||||
} 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 {
|
||||
setLoading(false)
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue