修复:解决测试发现的问题
This commit is contained in:
@@ -27,7 +27,7 @@
|
||||
@click="editField(field)"
|
||||
>
|
||||
<view class="value-wrapper">
|
||||
<text v-if="userInfo[field.key]" class="value">
|
||||
<text v-if="userInfo[field.key] || userInfo[field.key] === 0" class="value">
|
||||
{{ formatValue(field, userInfo[field.key]) }}
|
||||
</text>
|
||||
<text v-else class="placeholder">{{ $t('user.notSet') }}</text>
|
||||
@@ -163,7 +163,8 @@ const fields = computed(() => [
|
||||
// 性别选项
|
||||
const sexOptions = [
|
||||
{ label: t('user.male'), value: 1 },
|
||||
{ label: t('user.female'), value: 2 }
|
||||
{ label: t('user.female'), value: 0 },
|
||||
{ label: t('user.secrecy'), value: 2 },
|
||||
]
|
||||
|
||||
// 编辑相关
|
||||
@@ -198,10 +199,8 @@ const avatarUrl = ref('')
|
||||
*/
|
||||
const userInfo = ref<any>({}) // 用户信息
|
||||
const getData = async () => {
|
||||
uni.showLoading()
|
||||
try {
|
||||
const res = await getUserInfo()
|
||||
uni.hideLoading()
|
||||
if (res.result) {
|
||||
userStore.setUserInfo(res.result)
|
||||
userInfo.value = res.result
|
||||
@@ -216,7 +215,22 @@ const getData = async () => {
|
||||
*/
|
||||
const formatValue = (field: any, value: any) => {
|
||||
if (field.key === 'sex') {
|
||||
return value === 1 ? t('user.male') : t('user.female')
|
||||
let result = null
|
||||
switch(value) {
|
||||
case 1:
|
||||
result = t('user.male')
|
||||
break
|
||||
case 0:
|
||||
result = t('user.female')
|
||||
break
|
||||
case 2:
|
||||
result = t('user.secrecy')
|
||||
break
|
||||
default:
|
||||
result = null
|
||||
break
|
||||
}
|
||||
return result
|
||||
}
|
||||
if (field.key === 'password') {
|
||||
return '******'
|
||||
@@ -385,8 +399,6 @@ const handleSubmit = async () => {
|
||||
const key = currentField.value?.key
|
||||
|
||||
try {
|
||||
uni.showLoading()
|
||||
|
||||
// 构建更新数据对象
|
||||
let updateData: any = Object.assign({}, userInfo.value)
|
||||
|
||||
@@ -394,7 +406,6 @@ const handleSubmit = async () => {
|
||||
case 'email':
|
||||
// 更新邮箱
|
||||
if (!editForm.value.email || !editForm.value.code) {
|
||||
uni.hideLoading()
|
||||
uni.showToast({
|
||||
title: t('user.pleaseInputCode'),
|
||||
icon: 'none'
|
||||
@@ -407,7 +418,6 @@ const handleSubmit = async () => {
|
||||
case 'password':
|
||||
// 更新密码
|
||||
if (!passwordOk.value) {
|
||||
uni.hideLoading()
|
||||
uni.showToast({
|
||||
title: passwordNote.value,
|
||||
icon: 'none'
|
||||
@@ -415,7 +425,6 @@ const handleSubmit = async () => {
|
||||
return
|
||||
}
|
||||
if (editForm.value.password !== editForm.value.confirmPassword) {
|
||||
uni.hideLoading()
|
||||
uni.showToast({
|
||||
title: t('user.passwordNotMatch'),
|
||||
icon: 'none'
|
||||
@@ -429,7 +438,6 @@ const handleSubmit = async () => {
|
||||
// 更新头像
|
||||
console.log('avatarUrl.value:', avatarUrl.value)
|
||||
if (!avatarUrl.value) {
|
||||
uni.hideLoading()
|
||||
uni.showToast({
|
||||
title: t('common.pleaseSelect') + t('user.avatar'),
|
||||
icon: 'none'
|
||||
@@ -444,8 +452,7 @@ const handleSubmit = async () => {
|
||||
|
||||
case 'sex':
|
||||
// 更新性别
|
||||
const sexValue = editValue.value === 2 ? 0 : editValue.value
|
||||
updateData.sex = sexValue
|
||||
updateData.sex = editValue.value
|
||||
await updateUserInfo(updateData)
|
||||
break
|
||||
|
||||
@@ -463,7 +470,6 @@ const handleSubmit = async () => {
|
||||
break
|
||||
}
|
||||
|
||||
uni.hideLoading()
|
||||
uni.showToast({
|
||||
title: t('user.updateSuccess'),
|
||||
icon: 'success'
|
||||
@@ -477,7 +483,6 @@ const handleSubmit = async () => {
|
||||
}, 500)
|
||||
} catch (error) {
|
||||
console.error('更新失败:', error)
|
||||
uni.hideLoading()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user