|
|
|
@ -19,7 +19,7 @@ |
|
|
|
<button class="avatar-button" open-type="chooseAvatar" @chooseavatar="onChooseAvatar"> |
|
|
|
<image |
|
|
|
class="avatar-image" |
|
|
|
:src="userInfo.headImage || '/static/默认图片.png'" |
|
|
|
:src="userInfo.avatar || '/static/默认头像.png'" |
|
|
|
mode="aspectFill" |
|
|
|
></image> |
|
|
|
</button> |
|
|
|
@ -30,15 +30,15 @@ |
|
|
|
<text class="form-label">昵称</text> |
|
|
|
<input |
|
|
|
class="form-input" |
|
|
|
type="nickname" |
|
|
|
v-model="userInfo.nickName" |
|
|
|
type="name" |
|
|
|
v-model="userInfo.name" |
|
|
|
placeholder="请输入昵称" |
|
|
|
@blur="onNicknameBlur" |
|
|
|
@blur="nameBlur" |
|
|
|
/> |
|
|
|
</view> |
|
|
|
|
|
|
|
<!-- 手机号 --> |
|
|
|
<!-- <view class="form-item"> |
|
|
|
<view class="form-item"> |
|
|
|
<text class="form-label">手机号</text> |
|
|
|
<view class="phone-container" v-if="!userInfo.phone"> |
|
|
|
<button |
|
|
|
@ -51,7 +51,7 @@ |
|
|
|
</view> |
|
|
|
<text class="form-label" v-else>{{ userInfo.phone }}</text> |
|
|
|
</view> |
|
|
|
--> |
|
|
|
|
|
|
|
<!-- 所在部门 --> |
|
|
|
<!-- <view class="form-item"> |
|
|
|
<text class="form-label">所在部门</text> |
|
|
|
@ -98,8 +98,8 @@ export default { |
|
|
|
data() { |
|
|
|
return { |
|
|
|
userInfo: { |
|
|
|
headImage: '', |
|
|
|
nickName: '', |
|
|
|
avatar: '', |
|
|
|
name: '', |
|
|
|
phone: '', |
|
|
|
department: { |
|
|
|
title: '', |
|
|
|
@ -113,7 +113,8 @@ export default { |
|
|
|
}, |
|
|
|
async onLoad() { |
|
|
|
this.calculateContainerHeight(); |
|
|
|
// await this.getUserInfo(); |
|
|
|
|
|
|
|
await this.getUserInfo(); |
|
|
|
}, |
|
|
|
computed: { |
|
|
|
// 部门选择器数据格式转换 |
|
|
|
@ -135,16 +136,16 @@ export default { |
|
|
|
// 获取微信用户信息 |
|
|
|
async getWechatUserInfo() { |
|
|
|
const { result } = await this.$api.user.queryUser() |
|
|
|
this.userInfo.nickName = result.nickName |
|
|
|
this.userInfo.headImage = result.headImage |
|
|
|
this.userInfo.name = result.name |
|
|
|
this.userInfo.avatar = result.avatar |
|
|
|
this.userInfo.phone = result.phone |
|
|
|
}, |
|
|
|
|
|
|
|
// 提交表单 |
|
|
|
async getUserInfo(){ |
|
|
|
const { result:info } = await this.$api.user.queryUser() |
|
|
|
this.userInfo.nickName = info.nickName |
|
|
|
this.userInfo.headImage = info.headImage |
|
|
|
const { result:info } = await this.$api.login.getUserInfo() |
|
|
|
this.userInfo.name = info.name |
|
|
|
this.userInfo.avatar = info.headImage |
|
|
|
this.userInfo.phone = info.phone |
|
|
|
}, |
|
|
|
|
|
|
|
@ -169,7 +170,7 @@ export default { |
|
|
|
|
|
|
|
if (uploadResult.success) { |
|
|
|
// 上传成功,更新头像URL |
|
|
|
this.userInfo.headImage = uploadResult.url; |
|
|
|
this.userInfo.avatar = uploadResult.url; |
|
|
|
console.log('头像上传成功', uploadResult.url); |
|
|
|
uni.showToast({ |
|
|
|
title: '头像上传成功', |
|
|
|
@ -182,7 +183,7 @@ export default { |
|
|
|
uni.hideLoading(); |
|
|
|
console.error('头像上传异常:', error); |
|
|
|
// 异常情况下使用本地头像 |
|
|
|
this.userInfo.headImage = e.detail.avatarUrl; |
|
|
|
this.userInfo.avatar = e.detail.avatarUrl; |
|
|
|
uni.showToast({ |
|
|
|
title: '头像处理异常,使用本地头像', |
|
|
|
icon: 'none' |
|
|
|
@ -198,8 +199,8 @@ export default { |
|
|
|
|
|
|
|
|
|
|
|
// 昵称输入失焦 |
|
|
|
onNicknameBlur() { |
|
|
|
if (!this.userInfo.nickName.trim()) { |
|
|
|
nameBlur() { |
|
|
|
if (!this.userInfo.name.trim()) { |
|
|
|
uni.showToast({ |
|
|
|
title: '请输入昵称', |
|
|
|
icon: 'none' |
|
|
|
@ -234,11 +235,11 @@ export default { |
|
|
|
if (e.detail.errMsg === 'getPhoneNumber:ok') { |
|
|
|
// 获取成功,可以通过e.detail.code发送到后端换取手机号 |
|
|
|
console.log('获取手机号成功', e.detail); |
|
|
|
const res = await this.$api.login.bindPhone({ |
|
|
|
phoneCode: e.detail.code |
|
|
|
const { result:phoneRes } = await this.$api.login.bindPhone({ |
|
|
|
code: e.detail.code |
|
|
|
}) |
|
|
|
const str = JSON.parse(res.result); |
|
|
|
this.userInfo.phone = str.phone_info.phoneNumber |
|
|
|
|
|
|
|
this.userInfo.phone = phoneRes |
|
|
|
uni.showToast({ |
|
|
|
title: '手机号获取成功', |
|
|
|
icon: 'success' |
|
|
|
@ -254,7 +255,7 @@ export default { |
|
|
|
|
|
|
|
// 提交用户信息 |
|
|
|
async submitUserInfo() { |
|
|
|
if (!this.userInfo.nickName.trim()) { |
|
|
|
if (!this.userInfo.name.trim()) { |
|
|
|
uni.showToast({ |
|
|
|
title: '请输入昵称', |
|
|
|
icon: 'none' |
|
|
|
@ -270,24 +271,17 @@ export default { |
|
|
|
return; |
|
|
|
} |
|
|
|
|
|
|
|
if (!this.userInfo.department.title.trim()) { |
|
|
|
uni.showToast({ |
|
|
|
title: '请选择所在部门', |
|
|
|
icon: 'none' |
|
|
|
}); |
|
|
|
return; |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
console.log('提交用户信息', this.userInfo); |
|
|
|
|
|
|
|
try { |
|
|
|
// 提交用户信息 |
|
|
|
await this.$api.user.updateUser({ |
|
|
|
nickName: this.userInfo.nickName, |
|
|
|
await this.$api.login.updateUserInfo({ |
|
|
|
name: this.userInfo.name, |
|
|
|
phone: this.userInfo.phone, |
|
|
|
headImage: this.userInfo.headImage, |
|
|
|
department: this.userInfo.department.id, |
|
|
|
remark: this.userInfo.remark |
|
|
|
avatar: this.userInfo.avatar, |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
uni.showToast({ |
|
|
|
|