revert 解决冲突
This commit is contained in:
2025-11-27 15:38:24 +08:00
parent 3da220526b
commit 64abd3d4ab
28 changed files with 1059 additions and 705 deletions

View File

@@ -199,10 +199,14 @@ const avatarUrl = ref('')
*/
const userInfo = ref<any>({}) // 用户信息
const getData = async () => {
const res = await getUserInfo()
if (res.result) {
userStore.setUserInfo(res.result)
userInfo.value = res.result
try {
const res = await getUserInfo()
if (res.result) {
userStore.setUserInfo(res.result)
userInfo.value = res.result
}
} catch (error) {
console.error('获取用户信息失败:', error)
}
}
@@ -320,12 +324,16 @@ const sendCode = async () => {
return
}
await sendEmailCode(editForm.value.email)
uni.showToast({
title: t('user.sendCodeSuccess'),
icon: 'none'
})
startCountdown()
try {
await sendEmailCode(editForm.value.email)
uni.showToast({
title: t('user.sendCodeSuccess'),
icon: 'none'
})
startCountdown()
} catch (error) {
console.error('发送验证码失败:', error)
}
}
/**
@@ -390,88 +398,92 @@ const checkPasswordStrength = () => {
const handleSubmit = async () => {
const key = currentField.value?.key
// 构建更新数据对象
let updateData: any = Object.assign({}, userInfo.value)
try {
// 构建更新数据对象
let updateData: any = Object.assign({}, userInfo.value)
switch (key) {
case 'email':
// 更新邮箱
if (!editForm.value.email || !editForm.value.code) {
uni.showToast({
title: t('user.pleaseInputCode'),
icon: 'none'
})
return
}
await updateEmail(userInfo.value.id, editForm.value.email, editForm.value.code)
break
case 'password':
// 更新密码
if (!passwordOk.value) {
uni.showToast({
title: passwordNote.value,
icon: 'none'
})
return
}
if (editForm.value.password !== editForm.value.confirmPassword) {
uni.showToast({
title: t('user.passwordNotMatch'),
icon: 'none'
})
return
}
await updatePassword(userInfo.value.id, editForm.value.password)
break
case 'avatar':
// 更新头像
console.log('avatarUrl.value:', avatarUrl.value)
if (!avatarUrl.value) {
uni.showToast({
title: t('common.pleaseSelect') + t('user.avatar'),
icon: 'none'
})
return
}
// 如果是新上传的图片,需要先上传
updateData.avatar = avatarUrl.value
await updateUserInfo(updateData)
break
case 'sex':
// 更新性别
updateData.sex = editValue.value
await updateUserInfo(updateData)
break
default:
// 更新其他字段
if (!editValue.value) {
uni.showToast({
title: getPlaceholder(key),
icon: 'none'
})
return
}
updateData[key] = editValue.value
await updateUserInfo(updateData)
break
switch (key) {
case 'email':
// 更新邮箱
if (!editForm.value.email || !editForm.value.code) {
uni.showToast({
title: t('user.pleaseInputCode'),
icon: 'none'
})
return
}
await updateEmail(userInfo.value.id, editForm.value.email, editForm.value.code)
break
case 'password':
// 更新密码
if (!passwordOk.value) {
uni.showToast({
title: passwordNote.value,
icon: 'none'
})
return
}
if (editForm.value.password !== editForm.value.confirmPassword) {
uni.showToast({
title: t('user.passwordNotMatch'),
icon: 'none'
})
return
}
await updatePassword(userInfo.value.id, editForm.value.password)
break
case 'avatar':
// 更新头像
console.log('avatarUrl.value:', avatarUrl.value)
if (!avatarUrl.value) {
uni.showToast({
title: t('common.pleaseSelect') + t('user.avatar'),
icon: 'none'
})
return
}
// 如果是新上传的图片,需要先上传
updateData.avatar = avatarUrl.value
await updateUserInfo(updateData)
break
case 'sex':
// 更新性别
updateData.sex = editValue.value
await updateUserInfo(updateData)
break
default:
// 更新其他字段
if (!editValue.value) {
uni.showToast({
title: getPlaceholder(key),
icon: 'none'
})
return
}
updateData[key] = editValue.value
await updateUserInfo(updateData)
break
}
uni.showToast({
title: t('user.updateSuccess'),
icon: 'success'
})
closeModal()
// 刷新数据
setTimeout(() => {
getData()
}, 500)
} catch (error) {
console.error('更新失败:', error)
}
uni.showToast({
title: t('user.updateSuccess'),
icon: 'success'
})
closeModal()
// 刷新数据
setTimeout(() => {
getData()
}, 500)
}
/**