个人信息页面的头像修改暂定方案实行

This commit is contained in:
wangzimeng 2025-07-23 17:23:38 +08:00
parent fbce1a4103
commit eeccef63fc

View File

@ -4,7 +4,33 @@
<view class="container">
<view class="card">
<view class="list">
<view class="list-item" @click="setAvator">
<view class="list-item" @click="imageShow=true">
<view>
头像
</view>
<view class="right">
<u-image :src="avatar" shape="circle" width="100rpx" height="100rpx"></u-image>
<view style="margin-left: 10px;">
<u-icon name="arrow-right"></u-icon>
</view>
</view>
</view>
<u-popup :show="imageShow" mode="center" closeable closeOnClickOverlay @close="imageShow=false">
<view class="popup_box">
<view class="popup_title">更换图片</view>
<button class="popup_button" type="default" plain="true" open-type="chooseAvatar"
@chooseavatar="chooseavatar">
<u-image shape="circle" width="140rpx" height="140rpx" :src="upAvatar" mode="aspectFill"></u-image>
</button>
<view style="width: 80% !important;margin-top: 20px;">
<u-button shape="circle" @click="confirmImage" :customStyle="avatarShowStyle">
完成
</u-button>
</view>
</view>
</u-popup>
<!-- <view class="list-item" @click="setAvator">
<view class="left">
头像设置
</view>
@ -16,7 +42,7 @@
<u-icon name="arrow-right"></u-icon>
</view>
</view>
</view>
</view> -->
<view class="list-item" @click="toName('nc')">
<view class="left">
昵称设置
@ -142,6 +168,7 @@
export default {
data() {
return {
baseUrl: 'https://naweigetetest2.hschool.com.cn/',
typeop: '',
avatarStyle: {
display: 'flex',
@ -185,6 +212,17 @@
border: 'none',
fontFamily: "YouSheBiaoTiHei"
},
avatarShowStyle: {
width: '400rpx',
height: '90rpx',
borderRadius: '148rpx',
background: '#323232',
fontSize: '36rpx',
color: '#BBFC5B',
lineHeight: '90rpx',
border: 'none',
fontFamily: "YouSheBiaoTiHei"
},
//
niName: '',
//
@ -253,7 +291,9 @@
}]
],
sfInfo: {},
bankInfo: {}
bankInfo: {},
imageShow: false,
profile:'',
}
},
onLoad(options) {
@ -277,6 +317,117 @@
this.getDetail();
},
methods: {
confirmImage() {
console.log('confirmImage11',this.profile);
if(!this.profile){
uni.showToast({
title: "请选择图片",
icon: "none"
})
return
}
console.log('confirmImage22');
// this.userInfo.profile = this.profile
// this.userInfo.avatar = this.profile
this.upAvatar = this.profile;
this.avatar = this.avatar;
console.log(this.upAvatar);
console.log(this.avatar);
this.imageShow = false
this.submit();
},
async chooseavatar(e) {
console.log('chooseavatar',e,e.detail);
// this.profile = this.uploadFilePromise(e.detail.avatarUrl, 'user');
let result = await this.uploadFilePromise(e.detail.avatarUrl, 'user');
console.log('chooseavatar2222',result,);
this.profile = result
this.upAvatar = this.baseUrl + this.profile
this.avatar = this.profile;
console.log('chooseavatar3333',this.profile,this.avatar,this.upAvatar);
},
uploadFilePromise(url) {
console.log('uploadFilePromise',url);
// console.log('', `${baseUrl}/common/upload`);
console.log('上传-uploadFilePromise');
// console.log('category', category)
return new Promise((resolve, reject) => {
let a = uni.uploadFile({
url: 'https://naweigetetest2.hschool.com.cn/api/common/upload', //
filePath: url,
name: 'file',
formData: {
user: 'test',
category: 'category'
},
header: {
"token": uni.getStorageSync("token")
},
success: (res) => {
console.log('uploadFilePromise成功',res.data);
// setTimeout(() => {
// resolve(JSON.parse(res.data).url);
// }, 1000);
var js = JSON.parse(res.data);
console.log(js.data.errcode);
if (js.data.errcode == '30002') {
uni.showToast({
title: '请登录...',
icon: 'none',
duration: 1000
});
setTimeout(() => {
uni.switchTab({
url: '/pages/my/index',
})
}, 1000)
resolve('');
}
resolve(js.data.url);
},
fail: (err) => {
reject(err);
}
});
// console.log('');
});
// return new Promise((resolve, reject) => {
// let a = uni.uploadFile({
// url: 'https://naweigetetest2.hschool.com.cn/api/common/upload', //
// filePath: url,
// name: 'file',
// header: {
// "token": uni.getStorageSync("token")
// },
// formData: {
// 'user': 'test'
// },
// success: (res) => {
// console.log('res', JSON.parse(res.data), JSON.parse(res.data).url);
// setTimeout(() => {
// resolve(JSON.parse(res.data).url);
// }, 1000);
// },
// fail: (res) => {
// setTimeout(() => {
// console.log("", res)
// reject(res)
// }, 1000);
// }
// });
// });
},
closeImagePopup() {
this.imageShow = false
},
getBankList() {
uni.$u.http
.get("/api/school.newactivity.settle_log/detail")
@ -372,6 +523,8 @@
// }
if (userinfo.avatar !== null) {
this.avatar = userinfo.avatar
this.upAvatar = userinfo.avatar
this.profile = userinfo.avatar
uni.setStorageSync('avatar', this.avatar)
}
if (userinfo.nickname !== null) {
@ -731,5 +884,37 @@
}
}
}
.popup_box {
background-color: #fff;
display: flex;
flex-direction: column;
align-items: center;
justify-content: space-around;
padding: 20px;
.popup_title {
width: 500rpx;
text-align: center;
margin: 10px auto;
}
button {
box-shadow: 0 5px 7px 0 rgba(86, 119, 252, 0);
}
::v-deep button[type=default][plain] {
border: none;
}
.nickname {
border: none;
font-size: 32rpx;
margin: 0;
}
}
}
</style>