vue-pro/yudao-ui-app/pages/profile/profile.vue

130 lines
3.2 KiB
Vue
Raw Normal View History

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">
<u-avatar size="60" :src="userInfo.avatar"></u-avatar>
<u-icon class="btn" name="arrow-right"></u-icon>
</view>
</view>
<view class="info-item">
<view class="label">昵称</view>
2022-04-21 01:47:01 +08:00
<view v-if="!nameEditOn" class="info">
2022-04-21 00:01:24 +08:00
<view class="value">{{ userInfo.nickname }}</view>
2022-04-21 01:47:01 +08:00
<u-icon
class="btn"
name="edit-pen"
@click="
tempName = userInfo.nickname
nameEditOn = true
"
></u-icon>
</view>
<view v-else class="name-edit">
<u--input maxlength="10" border="bottom" v-model="tempName"></u--input>
<view class="edit-btn-group">
<u-tag class="edit-btn" text="保存" plain size="mini" type="primary" @click="handleSaveBtnClick"></u-tag>
<u-tag
class="edit-btn"
text="取消"
plain
size="mini"
type="info"
@click="
tempName = ''
nameEditOn = false
"
></u-tag>
</view>
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>
<u-icon class="btn" name="edit-pen"></u-icon>
</view>
</view>
</view>
</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
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: [],
nameEditOn: false,
tempName: ''
}
},
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-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
},
handleSaveBtnClick() {
updateNickname({ nickname: this.tempName }).then(res => {
this.nameEditOn = false;
this.userInfo.nickname = this.tempName
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-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 {
@include flex-right;
.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
}
}
</style>