mirror of
https://codeup.aliyun.com/67762337eccfc218f6110e0e/vue/learning-system-mobile.git
synced 2025-12-13 21:06:45 +08:00
修改头像
This commit is contained in:
@@ -7,9 +7,8 @@
|
|||||||
<text class="u-demo-block__title">基础信息</text>
|
<text class="u-demo-block__title">基础信息</text>
|
||||||
<view class="u-demo-block__content">
|
<view class="u-demo-block__content">
|
||||||
<u-cell-group >
|
<u-cell-group >
|
||||||
<u-cell title="头像" :isLink="true" @click="toRouter('headimg')">
|
<u-cell title="头像" :isLink="true">
|
||||||
<u-avatar v-if="userInfoObj.account.avatar!=''" slot="value" shape="circle" size="58pt" :src="userInfoObj.account.avatar"></u-avatar>
|
<u-avatar v-if="userInfoObj.account.avatar!=''" slot="value" @click="updateHeadImg" shape="circle" size="58pt" :src="imgurl"></u-avatar>
|
||||||
<!-- <text>{{userInfoObj.name}}</text> -->
|
|
||||||
</u-cell>
|
</u-cell>
|
||||||
<u-cell title="姓名" v-model="userInfoObj.name"></u-cell>
|
<u-cell title="姓名" v-model="userInfoObj.name"></u-cell>
|
||||||
<u-cell title="性别" v-model="userInfoObj.gender==1?'男':'女'"></u-cell>
|
<u-cell title="性别" v-model="userInfoObj.gender==1?'男':'女'"></u-cell>
|
||||||
@@ -65,8 +64,14 @@
|
|||||||
</template>
|
</template>
|
||||||
<script>
|
<script>
|
||||||
import userApi from "@/api/system/user";
|
import userApi from "@/api/system/user";
|
||||||
|
import uploadUtil from '@/utils/upload.js'
|
||||||
|
import accountApi from '@/api/account';
|
||||||
|
import config from '@/config/index.js'
|
||||||
|
import cropper from "@/components/x-cropper/x-cropper.vue"
|
||||||
import { mapGetters } from 'vuex';
|
import { mapGetters } from 'vuex';
|
||||||
|
import {getToken} from '@/utils/token.js'
|
||||||
export default {
|
export default {
|
||||||
|
components: {cropper},
|
||||||
data() {
|
data() {
|
||||||
return {
|
return {
|
||||||
aid:'',
|
aid:'',
|
||||||
@@ -74,6 +79,7 @@
|
|||||||
account:{nickName:'',mobile:'',avatar:'',email:'',passValue:''},
|
account:{nickName:'',mobile:'',avatar:'',email:'',passValue:''},
|
||||||
},
|
},
|
||||||
clearShow:false,
|
clearShow:false,
|
||||||
|
imgurl:"",
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
computed: {
|
computed: {
|
||||||
@@ -82,9 +88,11 @@
|
|||||||
onShow(){
|
onShow(){
|
||||||
this.$store.dispatch('GetUserInfo').then(rs=>{
|
this.$store.dispatch('GetUserInfo').then(rs=>{
|
||||||
this.aid=rs.aid;
|
this.aid=rs.aid;
|
||||||
|
this.imgurl = rs.avatar;
|
||||||
this.load();
|
this.load();
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
||||||
},
|
},
|
||||||
onLoad(){
|
onLoad(){
|
||||||
//this.load()
|
//this.load()
|
||||||
@@ -93,6 +101,50 @@
|
|||||||
logout() {
|
logout() {
|
||||||
this.clearShow=true;
|
this.clearShow=true;
|
||||||
},
|
},
|
||||||
|
|
||||||
|
updateHeadImg() {
|
||||||
|
let self=this;
|
||||||
|
if (this.fSelecting) return;
|
||||||
|
this.fSelecting = true;
|
||||||
|
setTimeout(() => {
|
||||||
|
this.fSelecting = false;
|
||||||
|
}, 500);
|
||||||
|
|
||||||
|
uni.chooseImage({
|
||||||
|
count: 1,
|
||||||
|
sizeType: ['original', 'compressed'],
|
||||||
|
sourceType: ['camera', 'album'],
|
||||||
|
success: (r) => {
|
||||||
|
uni.showLoading({
|
||||||
|
mask: true
|
||||||
|
});
|
||||||
|
|
||||||
|
uploadUtil.uploadFile(r.tempFilePaths[0]).then(rs=>{
|
||||||
|
if(rs.status==200){
|
||||||
|
this.imgurl = rs.result.httpPath;
|
||||||
|
accountApi.updateAvatar({id:this.aid,avatar:rs.result.filePath}).then(rs2=>{
|
||||||
|
if(rs2.status == 200){
|
||||||
|
// 更新下页面缓存
|
||||||
|
this.$store.dispatch('InitData');
|
||||||
|
// uni.navigateBack(-1);
|
||||||
|
uni.showToast({
|
||||||
|
title:'更新成功'
|
||||||
|
})
|
||||||
|
} else {
|
||||||
|
uni.showToast({
|
||||||
|
title:'更新失败'
|
||||||
|
})
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
}
|
||||||
|
});
|
||||||
|
uni.hideLoading();
|
||||||
|
}
|
||||||
|
})
|
||||||
|
},
|
||||||
|
|
||||||
|
|
||||||
confirmClear(){
|
confirmClear(){
|
||||||
let that = this;
|
let that = this;
|
||||||
that.$store.dispatch("LogOut").then(rs => {
|
that.$store.dispatch("LogOut").then(rs => {
|
||||||
|
|||||||
Reference in New Issue
Block a user