123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211 |
- <template>
- <view >
- <view class="content">
- <view class="info-item">
- <view class="item">
- <image class="head" :src="user.avatar==null?'https://fs-1319721001.cos.ap-chongqing.myqcloud.com/fs/20240229/22cb9518a55040dea74d8f730551a7a2.jpg':user.avatar" mode=""></image>
- <button class="wx-head" type="balanced" open-type="chooseAvatar" @chooseavatar="onChooseAvatar">
- </button>
- </view>
- </view>
- <view class="info-item">
- <view class="item">
- <input type="nickname" @blur="bindblur" @input="bindinput" placeholder="请点击授权昵称" v-model="nickName" class="input" />
- </view>
- </view>
- <view class="btn-box">
- <view class="btn" @click="submit()">保存</view>
- </view>
- </view>
-
- </view>
- </template>
- <script>
- import {getUserInfo,editUser} from '@/api/user.js'
- export default {
- data() {
- return {
- user:{
- nickName:"",
- avatar:null,
- user:null,
- }
- }
- },
- onLoad() {
-
- },
- methods: {
- bindblur(e) {
- this.nickName = e.detail.value; // 获取微信昵称
- },
- bindinput(e){
- this.nickName = e.detail.value; //这里要注意如果只用blur方法的话用户在输入玩昵称后直接点击保存按钮,会出现修改不成功的情况。
- },
- onChooseAvatar(e){
- let {
- avatarUrl
- } = e.detail;
- uni.uploadFile({
- url: uni.getStorageSync('requestPath')+'/app/common/uploadOSS', //仅为示例,非真实的接口地址
- filePath: avatarUrl,
- name: 'file',
- formData: {
- 'user': 'test' // 上传附带参数
- },
- success: (uploadFileRes) => {
- this.user.avatar =JSON.parse(uploadFileRes.data).url
- }
- });
- },
- // chooseImage() {
- // var that = this;
- // uni.chooseImage({
- // count: 1, // 默认9
- // sizeType: ['compressed'], //可以指定是原图还是压缩图,默认二者都有
- // sourceType: ['album', 'camera'], //从相册选择
- // success: (res) => {
- // uni.uploadFile({
- // url: uni.getStorageSync('requestPath')+'/api/common/uploadOSS', //仅为示例,非真实的接口地址
- // filePath: res.tempFilePaths[0],
- // name: 'file',
- // formData: {
- // 'user': 'test' // 上传附带参数
- // },
- // success: (uploadFileRes) => {
- // console.log(uploadFileRes)
- // this.user.avatar =JSON.parse(uploadFileRes.data).data.url
- // }
- // });
-
- // }
- // });
- // },
- submit(){
- if(this.nickName==null||this.nickName==""){
- uni.showToast({
- icon:'none',
- title: "请输入昵称",
- });
- return;
- }
- this.user.nickName=this.nickName;
- this.user.isWeixinAuth=1;
- editUser(this.user).then(
- res => {
- if(res.code==200){
- uni.setStorageSync('avatar',this.avatar);
- uni.setStorageSync('nickName',this.nickName);
- this.$emit('updateUser');
- }else{
- uni.showToast({
- icon:'none',
- title: "请求失败",
- });
- }
- },
- rej => {}
- );
- },
- getUserInfo(){
- getUserInfo().then(
- res => {
- if(res.code==200){
- if(res.user!=null){
- this.user=res.user;
- console.log(this.user)
- }
- else{
- this.utils.loginOut();
- }
-
- }else{
- uni.showToast({
- icon:'none',
- title: "请求失败",
- });
- }
- },
- rej => {}
- );
- },
-
- }
- }
- </script>
- <style lang="scss" scoped>
- .content{
- width: 100%;
- padding: 0 60upx;
- }
- .info-item{
- width: 100%;
- height: 104upx;
- background: #FFFFFF;
-
- display: flex;
- align-items: center;
- justify-content: center;
- margin: 15rpx 0rpx;
- .item{
-
- display: flex;
- align-items: center;
- justify-content: center;
- width: 100%;
- .input{
- width: 100%;
- height: 50rpx;
- padding: 15rpx 30rpx;
- border-radius: 30rpx;
- background-color: #F5F6FA;
- text-align: left;
- font-size: 30upx;
- font-family: PingFang SC;
- font-weight: 400;
- color: #0F1826;
- }
- .wx-head{
- position: absolute;
- width: 120upx;
- height: 120upx;
- opacity: 0;
- }
- }
- .head{
- border-radius: 50%;
- width: 120upx;
- height: 120upx;
- }
-
- .input{
- text-align: right;
- font-size: 30upx;
- font-family: PingFang SC;
- font-weight: 400;
- color: #0F1826;
- }
-
- }
- .btn-box{
- height: 140upx;
- width: 100%;
- display: flex;
- align-items: center;
- justify-content: center;
- .btn{
- width: 100%;
- height: 80upx;
- line-height: 80upx;
- text-align: center;
- font-size: 34upx;
- font-family: PingFang SC;
- font-weight: 400;
- color: #FFFFFF;
- background: #C39A58;
- border-radius: 60upx;
- }
- }
- </style>
|