Browse Source

用户名和头像获取不到修改

begmoon 2 years ago
parent
commit
35ff8190f6
6 changed files with 146 additions and 75 deletions
  1. 1 1
      pages/homepage/homepage.js
  2. 113 72
      pages/login/user.js
  3. 11 0
      pages/login/user.wxml
  4. 19 0
      pages/login/user.wxss
  5. 1 1
      pages/style/style.wxml
  6. 1 1
      project.private.config.json

+ 1 - 1
pages/homepage/homepage.js

@@ -95,7 +95,7 @@ Page({
    * 生命周期函数--监听页面显示
    */
   onShow: function () {
-  
+    this.getUserData(this.data.user_id)
   },
 
   /**

+ 113 - 72
pages/login/user.js

@@ -3,6 +3,8 @@ const app = getApp()
 var host = app.globalData.host;
 const $api = require('../../utils/api.js').API;
 var logindata={}
+const defaultAvatarUrl = 'https://mmbiz.qpic.cn/mmbiz/icTdbqWNOwNRna42FI242Lcia07jQodd2FJGIYQfG0LAJGFxM4FbnQP6yfMxBgJ0F3YRqJCJ1aPAK2dQagdusBZg/0'
+
 Page({
 
   /**
@@ -20,7 +22,9 @@ Page({
     status:0,
     text:'获取验证码',
     player_type:0,
-    signinfo:{}
+    signinfo:{},
+    avatarUrl: defaultAvatarUrl,
+    userName:'',
   },
 
   /**
@@ -81,8 +85,20 @@ Page({
     
   },
 
+  onChooseAvatar(e) {
+    const { avatarUrl } = e.detail 
+    this.setData({
+      avatarUrl,
+    })
 
-
+    this.uploadImg(this.data.avatarUrl)
+  },
+  
+  nameChange(e){
+    this.setData({
+      userName: e.detail.value
+    })
+  },
 
   inputchange(e) {
     this.setData({
@@ -109,13 +125,6 @@ Page({
   /**登陆 */
   login: function () {
     var _this=this;
-    // if (!this.data.usercode) {
-    //   wx.showToast({
-    //     icon: 'none',
-    //     title: '请输入用户代码',
-    //   })
-    //   return;
-    // }
     wx.getUserProfile({
       desc: '用于完善会员资料',
       success: res=> {
@@ -127,76 +136,97 @@ Page({
           avatarUrl: res.userInfo.avatarUrl,
           usercode: this.data.usercode
         }
-        wx.showLoading({
-          title: '正在登陆',
-        })
-        wx.login({
-          success(res) {
-            //获取code
-            $api.getOpenid({ code: res.code})
-            .then(res => {
-              //获取openid
-              if (res.data.code != 0) {
-                wx.showToast({
-                  icon: 'none',
-                  title: res.data.message,
-                })
-                wx.hideLoading();
-                return;
-              }
-              data.openid = res.data.data.openid;
-              logindata=data
-              $api.login(data)
-              .then(res=>{
-                //登录成功
-                wx.setStorage({
-                  key: 'userInfo',
-                  data: res.data.data,
-                })
-                //老用户直接进入系统
-              
-                if(res.data.data.role != 0){
-                  wx.switchTab({
-                    url: '../index/index',
-                  })
-                  
-                  return;
-                }
-                //新用户选择报名
-                _this.setData({
-                  status:3,
-                  player_type:0
-                })
-                wx.hideLoading();
-                wx.setNavigationBarTitle({
-                  title: '',
-                })
-                if (res.data.code != 0) {
-                  wx.showToast({
-                    icon: 'none',
-                    title: res.data.message,
-                  })
-                  return;
-                }
-                
+        
+        if(data.nickName == "微信用户" | data.nickName == ""){
+          _this.setData({
+            status:10,
+          })
+        } else{
+          _this.wxlogin(data)
+        } 
+      }
+    })
+
+  },
+
+  register(e){
+    var data = {
+      nickName: this.data.userName,
+      avatarUrl: this.data.avatarUrl,
+      usercode: this.data.usercode
+    }
+
+    this.wxlogin(data)
+  },
+
+  wxlogin(data){
+    var _this=this;
+    wx.showLoading({
+      title: '正在登陆',
+    })
+    wx.login({
+      success(res) {
+        //获取code
+        $api.getOpenid({ code: res.code})
+        .then(res => {
+          //获取openid
+          if (res.data.code != 0) {
+            wx.showToast({
+              icon: 'none',
+              title: res.data.message,
+            })
+            wx.hideLoading();
+            return;
+          }
+          data.openid = res.data.data.openid;
+          $api.login(data)
+          .then(res=>{
+            //登录成功
+            
+            wx.setStorage({
+              key: 'userInfo',
+              data: res.data.data,
+            })
+            
+            //老用户直接进入系统
           
-                
-                
-              })
-              .catch(err=>{
-                wx.hideLoading();
+            if(res.data.data.role != 0){
+              wx.switchTab({
+                url: '../index/index',
               })
+              
+              return;
+            }
+
+            //新用户选择报名
+            _this.setData({
+              status:3,
+              player_type:0
             })
-            .catch(err => {
-              //请求失败
-              wx.hideLoading();
+            wx.hideLoading();
+            wx.setNavigationBarTitle({
+              title: '',
             })
-        
-          }
+            if (res.data.code != 0) {
+              wx.showToast({
+                icon: 'none',
+                title: res.data.message,
+              })
+              return;
+            }
+          
+          })
+          .catch(err=>{
+            wx.hideLoading();
+          })
+        })
+        .catch(err => {
+          //请求失败
+          wx.hideLoading();
         })
+    
       }
     })
-
   },
   login1(){
     logindata.phone=this.data.phone
@@ -247,6 +277,17 @@ Page({
       }
     })
   },
+
+  uploadImg(path){
+    $api.uploadAvatar(path,'file').then(res=>{
+      if(res.code == 0){
+        this.setData({
+          avatarUrl: res.data.url
+        })
+      }
+    })
+  },
+  
   onCustomerService(){
     wx.openCustomerServiceChat({
       extInfo: {url: 'https://work.weixin.qq.com/kfid/kfcc1bd2a8bddad1dfb'},

+ 11 - 0
pages/login/user.wxml

@@ -50,3 +50,14 @@
   <navigator style="background: none;color:#D94B24;" url="../message/message"><image style="width: 18px;" mode="widthFix" src="../../images/zx.png"></image>  咨询顽主</navigator>
 </view>
 
+<!-- 上传头像和昵称 -->
+<view wx:if='{{status == 10}}'>
+  <text class="weui-input">头像:</text>
+  <button class="avatar-wrapper" open-type="chooseAvatar" bind:chooseavatar="onChooseAvatar">
+  <image class="avatar" src="{{avatarUrl}}"></image>
+  </button> 
+  <view class="weui-input"><text>昵称:</text><input type="nickname"  bindinput="nameChange" placeholder="请输入昵称"/>
+  </view>
+  <button class="btn" bindtap="register">登录</button>
+</view>
+

+ 19 - 0
pages/login/user.wxss

@@ -4,6 +4,9 @@ page{
   /* position: fixed; */
 }
 
+.avatar-wrapper{
+  margin-top: 20rpx;
+}
 .avatar{
   width: 120rpx;
   height: 120rpx;
@@ -168,6 +171,12 @@ page{
   color: #E90001 !important;
 }
 
+.weui-input{
+  margin: 30rpx;
+  display: flex;
+  font-size: 34rpx;
+}
+
 
 
 .contactus{
@@ -245,4 +254,14 @@ page{
   border-color: #999;
 }
 
+.btn{
+  width: 100%;
+  height: 70rpx;
+  background: #D94B24;
+  border-radius: 8rpx;
+  color: #fff;
+  font-size: 32rpx;
+  margin-top: 50rpx;
+}
+
 

+ 1 - 1
pages/style/style.wxml

@@ -10,7 +10,7 @@
       </view>
   </view>
 </view>
-<view class="item" wx:if="{{form.is_player==1}}"> 
+<view class="item"> 
    <label>参赛名</label>
    <view class="tags"> 
       <input value="{{form.username}}" bindinput="bindinput" placeholder-style="color:#999;" placeholder="请填写"></input> 

+ 1 - 1
project.private.config.json

@@ -1,5 +1,5 @@
 {
-  "projectname": "wanzb_xcxv3",
+  "projectname": "xiaochengxu-4",
   "setting": {
     "compileHotReLoad": true
   },