浏览代码

feat(福利go) 修改头像授权问题

xing.li 3 年之前
父节点
当前提交
e45a22d064

+ 20 - 1
api/activity.js

@@ -167,18 +167,37 @@ class activity extends request {
    * @param {*} openId 
    * @param {*} mobile 
    */
-  static async saveUser(openId,mobile) {
+  static async saveUser(openId,mobile,headerImg="",nickName="") {
     let params = {
       openid:openId,
       mobile:mobile,
       source:'FREE_MINI_APP'
     };
+    if(headerImg){
+      params.headerImg = headerImg;
+    }
+    if(nickName){
+      params.nickName = nickName;
+    }
 
     const res = await this.postRequest(`${this.BASE_URL}open/activity/save-user`, params)
     return res.data
    
   }
 
+  static async getUserInfo(mobile) {
+    let params = {
+      mobile:mobile,
+      source:'FREE_MINI_APP'
+    };
+   
+    const res = await this.postRequest(`${this.BASE_URL}open/activity/get-user`, params)
+    return res.data
+   
+  }
+
+  
+
   /**
    * 设置手机缓存
    * @param {*} mobile 

+ 17 - 0
pages/welfareMall/coupon/coupon.js

@@ -106,6 +106,23 @@ Page({
     
 },
 
+getUserProfile: function(e){
+  wx.getUserProfile({
+    desc: '用于完善会员资料', // 声明获取用户个人信息后的用途,后续会展示在弹窗中,请谨慎填写
+    success: (res) => {
+      console.log(res);
+      // res.userInfo['encryptedData'] = res.encryptedData
+      // res.userInfo['iv'] = res.iv
+      app.wxLogin(res.userInfo);
+      this.setData({
+        userInfo: res.userInfo,
+        hasUserInfo: true
+      })
+      this.userRecruitInfo(res.userInfo.openId)
+    }
+  })
+},
+
   userCouponListView: function(data) {
     if (!Array.isArray(data) || data.length == 0) {
         console.log("订单列表数据为空");

+ 25 - 2
pages/welfareMall/personal/personal.js

@@ -15,7 +15,8 @@ Page({
     grayTheme:false,
     navigationList:[],
     couponPath: false,
-    avatarUrl : 'https://mmbiz.qpic.cn/mmbiz/icTdbqWNOwNRna42FI242Lcia07jQodd2FJGIYQfG0LAJGFxM4FbnQP6yfMxBgJ0F3YRqJCJ1aPAK2dQagdusBZg/0'
+    avatarUrl : 'https://mmbiz.qpic.cn/mmbiz/icTdbqWNOwNRna42FI242Lcia07jQodd2FJGIYQfG0LAJGFxM4FbnQP6yfMxBgJ0F3YRqJCJ1aPAK2dQagdusBZg/0',
+    hasUserInfo:false
 
   },
   onChooseAvatar(e) {
@@ -169,6 +170,8 @@ Page({
       })
     }
 
+    // let  info = await activity.getUserInfo();
+
     if(this.data.isLogin){
       let nums = await this.getCountNum();
       this.setData({
@@ -195,11 +198,31 @@ Page({
     wx.removeStorageSync('userInfo');
     this.setData({
       isLogin:false,
-      countNum:0
+      countNum:0,
+      hasUserInfo:false
     })
    
   },
 
+  getUserProfile: function(e){
+    wx.getUserProfile({
+      desc: '用于完善会员资料', // 声明获取用户个人信息后的用途,后续会展示在弹窗中,请谨慎填写
+      success: (res) => {
+        console.log(res);
+        var openId = wx.getStorageSync('loginInfo').openId;
+        var mobile = getMobileCache();
+        if(openId && mobile){
+          activity.saveUser(openId,mobile,res.userInfo.avatarUrl,res.userInfo.nickName);
+        }
+        this.setData({
+          userInfo: res.userInfo,
+          hasUserInfo: true
+        })
+        // this.userRecruitInfo(res.userInfo.openId)
+      }
+    })
+  },
+
   /**
    * 生命周期函数--监听页面隐藏
    */

+ 26 - 17
pages/welfareMall/personal/personal.wxml

@@ -4,30 +4,39 @@
     <view slot="body" class="personal flex-column">
       <!-- 首部个人信息 -->
 
-      <!-- <button class="avatar-wrapper" open-type="chooseAvatar" bind:chooseavatar="onChooseAvatar">
-      <image class="avatar" src="{{avatarUrl}}" style="height: 100rpx;width: 100rpx;"></image>
-     </button> 
-    <input type="nickname" class="weui-input" placeholder="请输入昵称"/> -->
       <view class="head flex-column">
-        <view class="head-personal flex-row">
-        
-          <image class="head-personal-logo" src="/images/welfareMall/head-portrait.png" />
+        <view class="head-personal flex-row" wx:if="{{hasUserInfo}}">
+      
           <!-- 获取用户头像 -->
-          <view class="hat" wx:if="{{isLogin}}"></view>
-          <!-- <open-data wx:if="{{isLogin}}" class="head-personal-logo" type="userAvatarUrl"></open-data> -->
-          <view class="head-personal-nl flex-column" wx:if="{{isLogin}}">
+          <!-- <view class="hat"></view> -->
+          <image class="head-personal-logo" src="{{userInfo.avatarUrl}}"> </image>
+          <view class="head-personal-nl flex-column">
+            <!-- 获取用户微信昵称 -->
+            <view class="head-personal-name">{{userInfo.nickName}}</view>
+            <view class="flex-row">
+              <view class="head-personal-name" wx:if="{{isLogin}}">{{phone.toHide(mobileTop)}}</view>
+              <button class="head-personal-login" style="background-color: transparent;" wx:if="{{!isLogin}}" open-type="getPhoneNumber" bindgetphonenumber="getPhoneNumber">授权手机号</button>
+              <view class="logout" wx:if="{{isLogin}}" bindtap="logout">重新授权</view>
+            </view>
+          </view>
+      
+        </view>
+      
+        <view class="head-personal flex-row" wx:else>
+          <image class="head-personal-logo" src="/images/welfareMall/head-portrait.png"> </image>
+          <view class="head-personal-nl flex-column">
             <!-- 获取用户微信昵称 -->
-            <!-- <open-data class="head-personal-name" type="userNickName" lang="zh_CN"></open-data> -->
-            <view class="head-personal-login">{{phone.toHide(mobileTop)}}</view>
+            <button class="personal-isLogin"  wx:if="{{isLogin}}" bindtap="getUserProfile">头像/昵称</button>
+            <view class="flex-row">
+              <view class="head-personal-name" wx:if="{{isLogin}}">{{phone.toHide(mobileTop)}}</view>
+              <button class="personal-isLogin" wx:if="{{!isLogin}}" open-type="getPhoneNumber" bindgetphonenumber="getPhoneNumber">登录/注册</button>
+              <view class="logout" wx:if="{{isLogin}}" bindtap="logout">重新授权</view>
+            </view>
           </view>
        
-          <button class="personal-isLogin" wx:if="{{!isLogin}}" open-type="getPhoneNumber" bindgetphonenumber="getPhoneNumber">登录/注册</button>
-          <view class="logout" wx:if="{{isLogin}}" bindtap="logout">退出登录</view>
-          <!-- <image wx:if="{{isLogin}}" src="/images/welfareMall/logout.png" style="height: 30px;width: 30px;margin-left: 90px;" bindtap="logout"></image> -->
         </view>
         <view>
-        <button class="wx-isLogin-card" wx:if="{{!isLogin}}" open-type="getPhoneNumber" bindgetphonenumber="getPathCoupon"></button>
-
+        
           <view class="head-card flex-row" catchtap="{{couponPath?'getCouponPath':''}}">
             <view class="head-card-coupon">我的优惠券</view>
             <view class="head-card-nt flex-row">

+ 15 - 9
pages/welfareMall/personal/personal.wxss

@@ -60,30 +60,35 @@ page{
   width: 136rpx;
   height: 136rpx;
   border-radius: 50%;
-  overflow :  hidden ;
-  position: absolute;
-  z-index: 3;
+  /* overflow :  hidden ; */
+  /* position: absolute; */
+  /* z-index: 3; */
 }
 
 .personal-isLogin {
   padding: 0 !important;
   padding-left: 0 !important;
-  width: 170rpx !important;
+  /* width: 170rpx !important; */
   font-size: 38rpx;
   font-weight: 500;
   color: #303030;
-  margin-left: 33rpx !important;
-  margin-right: 0rpx !important;
+  /* margin-left: 33rpx !important; */
+  /* margin-right: 0rpx !important; */
 }
 
 .head-personal-nl{
-  margin-left: 86rpx;
+  /* margin-left: 150rpx; */
   align-items: flex-start;
+  width: 300rpx;
+  height: 136rpx;
+  justify-content: space-around;
 }
 
 .head-personal-name{
   font-size: 30rpx;
   font-weight: 500;
+  width: 368rpx;
+  text-align: center;
   color: #303030;
 }
 
@@ -92,6 +97,7 @@ page{
   font-size: 26rpx;
   font-weight: 400;
   color: #303030;
+  
 }
 
 .head-card{
@@ -219,7 +225,7 @@ page{
   color: #303030;
   background-color: transparent;
   border-style: none;
-  margin-left: 186rpx !important;
+  /* margin-left: 186rpx !important; */
 }
 
 .broadcast{
@@ -264,7 +270,7 @@ page{
   height: 40rpx;
   line-height: 40rpx;
   width: 100rpx;
-  margin-top: 18rpx;
+  /* margin-top: 18rpx; */
   margin-left: 12rpx;
   font-size: 22rpx;
   text-align: center;