Browse Source

修改个人信息

master
chenkun 10 months ago
parent
commit
3caf34f677
1 changed files with 57 additions and 80 deletions
  1. +57
    -80
      pages_mine/mine/updateUserInfo.vue

+ 57
- 80
pages_mine/mine/updateUserInfo.vue View File

@ -6,18 +6,19 @@
<!--主页面--> <!--主页面-->
<view class="frame"> <view class="frame">
<view class="headImage"> <view class="headImage">
<view style="" class="key">头像</view> <view style="" class="key">头像</view>
<view style="" class="value" @click="chooseAndUpdateUserImage">
<image :src='form.headImage' style="width: 100%;height: 100%"></image>
<!-- <uv-upload :fileList="fileList" :maxCount="1" multiple width="150rpx" height="150rpx"
:deletable="false" :previewFullImage="false" @afterRead="afterRead" ></uv-upload> -->
</view>
<button style="" class="value" @chooseavatar="onChooseAvatar" open-type="chooseAvatar">
<image :src="form.headImage" v-if="form.headImage" style="width: 150%;height: 100%" mode="">
</image>
<image src="/static/image/tabbar/6.png" v-else style="width: 100%;height: 100%" mode="">
</image>
</button>
</view> </view>
<view class="item"> <view class="item">
<view class="label">昵称</view> <view class="label">昵称</view>
<view class="value"> <view class="value">
<uv-input v-model="form.nickName" placeholder="昵称" border="bottom" clearable></uv-input>
<input type="nickname" placeholder="请输入昵称" style="text-align: right;" id="nickName"
v-model="form.nickName" />
</view> </view>
</view> </view>
<view class="item" @click="sexChange"> <view class="item" @click="sexChange">
@ -75,88 +76,64 @@
} }
}, },
mounted() { mounted() {
this.form = this.userInfo
this.form.phone = this.userInfo.phone
this.form.headImage = this.userInfo.headImage
this.form.nickName = this.userInfo.nickName
this.form.sex = this.userInfo.sex
if (this.userInfo.sex == '' || this.userInfo.sex == null) { if (this.userInfo.sex == '' || this.userInfo.sex == null) {
this.userInfo.sex = '未知'
this.form.sex = '未知'
} }
console.log(this.userInfo.headImage, "this.userInfo.headImage");
// this.fileList.push({
// url: this.userInfo.headImage
// })
}, },
methods: { methods: {
onChooseAvatar(res) {
let self = this
console.log(res.target.avatarUrl, "res.target.avatarUrl");
self.$Oss.ossUpload(res.target.avatarUrl)
.then(url => {
console.log(url, "url");
self.form.headImage = url
})
},
// //
confirmEditUserInfo() { confirmEditUserInfo() {
this.$api('infoUpdateInfo', this.form, res => {
if (res.code == 200) {
// VueX
uni.showToast({
title: '修改成功',
icon: 'success'
let self = this
uni.createSelectorQuery().in(this)
.select("#nickName")
.fields({
properties: ["value"],
})
.exec((res) => {
const nickName = res?.[0]?.value
self.form.nickName = nickName
if (self.$utils.verificationAll(self.form, {
headImage: '请选择头像',
nickName: '请填写昵称'
})) {
return
}
self.$api('infoUpdateInfo', self.form, res => {
if (res.code == 200) {
uni.navigateTo({
url: '/pages/index/index'
})
}
}) })
setTimeout(() => {
uni.navigateTo({
url: '/pages/index/index'
})
}, 300)
}
})
},
//
chooseAndUpdateUserImage() {
const self = this;
uni.chooseImage({
count: 1, //
sizeType: ['original', 'compressed'], //
sourceType: ['album', 'camera'], //
success: (res) => {
//
const tempFilePath = res.tempFilePaths[0];
console.log(tempFilePath, "Selected Image");
//
self.updateUserImage(tempFilePath);
},
fail: (err) => {
console.error("Failed to select image:", err);
}
});
},
//
updateUserImage(filePath) {
const self = this;
console.log(filePath, "Selected Image Path");
})
//
self.$Oss.ossUpload(filePath).then(url => {
// URL
self.form.headImage = url;
console.log("Uploaded Image URL:", url);
}).catch(err => {
console.error("Failed to upload image:", err);
});
},
deleteImage(e) {
this.fileList.splice(e.index, 1)
},
afterRead(e) {
let self = this
e.file.forEach(file => {
self.$Oss.ossUpload(file.url).then(url => {
self.fileList.push({
url
this.$api('infoUpdateInfo', this.form, res => {
if (res.code == 200) {
uni.navigateTo({
url: '/pages/index/index'
}) })
})
}
}) })
}, },
sexChange() { sexChange() {
this.$refs.actionSheet.open() //ActionSheet this.$refs.actionSheet.open() //ActionSheet
}, },
@ -177,7 +154,6 @@
} }
</script> </script>
<style lang="scss" scoped> <style lang="scss" scoped>
* { * {
box-sizing: border-box; box-sizing: border-box;
@ -195,17 +171,18 @@
padding: 20rpx; padding: 20rpx;
.key { .key {
width: 70%;
height: 150rpx;
width: 500rpx;
display: flex; display: flex;
align-items: center; align-items: center;
} }
.value { .value {
border-radius: 50%;
border-radius: 50rpx;
border: 1px solid red; border: 1px solid red;
box-sizing: border-box;
overflow: hidden; overflow: hidden;
width: 30%;
width: 100rpx;
height: 100rpx;
} }
} }


Loading…
Cancel
Save