用户修改昵称

This commit is contained in:
sfmind 2022-04-21 01:47:01 +08:00
parent e9c0c452c8
commit 79ab6f308d
2 changed files with 59 additions and 19 deletions

View File

@ -1,3 +1,4 @@
//请求工具参考https://ext.dcloud.net.cn/plugin?id=392
const { http } = uni.$u
/* login */
@ -19,6 +20,11 @@ export const updateAvatar = filePath =>
fileType: 'image',
filePath: filePath
})
//修改用户昵称
export const updateNickname = params =>
http.put('/app-api/member/user/update-nickname', {}, {
params
})
/* index */
// 获取滚动图数据

View File

@ -10,9 +10,33 @@
</view>
<view class="info-item">
<view class="label">昵称</view>
<view class="info">
<view v-if="!nameEditOn" class="info">
<view class="value">{{ userInfo.nickname }}</view>
<u-icon class="btn" name="edit-pen"></u-icon>
<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>
</view>
</view>
<view class="info-item">
@ -27,7 +51,7 @@
</template>
<script>
import { getUserInfo, updateAvatar } from '../../common/api'
import { getUserInfo, updateAvatar, updateNickname } from '../../common/api'
export default {
data() {
@ -37,7 +61,9 @@ export default {
avatar: '',
mobile: ''
},
avatarFiles: []
avatarFiles: [],
nameEditOn: false,
tempName: ''
}
},
onLoad() {
@ -45,28 +71,27 @@ export default {
},
methods: {
loadUserInfoData() {
getUserInfo()
.then(res => {
getUserInfo().then(res => {
this.userInfo = res.data
})
.catch(err => {
//console.log(err)
})
},
handleAvatarClick() {
uni.chooseImage({
success: chooseImageRes => {
const tempFilePaths = chooseImageRes.tempFilePaths
console.log(tempFilePaths)
updateAvatar(tempFilePaths[0])
.then(res => {
console.log(res)
})
.catch(err => {
//console.log(err)
updateAvatar(tempFilePaths[0]).then(res => {
this.userInfo.avatar = res.data
this.$store.commit('setUserInfo', this.userInfo)
})
}
})
},
handleSaveBtnClick() {
updateNickname({ nickname: this.tempName }).then(res => {
this.nameEditOn = false;
this.userInfo.nickname = this.tempName
this.$store.commit('setUserInfo', this.userInfo)
})
}
}
}
@ -90,6 +115,15 @@ export default {
margin-left: 30rpx;
}
}
.name-edit {
@include flex-left;
.edit-btn-group {
@include flex;
.edit-btn {
margin-left: 20rpx;
}
}
}
}
}
</style>