flyx/pages/user/change.vue
2024-07-07 16:19:19 +08:00

350 lines
6.4 KiB
Vue

<template>
<view class="content">
<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="avatar-wrapper" @click="chooseAvatar">
<image class="avatar" :src="avatarUrl"></image>
</view>
<text class="user_logo-title">修改头像</text>
<image class="camera" :src="$img1('my/camera.png')" mode="aspectFill"></image>
</view>
<view class="row">
<view class="row-title">昵称:</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>
</template>
<script>
export default {
data() {
return {
statusBarHeight: uni.getSystemInfoSync().statusBarHeight,
avatarUrl: uni.getStorageSync('userinfo').headimg,
nickname: uni.getStorageSync('userinfo').nickname,
headimg_status: false,
id: uni.getStorageSync('userinfo').ID
}
},
onLoad() {},
methods: {
back() {
uni.navigateBack()
},
getnickname(e) {
this.nickname = e.detail.value
console.log(e, this.nickname)
},
onChooseAvatar(e) {
console.log(e)
this.avatarUrl = e.detail.avatarUrl
this.headimg_status = true
},
chooseAvatar() {
let that = this
uni.chooseImage({
count: 1,
success: (res) => {
console.log(res);
uni.showLoading({
title:'上传中...',
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()
}
})
}
})
},
setdata() {
let that = this
if (this.headimg_status) {
that.req({
url: 'update_userinfo',
data: {
nickname: that.nickname,
headimg: that.avatarUrl
},
success(ress) {
if (ress.status == 1) {
uni.showToast({
title: '修改成功',
icon: 'success',
success() {
setTimeout(() => {
that.$c.back()
}, 500)
}
})
}
}
})
} else {
that.req({
url: 'update_userinfo',
data: {
nickname: that.nickname,
headimg: that.avatarUrl
},
success(ress) {
if (ress.status == 1) {
uni.showToast({
title: '修改成功',
icon: 'success',
success() {
setTimeout(() => {
uni.redirectTo({
url: './index'
})
}, 1000)
}
})
}
}
})
}
}
}
}
</script>
<style lang="scss">
.content {
width: 100vw;
height: 100vh;
box-sizing: border-box;
color: #fff;
.head {
position: fixed;
top: 0;
z-index: 20;
.header_title {
height: 70rpx;
line-height: 70rpx;
width: 100%;
box-sizing: border-box;
font-weight: bold;
display: flex;
align-items: center;
padding-left: 30rpx;
box-sizing: border-box;
>view:nth-of-type(1) {
display: flex;
align-items: center;
}
>view:nth-of-type(2) {
width: 520rpx;
text-align: center;
/* margin: auto; */
}
image {
width: 48rpx;
height: 48rpx;
}
}
}
}
.user_logo {
/* background-color: #000000; */
padding: 80rpx 0 60rpx 0;
text-align: center;
&-title{
font-weight: 400;
font-size: 36rpx;
color: #FFFFFF;
position: absolute;
top: 280rpx;
left: 50%;
transform: translateX(-50%);
font-weight: 400;
font-size: 30rpx;
color: #FFFFFF;
}
}
button::after {
border: none;
}
button {
background-color: transparent;
padding-left: 0;
padding-right: 0;
line-height: inherit;
border-radius: 0;
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
width: 160rpx;
height: 160rpx;
}
.user_logo>.avatar-wrapper {
width: 165rpx;
height: 165rpx;
margin: auto;
border-radius: 128rpx;
overflow: hidden;
border: 1rpx solid #fff;
}
.user_logo>.avatar-wrapper>image {
width: 160rpx;
height: 160rpx;
border-radius: 50rpx;
overflow: hidden;
}
.user_logo>.camera {
width: 88rpx;
height: 94rpx;
position: relative;
bottom: 60rpx;
left: 60rpx;
}
.user_logo>view:nth-of-type(1) {
font-size: 25rpx;
font-weight: 400;
color: #ffffff;
}
.user_logo>view:nth-of-type(3) {
font-size: 22rpx;
font-weight: 400;
color: #ffffff;
margin-top: 20rpx;
}
.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: #894DD3;
border-radius: 49rpx;
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>