用户修改昵称

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 const { http } = uni.$u
/* login */ /* login */
@ -19,6 +20,11 @@ export const updateAvatar = filePath =>
fileType: 'image', fileType: 'image',
filePath: filePath filePath: filePath
}) })
//修改用户昵称
export const updateNickname = params =>
http.put('/app-api/member/user/update-nickname', {}, {
params
})
/* index */ /* index */
// 获取滚动图数据 // 获取滚动图数据

View File

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