2022-04-06 16:08:26 +08:00
|
|
|
|
<template>
|
2022-04-21 00:01:24 +08:00
|
|
|
|
<view class="container">
|
|
|
|
|
<view class="user-info">
|
|
|
|
|
<view class="info-item">
|
|
|
|
|
<view class="label">头像:</view>
|
|
|
|
|
<view class="info" @click="handleAvatarClick">
|
2022-12-05 21:51:39 +08:00
|
|
|
|
<u-avatar size="50" shape="square" :src="userInfo.avatar"></u-avatar>
|
2022-04-21 00:01:24 +08:00
|
|
|
|
<u-icon class="btn" name="arrow-right"></u-icon>
|
|
|
|
|
</view>
|
|
|
|
|
</view>
|
|
|
|
|
<view class="info-item">
|
|
|
|
|
<view class="label">昵称:</view>
|
2022-11-19 21:40:26 +08:00
|
|
|
|
<view class="info">
|
2022-12-05 21:51:39 +08:00
|
|
|
|
<u--input maxlength="10" border="none" v-model="userInfo.nickname" inputAlign="right" @change="handleNameChange"></u--input>
|
2022-04-21 00:01:24 +08:00
|
|
|
|
</view>
|
|
|
|
|
</view>
|
|
|
|
|
<view class="info-item">
|
|
|
|
|
<view class="label">手机:</view>
|
|
|
|
|
<view class="info">
|
|
|
|
|
<view class="value">{{ userInfo.mobile }}</view>
|
|
|
|
|
</view>
|
|
|
|
|
</view>
|
|
|
|
|
</view>
|
2022-11-19 21:40:26 +08:00
|
|
|
|
|
|
|
|
|
<view v-if="nameUpdateVisible" class="btn-group">
|
|
|
|
|
<u-button type="primary" text="保存" customStyle="margin-top: 50px" @click="handleSaveBtnClick"></u-button>
|
|
|
|
|
</view>
|
|
|
|
|
|
2022-04-21 00:01:24 +08:00
|
|
|
|
</view>
|
2022-04-06 16:08:26 +08:00
|
|
|
|
</template>
|
|
|
|
|
|
|
|
|
|
<script>
|
2022-05-01 22:39:16 +08:00
|
|
|
|
import { getUserInfo, updateAvatar, updateNickname } from '../../api/user'
|
2022-04-21 00:01:24 +08:00
|
|
|
|
|
2022-04-16 22:04:02 +08:00
|
|
|
|
export default {
|
|
|
|
|
data() {
|
|
|
|
|
return {
|
2022-04-21 00:01:24 +08:00
|
|
|
|
userInfo: {
|
|
|
|
|
nickname: '',
|
|
|
|
|
avatar: '',
|
|
|
|
|
mobile: ''
|
|
|
|
|
},
|
2022-04-21 01:47:01 +08:00
|
|
|
|
avatarFiles: [],
|
2022-12-05 21:51:39 +08:00
|
|
|
|
tempName: ''
|
2022-11-19 21:40:26 +08:00
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
computed: {
|
|
|
|
|
nameUpdateVisible: function () {
|
|
|
|
|
return this.userInfo.nickname !== this.tempName
|
2022-04-16 22:04:02 +08:00
|
|
|
|
}
|
|
|
|
|
},
|
2022-04-21 00:01:24 +08:00
|
|
|
|
onLoad() {
|
|
|
|
|
this.loadUserInfoData()
|
|
|
|
|
},
|
|
|
|
|
methods: {
|
|
|
|
|
loadUserInfoData() {
|
2022-04-21 01:47:01 +08:00
|
|
|
|
getUserInfo().then(res => {
|
|
|
|
|
this.userInfo = res.data
|
2022-11-19 21:40:26 +08:00
|
|
|
|
this.tempName = this.userInfo.nickname
|
2022-04-21 01:47:01 +08:00
|
|
|
|
})
|
2022-04-21 00:01:24 +08:00
|
|
|
|
},
|
|
|
|
|
handleAvatarClick() {
|
|
|
|
|
uni.chooseImage({
|
|
|
|
|
success: chooseImageRes => {
|
|
|
|
|
const tempFilePaths = chooseImageRes.tempFilePaths
|
2022-04-21 01:47:01 +08:00
|
|
|
|
updateAvatar(tempFilePaths[0]).then(res => {
|
|
|
|
|
this.userInfo.avatar = res.data
|
2022-05-02 16:53:56 +08:00
|
|
|
|
this.$store.commit('SET_USER_INFO', this.userInfo)
|
2022-04-21 01:47:01 +08:00
|
|
|
|
})
|
2022-04-21 00:01:24 +08:00
|
|
|
|
}
|
|
|
|
|
})
|
2022-04-21 01:47:01 +08:00
|
|
|
|
},
|
2022-11-19 21:40:26 +08:00
|
|
|
|
handleNameChange(val) {
|
|
|
|
|
let str = uni.$u.trim(val, 'all')
|
|
|
|
|
this.$nextTick(() => {
|
|
|
|
|
this.userInfo.nickname = str
|
|
|
|
|
})
|
|
|
|
|
},
|
2022-04-21 01:47:01 +08:00
|
|
|
|
handleSaveBtnClick() {
|
2022-11-19 21:40:26 +08:00
|
|
|
|
updateNickname({ nickname: this.userInfo.nickname }).then(res => {
|
|
|
|
|
this.tempName = this.userInfo.nickname
|
2022-05-02 16:53:56 +08:00
|
|
|
|
this.$store.commit('SET_USER_INFO', this.userInfo)
|
2022-11-19 21:40:26 +08:00
|
|
|
|
uni.$u.toast('已保存')
|
|
|
|
|
setTimeout(() => {
|
|
|
|
|
uni.switchTab({
|
|
|
|
|
url: '/pages/user/user'
|
|
|
|
|
})
|
|
|
|
|
}, 300)
|
2022-04-21 01:47:01 +08:00
|
|
|
|
})
|
2022-04-21 00:01:24 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
2022-04-16 22:04:02 +08:00
|
|
|
|
}
|
2022-04-06 16:08:26 +08:00
|
|
|
|
</script>
|
|
|
|
|
|
2022-04-21 00:01:24 +08:00
|
|
|
|
<style lang="scss" scoped>
|
|
|
|
|
.user-info {
|
|
|
|
|
.info-item {
|
|
|
|
|
padding: 20rpx 60rpx;
|
|
|
|
|
border-bottom: $custom-border-style;
|
|
|
|
|
@include flex-space-between;
|
|
|
|
|
.label {
|
|
|
|
|
font-size: 30rpx;
|
|
|
|
|
}
|
|
|
|
|
.info {
|
2022-11-19 21:40:26 +08:00
|
|
|
|
@include flex-left;
|
2022-04-21 00:01:24 +08:00
|
|
|
|
.value {
|
|
|
|
|
font-size: 30rpx;
|
|
|
|
|
}
|
|
|
|
|
.btn {
|
|
|
|
|
margin-left: 30rpx;
|
|
|
|
|
}
|
|
|
|
|
}
|
2022-04-21 01:47:01 +08:00
|
|
|
|
.name-edit {
|
|
|
|
|
@include flex-left;
|
|
|
|
|
.edit-btn-group {
|
|
|
|
|
@include flex;
|
|
|
|
|
.edit-btn {
|
|
|
|
|
margin-left: 20rpx;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2022-04-21 00:01:24 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
2022-11-19 21:40:26 +08:00
|
|
|
|
|
|
|
|
|
.btn-group {
|
|
|
|
|
padding: 0 30rpx;
|
|
|
|
|
}
|
2022-04-21 00:01:24 +08:00
|
|
|
|
</style>
|