Files
app-govern/pages/user/changeName.vue
2023-08-11 11:03:31 +08:00

79 lines
2.0 KiB
Vue

<template>
<Cn-page :loading="loading">
<view slot="body">
<view class="change-name">
<view class="content">
<uni-easyinput type="text" v-model="name" placeholder="请输入昵称" />
</view>
<view class="btn-wrap">
<view class="btn-wrap-item" @click="submit"> 提交 </view>
</view>
</view>
</view>
</Cn-page>
</template>
<script>
import { apiUpdateUser } from '@/common/api/user'
export default {
data() {
return {
loading: false,
// 表单数据
name: '',
}
},
methods: {
submit() {
apiUpdateUser({
name: this.name,
}).then((res) => {
console.log(res)
uni.showToast({
title: '修改成功',
icon: 'none',
})
let userInfo = uni.getStorageSync(this.$cacheKey.userInfo)
userInfo.nickname = this.name
uni.setStorageSync(this.$cacheKey.userInfo, userInfo)
setTimeout(() => {
uni.navigateBack()
}, 1500)
})
},
},
onLoad() {
this.name = uni.getStorageSync(this.$cacheKey.userInfo).nickname
},
}
</script>
<style lang="scss">
.change-name {
padding: 34rpx;
.content {
margin-bottom: 20rpx;
padding: 34rpx;
background: $uni-theme-white;
border-radius: 12rpx;
}
.btn-wrap {
margin-top: 40rpx;
display: flex;
align-items: center;
justify-content: space-between;
.btn-wrap-item {
display: flex;
align-items: center;
justify-content: center;
flex: 1;
background: $uni-theme-color;
color: #fff;
height: 80rpx;
border-radius: 12rpx;
}
}
}
</style>