This commit is contained in:
zpc 2025-03-22 16:07:55 +08:00
parent 36075472d3
commit d7816a2bb7

View File

@ -1,389 +1,300 @@
<template> <template>
<view class="content"> <view class="content">
<uni-nav-bar left-icon="left" title="个人资料" color="#fff" backgroundColor="transparent" :fixed="true" <uni-nav-bar
:statusBar="true" :border="false" @clickLeft="back"></uni-nav-bar> left-icon="left"
title="个人资料"
color="#fff"
backgroundColor="transparent"
:fixed="true"
:statusBar="true"
:border="false"
@clickLeft="back"
></uni-nav-bar>
<view class="user_logo relative"> <view class="user-avatar">
<!-- <button class="avatar-wrapper" open-type="chooseAvatar" @click="chooseAvatar"> <button
<image class="avatar" :src="avatarUrl"></image> class="avatar-wrapper"
</button> --> open-type="chooseAvatar"
@chooseavatar="onChooseAvatar"
>
<image class="avatar" :src="avatarUrl"></image>
</button>
<text class="avatar-title">修改头像</text>
<image
class="camera-icon"
:src="$img1('my/camera.png')"
mode="aspectFill"
></image>
</view>
<button class="avatar-wrapper" open-type="chooseAvatar" @chooseavatar="onChooseAvatar"> <view class="form-container">
<image class="avatar" :src="avatarUrl"></image> <view class="form-item">
</button> <view class="form-label">昵称:</view>
<view class="form-input">
<text class="user_logo-title">修改头像</text> <input
<image class="camera" :src="$img1('my/camera.png')" mode="aspectFill"></image> type="nickname"
</view> v-model="nickname"
placeholder="请输入您的昵称"
<view class="row"> @blur="getnickname"
<view class="row-title">昵称:</view> />
</view>
<view class="right">
<input type="nickname" v-model="nickname" placeholder="请输入您的昵称" @blur="getnickname" />
</view>
</view>
<view class="row">
<view class="row-title">ID:</view>
<view class="right">
<input disabled :value="id" />
</view>
</view>
<view class="btn_b center" @click="setdata()">确认修改</view>
<!-- <view class="row">
<view class="row-title">手机号:</view>
<view class="right">
<input
:value="nickname"
placeholder="请输入您的昵称"
@blur="getnickname"
/>
</view> </view>
</view> -->
</view> <view class="form-item">
<view class="form-label">ID:</view>
<view class="form-input">
<input disabled :value="uid" />
</view>
</view>
</view>
<view class="submit-btn" @click="updateUserInfo">确认修改</view>
</view>
</template> </template>
<script> <script>
export default { export default {
data() { data() {
return { return {
statusBarHeight: uni.getSystemInfoSync().statusBarHeight, statusBarHeight: uni.getSystemInfoSync().statusBarHeight,
avatarUrl: uni.getStorageSync('userinfo').headimg, avatarUrl: "",
nickname: uni.getStorageSync('userinfo').nickname, nickname: "",
headimg_status: false, headimg_status: false,
id: uni.getStorageSync('userinfo').ID, id: "",
imageBase64: "", uid: "",
} imageBase64: "",
}, };
onLoad() {}, },
methods: {
back() {
uni.navigateBack()
},
getnickname(e) {
this.nickname = e.detail.value
console.log(e, this.nickname)
},
onChooseAvatar(e) { onLoad() {
// console.log("6666666666", e.detail, e.detail.avatarUrl) this.initUserInfo();
this.avatarUrl = e.detail.avatarUrl },
this.headimg_status = true
var that = this;
// Base64
uni.getFileSystemManager().readFile({
filePath: this.avatarUrl,
encoding: 'base64',
success: (base64Res) => {
const base64 = 'data:image/png;base64,' + base64Res.data;
console.log(base64);
that.imageBase64 = base64;
},
fail: (err) => {
console.error('读取文件失败:', err);
}
methods: {
/**
* 初始化用户信息
*/
initUserInfo() {
const userInfo = uni.getStorageSync("userinfo");
if (userInfo) {
this.avatarUrl = userInfo.headimg || "";
this.nickname = userInfo.nickname || "";
this.id = userInfo.ID;
this.uid = userInfo.uid;
}
},
}); /**
* 返回上一页
*/
back() {
uni.navigateBack();
},
// // /**
// uni.getFileSystemManager().readFile({ * 获取昵称
// filePath: this.avatarUrl, */
// encoding: 'binary', getnickname(e) {
// success: (binaryRes) => { this.nickname = e.detail.value;
// const binaryData = binaryRes.data; },
// console.log(':', binaryData);
// },
// fail: (err) => {
// console.error(':', err);
// }
// });
},
// chooseAvatar() { /**
// let that = this * 选择头像
// uni.chooseImage({ */
// count: 1, onChooseAvatar(e) {
// success: (res) => { if (e && e.detail && e.detail.avatarUrl) {
// console.log(res); this.avatarUrl = e.detail.avatarUrl;
// uni.showLoading({ this.headimg_status = true;
// title: '...', this.convertToBase64(this.avatarUrl);
// mask: true }
// }) },
// uni.uploadFile({
// url: that.siteBaseUrl + 'picture1',
// filePath: res.tempFilePaths[0],
// name: 'file',
// success: (e) => {
// let re = JSON.parse(e.data)
// that.avatarUrl = re.data.path
// that.headimg_status = true
// },
// fail: (err) => {
// uni.showToast({
// title: '',
// icon: 'none'
// })
// },
// complete: () => {
// uni.hideLoading()
// }
// })
// } /**
// }) * 将图片转换为Base64
// }, */
setdata() { convertToBase64(filePath) {
let that = this uni.getFileSystemManager().readFile({
if (this.headimg_status) { filePath: filePath,
that.req({ encoding: "base64",
url: 'update_userinfo', success: (res) => {
data: { this.imageBase64 = "data:image/png;base64," + res.data;
nickname: that.nickname, },
headimg: that.avatarUrl, fail: (err) => {
imagebase: that.imageBase64 console.error("读取文件失败:", err);
}, uni.showToast({
success(ress) { title: "图片处理失败",
if (ress.status == 1) { icon: "none",
uni.showToast({ });
title: '修改成功', },
icon: 'success', });
success() { },
setTimeout(() => {
that.$c.back() /**
}, 500) * 更新用户信息
} */
}) updateUserInfo() {
} if (!this.nickname) {
} uni.showToast({
}) title: "请输入昵称",
} else { icon: "none",
that.req({ });
url: 'update_userinfo', return;
data: { }
nickname: that.nickname,
headimg: that.avatarUrl, const data = {
imagebase: that.imageBase64 nickname: this.nickname,
}, headimg: this.avatarUrl,
success(ress) { imagebase: this.imageBase64,
if (ress.status == 1) { };
uni.showToast({
title: '修改成功', this.$request
icon: 'success', .post("update_userinfo", data)
success() { .then((res) => {
setTimeout(() => { if (res.status === 1) {
uni.redirectTo({ //
url: './index' const userInfo = uni.getStorageSync("userinfo") || {};
}) userInfo.nickname = this.nickname;
}, 1000) userInfo.headimg = this.avatarUrl;
} uni.setStorageSync("userinfo", userInfo);
})
} uni.showToast({
} title: "修改成功",
}) icon: "success",
} });
}
} //
} setTimeout(() => {
uni.redirectTo({
url: "./index",
});
}, 1000);
} else {
uni.showToast({
title: res.msg || "修改失败",
icon: "none",
});
}
})
.catch((err) => {
uni.showToast({
title: "网络请求失败",
icon: "none",
});
console.error(err);
});
},
},
};
</script> </script>
<style lang="scss"> <style lang="scss">
.content { .content {
width: 100vw; width: 100vw;
height: 100vh; height: 100vh;
box-sizing: border-box; box-sizing: border-box;
color: #fff; color: #fff;
display: flex;
flex-direction: column;
}
.head { .user-avatar {
position: fixed; padding: 80rpx 0 60rpx 0;
top: 0; text-align: center;
z-index: 20; position: relative;
.header_title { .avatar-title {
height: 70rpx; font-size: 30rpx;
line-height: 70rpx; color: #ffffff;
width: 100%; position: absolute;
box-sizing: border-box; top: 280rpx;
font-weight: bold; left: 50%;
display: flex; transform: translateX(-50%);
align-items: center; }
padding-left: 30rpx;
box-sizing: border-box;
>view:nth-of-type(1) { .avatar-wrapper {
display: flex; width: 165rpx;
align-items: center; height: 165rpx;
} margin: auto;
border-radius: 128rpx;
overflow: hidden;
border: 1rpx solid #fff;
background-color: transparent;
padding: 0;
line-height: normal;
display: flex;
align-items: center;
justify-content: center;
>view:nth-of-type(2) { &::after {
width: 520rpx; border: none;
text-align: center; }
/* margin: auto; */
}
image { .avatar {
width: 48rpx; width: 160rpx;
height: 48rpx; height: 160rpx;
} border-radius: 50%;
} }
} }
}
.user_logo { .camera-icon {
/* background-color: #000000; */ width: 88rpx;
padding: 80rpx 0 60rpx 0; height: 94rpx;
text-align: center; position: relative;
bottom: 60rpx;
left: 60rpx;
}
}
&-title { .form-container {
font-weight: 400; width: 690rpx;
font-size: 36rpx; margin: 0 auto;
color: #FFFFFF; }
position: absolute;
top: 280rpx;
left: 50%;
transform: translateX(-50%);
font-weight: 400;
font-size: 30rpx;
color: #FFFFFF;
}
}
button::after { .form-item {
border: none; display: flex;
} padding: 30rpx 0;
position: relative;
button { &::after {
background-color: transparent; content: "";
padding-left: 0; display: block;
padding-right: 0; position: absolute;
line-height: inherit; left: 0;
border-radius: 0; bottom: 0;
display: flex; width: 100%;
flex-direction: column; height: 2rpx;
align-items: center; background: #666666;
justify-content: center; }
width: 160rpx;
height: 160rpx;
}
.user_logo>.avatar-wrapper { .form-label {
width: 165rpx; width: 120rpx;
height: 165rpx; font-size: 32rpx;
margin: auto; color: #ffffff;
border-radius: 128rpx; }
overflow: hidden;
border: 1rpx solid #fff;
}
.user_logo>.avatar-wrapper>image { .form-input {
width: 160rpx; flex: 1;
height: 160rpx;
border-radius: 50rpx;
overflow: hidden;
}
.user_logo>.camera { input {
width: 88rpx; flex: 1;
height: 94rpx; text-align: right;
position: relative; font-size: 28rpx;
bottom: 60rpx; color: #ffffff;
left: 60rpx; }
} }
}
.user_logo>view:nth-of-type(1) { .submit-btn {
font-size: 25rpx; width: 468rpx;
font-weight: 400; height: 112rpx;
color: #ffffff; background: #ff873a;
} border-radius: 50rpx;
border: 2rpx solid #ffffff;
.user_logo>view:nth-of-type(3) { font-size: 28rpx;
font-size: 22rpx; color: #ffffff;
font-weight: 400; margin: 200rpx auto 0;
color: #ffffff; display: flex;
margin-top: 20rpx; align-items: center;
} justify-content: center;
}
.nicheng_tit {
font-size: 32rpx;
font-weight: 400;
color: #999999;
padding: 0 36rpx;
margin-top: 70rpx;
}
.nicheng_ipt {
width: 690rpx;
height: 88rpx;
background: #333333;
border: 1px solid #333333;
border-radius: 10rpx;
margin: 0 auto;
padding: 0 36rpx;
box-sizing: border-box;
font-size: 28rpx;
font-weight: 400;
color: #fff;
border-radius: 9rpx;
margin-top: 22rpx;
}
.btn_b {
width: 468rpx;
height: 112rpx;
background: #ff873a;
border-radius: 50rpx;
border: 2rpx solid #FFFFFF;
font-weight: 400;
font-size: 28rpx;
color: #FFFFFF;
margin: 200rpx auto 0;
}
.row {
display: flex;
padding: 30rpx 0;
width: 690rpx;
margin: 0 auto;
position: relative;
&::after {
content: '';
display: block;
position: absolute;
left: 0;
bottom: 0;
width: 100%;
height: 2rpx;
background: #666666;
}
.row-title {
width: 120rpx;
font-size: 32rpx;
font-family: Source Han Sans CN;
font-weight: 400;
color: #ffffff;
}
.right {
flex: 1;
input {
flex: 1;
text-align: right;
font-size: 28rpx;
font-family: Source Han Sans CN;
font-weight: 400;
color: #ffffff;
}
}
}
</style> </style>