Files
dvcp_v2_wechat_app/src/mods/extra/AppMine/userInfo.vue

249 lines
5.2 KiB
Vue
Raw Normal View History

2022-07-15 19:03:40 +08:00
<template>
<div class="page">
<div class="info-list">
<div class="item-content mar-b8">
<div class="item solid">
<p class="mar-t22">头像</p>
<button class="user-img-div" open-type="chooseAvatar" @chooseavatar="handleWeixinSync">
2023-03-13 14:01:54 +08:00
<img v-if="user.avatarUrl" :src="user.avatarUrl" class="user-img">
<!-- <img src="https://cdn.cunwuyun.cn/dvcp/myFamily/tx.png" alt="" class="user-img" > -->
2022-07-15 19:03:40 +08:00
</button>
</div>
<div class="item">
<p>用户昵称</p>
<div v-if="!editNickName" @click="editNickName=true">
<p class="name" v-text="nickName"/>
</div>
<input v-else type="nickname" class="editNickName" v-model="nickName" @blur="handleWeixinSync">
</div>
</div>
<div class="item-content mar-b8">
<div class="item">
<p>手机号</p>
<div>{{ user.phone || '' }}</div>
</div>
</div>
<div class="item-content" @click="onLogout">
<div class="item">
<p class="login-out">退出登录</p>
</div>
</div>
</div>
</div>
</template>
<script>
import {mapActions, mapState} from 'vuex'
export default {
name: "userInfo",
appName: "个人中心",
computed: {
...mapState(['user', 'token']),
nickName: {
set(v) {
},
get() {
const {nickName} = this.user
return nickName
}
2023-03-13 14:01:54 +08:00
},
2022-07-15 19:03:40 +08:00
},
onLoad() {
this.getUserInfo()
2023-03-13 14:01:54 +08:00
2022-07-15 19:03:40 +08:00
},
data() {
return {
2023-03-13 14:01:54 +08:00
editNickName: false,
avatar: '',
2022-07-15 19:03:40 +08:00
}
},
methods: {
...mapActions(['getUserInfo', 'autoLogin']),
2023-03-13 14:01:54 +08:00
updateInfo() {
this.$instance.post(`/app/appwechatuser/update-nickName`,null,{
params: {
id: this.user.id,
nickName: this.nickName,
avatarUrl: this.avatar? this.avatar : this.user.avatarUrl,
}
}).then(res=> {
if(res?.code==0) {
this.$u.toast('修改成功')
}
})
},
2022-07-15 19:03:40 +08:00
upLoad(img) {
return new Promise((resolve, reject) => {
uni.uploadFile({
2022-09-21 16:21:41 +08:00
url: `${this.$instance.defaults.baseURL}/admin/file/add`,
2022-07-15 19:03:40 +08:00
filePath: img,
name: 'file',
header: {
'Content-Type': 'multipart/form-data',
Authorization: uni.getStorageSync('token')
},
success: uploadFileRes => {
2023-03-13 14:01:54 +08:00
this.avatar = JSON.parse(uploadFileRes.data).data[0].split(';')[0]
console.log(JSON.parse(uploadFileRes.data).data[0].split(';')[0])
2022-07-15 19:03:40 +08:00
resolve(uploadFileRes)
},
fail: err => {
reject(err)
}
})
})
},
onLogout() {
uni.showModal({
title: '提示',
content: "是否要退出登录",
success: res => {
if (res.confirm) {
this.$store.commit('logout')
this.$toast('退出成功');
setTimeout(() => {
uni.switchTab({
2022-07-15 19:44:39 +08:00
url: '/pages/AppMine/AppMine'
2022-07-15 19:03:40 +08:00
})
}, 500)
}
}
})
},
handleWeixinSync({detail}) {
2023-03-13 14:01:54 +08:00
const { value: nickName, avatarUrl } = detail
this.autoLogin({ nickName, avatarUrl })
if(avatarUrl?.length) {
this.upLoad(avatarUrl).then(() => {
this.updateInfo()
})
}
if(nickName) {
this.updateInfo()
}
2022-07-15 19:03:40 +08:00
}
}
}
</script>
<style scoped lang="scss">
@import "~dvcp-wui/common";
.page {
width: 100%;
background-color: #F5F5F5;
.info-list {
margin: 0 0 16px 0;
.item-content {
padding: 0 32px;
background-color: #fff;
}
.item {
padding: 36px 0;
line-height: 40px;
width: 100%;
box-sizing: content-box;
display: flex;
justify-content: space-between;
p {
color: #333;
font-weight: 400;
}
div {
color: #666;
font-size: 28px;
}
.user-img-div {
width: 104px;
height: 104px;
border-radius: 50%;
overflow: hidden;
}
.user-img {
width: 104px;
height: 104px;
vertical-align: middle;
border-radius: 50%;
}
.right-icon {
width: 40px;
height: 40px;
vertical-align: middle;
}
.mar-t22 {
margin-top: 44px;
}
}
.login-out {
width: 100%;
font-size: 30px;
text-align: center;
}
}
.self-knowledge-show {
position: fixed;
left: 0;
top: 0;
z-index: 100;
width: 100%;
height: 100%;
background: rgba(0, 0, 0, 0.3);
}
.toast-bg {
position: fixed;
z-index: 101;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
}
.toast {
background-color: #fff;
width: 686px;
height: 316px;
font-size: 36px;
}
.toast-msg {
text-align: center;
line-height: 50px;
color: #333;
font-weight: 500;
padding: 84px 0 80px 0;
}
.toast-btn {
display: inline-block;
width: 120px;
text-align: center;
line-height: 50px;
}
.cancel {
margin-left: 394px;
margin-right: 40px;
}
.confirm {
color: #197DF0;
}
.editNickName {
text-align: right;
font-size: 28px;
}
}
</style>