|
|
@ -13,6 +13,7 @@ |
|
|
<uv-input |
|
|
<uv-input |
|
|
v-model="userInfo.name" |
|
|
v-model="userInfo.name" |
|
|
placeholder="请输入昵称" |
|
|
placeholder="请输入昵称" |
|
|
|
|
|
type="nickname" |
|
|
:customStyle="inputStyle" |
|
|
:customStyle="inputStyle" |
|
|
border="bottom" |
|
|
border="bottom" |
|
|
></uv-input> |
|
|
></uv-input> |
|
|
@ -39,7 +40,7 @@ |
|
|
<text class="required">*</text> |
|
|
<text class="required">*</text> |
|
|
<text>头像</text> |
|
|
<text>头像</text> |
|
|
</view> |
|
|
</view> |
|
|
<view class="avatar-container" @click="uploadAvatar"> |
|
|
|
|
|
|
|
|
<button class="avatar-container" open-type="chooseAvatar" @chooseavatar="onChooseAvatar"> |
|
|
<view |
|
|
<view |
|
|
v-if="userInfo.avatar === 'undefined'" |
|
|
v-if="userInfo.avatar === 'undefined'" |
|
|
class="avatar-image" |
|
|
class="avatar-image" |
|
|
@ -56,7 +57,7 @@ |
|
|
<view class="avatar-mask" :class="{ 'fade-out': showMask }" v-if="showMask"> |
|
|
<view class="avatar-mask" :class="{ 'fade-out': showMask }" v-if="showMask"> |
|
|
<text>点击上传头像</text> |
|
|
<text>点击上传头像</text> |
|
|
</view> |
|
|
</view> |
|
|
</view> |
|
|
|
|
|
|
|
|
</button> |
|
|
</view> |
|
|
</view> |
|
|
</view> |
|
|
</view> |
|
|
|
|
|
|
|
|
@ -102,25 +103,74 @@ export default { |
|
|
} |
|
|
} |
|
|
}, |
|
|
}, |
|
|
methods: { |
|
|
methods: { |
|
|
|
|
|
|
|
|
|
|
|
// // 微信昵称审核回调 |
|
|
|
|
|
// onNicknameReview(e) { |
|
|
|
|
|
// console.log('微信昵称审核回调', e); |
|
|
|
|
|
// if (e.detail.pass) { |
|
|
|
|
|
// // 审核通过,使用微信昵称 |
|
|
|
|
|
// this.userInfo.name = e.detail.value; |
|
|
|
|
|
// console.log('微信昵称审核通过:', e.detail.value); |
|
|
|
|
|
// uni.showToast({ |
|
|
|
|
|
// title: '昵称获取成功', |
|
|
|
|
|
// icon: 'success' |
|
|
|
|
|
// }); |
|
|
|
|
|
// } else { |
|
|
|
|
|
// // 审核不通过 |
|
|
|
|
|
// console.log('微信昵称审核不通过'); |
|
|
|
|
|
// uni.showToast({ |
|
|
|
|
|
// title: '昵称包含敏感词,请重新输入', |
|
|
|
|
|
// icon: 'none' |
|
|
|
|
|
// }); |
|
|
|
|
|
// } |
|
|
|
|
|
// }, |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 上传头像 |
|
|
|
|
|
async uploadAvatar() { |
|
|
|
|
|
try { |
|
|
|
|
|
const result = await this.$utils.chooseAndUpload() |
|
|
|
|
|
if (result && result.success) { |
|
|
|
|
|
console.log(result); |
|
|
|
|
|
|
|
|
// 选择头像并上传到OSS |
|
|
|
|
|
async onChooseAvatar(e) { |
|
|
|
|
|
console.log('选择头像回调', e); |
|
|
|
|
|
if (e.detail.avatarUrl) { |
|
|
|
|
|
try { |
|
|
|
|
|
// 显示上传中提示 |
|
|
|
|
|
uni.showLoading({ title: '上传头像中...' }); |
|
|
|
|
|
|
|
|
|
|
|
// 构造文件对象 |
|
|
|
|
|
const file = { |
|
|
|
|
|
path: e.detail.avatarUrl, |
|
|
|
|
|
tempFilePath: e.detail.avatarUrl |
|
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
// 上传到OSS |
|
|
|
|
|
const uploadResult = await this.$utils.uploadImage(file); |
|
|
|
|
|
|
|
|
this.userInfo.avatar = result.url |
|
|
|
|
|
|
|
|
uni.hideLoading(); |
|
|
|
|
|
|
|
|
|
|
|
if (uploadResult.success) { |
|
|
|
|
|
// 上传成功,更新头像URL |
|
|
|
|
|
this.userInfo.avatar = uploadResult.url; |
|
|
|
|
|
console.log('头像上传成功', uploadResult.url); |
|
|
|
|
|
uni.showToast({ |
|
|
|
|
|
title: '头像上传成功', |
|
|
|
|
|
icon: 'success' |
|
|
|
|
|
}); |
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
} catch (error) { |
|
|
|
|
|
uni.hideLoading(); |
|
|
|
|
|
console.error('头像上传异常:', error); |
|
|
|
|
|
// 异常情况下使用本地头像 |
|
|
|
|
|
this.userInfo.avatar = e.detail.avatarUrl; |
|
|
|
|
|
uni.showToast({ |
|
|
|
|
|
title: '头像处理异常,使用本地头像', |
|
|
|
|
|
icon: 'none' |
|
|
|
|
|
}); |
|
|
} |
|
|
} |
|
|
} catch (error) { |
|
|
|
|
|
console.error('头像上传失败:', error) |
|
|
|
|
|
|
|
|
} else { |
|
|
uni.showToast({ |
|
|
uni.showToast({ |
|
|
title: '头像上传失败', |
|
|
|
|
|
icon: 'error' |
|
|
|
|
|
}) |
|
|
|
|
|
|
|
|
title: '头像选择失败', |
|
|
|
|
|
icon: 'none' |
|
|
|
|
|
}); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
}, |
|
|
}, |
|
|
|
|
|
|
|
|
// 保存资料 |
|
|
// 保存资料 |
|
|
@ -175,6 +225,7 @@ export default { |
|
|
const res = await this.$api.login.getUserInfo() |
|
|
const res = await this.$api.login.getUserInfo() |
|
|
if (res.code === 200) { |
|
|
if (res.code === 200) { |
|
|
this.userInfo = res.result |
|
|
this.userInfo = res.result |
|
|
|
|
|
this.$store.dispatch('updateUserInfo', this.userInfo) |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
}, |
|
|
}, |
|
|
|