Bläddra i källkod

feat(福利go) 修改个人中心的 手机授权管理

xing.li 3 år sedan
förälder
incheckning
5d08ef7de9

+ 0 - 10
.idea/runConfigurations.xml

@@ -1,10 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<project version="4">
-  <component name="RunConfigurationProducerService">
-    <option name="ignoredProducers">
-      <set>
-        <option value="com.android.tools.idea.compose.preview.runconfiguration.ComposePreviewRunConfigurationProducer" />
-      </set>
-    </option>
-  </component>
-</project>

+ 10 - 0
api/activity.js

@@ -152,6 +152,16 @@ class activity extends request {
     return res.data
   }
 
+    /**
+   * 解锁手机号  新接口
+   * @param {*} orderSn 
+   */
+  static async getAuthMobileNew(params) {
+   
+    const res = await this.postRequest(`${this.BASE_URL}open/wxapp/auth-mobile-new`, params)
+    return res.data
+  }
+
   /**
    * 保存用户信息
    * @param {*} openId 

+ 27 - 0
app.js

@@ -53,6 +53,33 @@ App({
       }
     })
   },
+
+  
+
+  async doDecodePhoneNew(code,call='') {
+ 
+    //验证登录是否失效
+      var params = {
+        code:code,
+        appCode:this.globalData.appCode
+      };
+      try {
+        let res = Activity.getAuthMobileNew(params);   
+        res.then(userInfo=>{
+          console.log(userInfo)
+          let mobile = userInfo.phoneNumber;
+          // @todo从缓存里面取openId
+          let openId = Activity.getOpenId();
+          //保存用户信息
+          Activity.saveUser(openId,mobile);
+          Activity.setMobileCache(mobile);
+          call();
+        })
+      }catch(err) {
+        console.log(err);
+      }
+    
+  },
   /**
    * 接口请求手机号
    * @param {*} encryptedData

+ 25 - 10
pages/activityList/activityList.js

@@ -1,5 +1,7 @@
 const { default: activity } = require("../../api/activity");
 
+import {getMobileCache, getPhoneNumberNew as getPhoneNumberSync} from '../../utils/user'
+
 // pages/activityList/activityList.js
 Page({
 
@@ -94,15 +96,9 @@ Page({
   },
   //获取手机号
   getPhoneNumber(e) {
+
     let _self = this;
-    var encryptedData = e.detail.encryptedData;
-    console.log(encryptedData);
-    var iv = e.detail.iv;
-    if (!encryptedData || encryptedData.length == 0 || !iv || iv.length == 0) {
-      return;
-    }
-    //获取手机号
-    getApp().doDecodePhone(encryptedData, iv, function () {
+    getPhoneNumberSync(e, async () => {
       let userMobile = activity.getMobileCache();
       console.log(userMobile)
       if (userMobile.length !== 0) {
@@ -112,8 +108,27 @@ Page({
         //判断该手机号在不在分享名单里
         _self.isShareByMobile();
       }
-    
-    });
+    })
+    // let _self = this;
+    // var encryptedData = e.detail.encryptedData;
+    // console.log(encryptedData);
+    // var iv = e.detail.iv;
+    // if (!encryptedData || encryptedData.length == 0 || !iv || iv.length == 0) {
+    //   return;
+    // }
+    //获取手机号
+    // getApp().doDecodePhone(encryptedData, iv, function () {
+    //   let userMobile = activity.getMobileCache();
+    //   console.log(userMobile)
+    //   if (userMobile.length !== 0) {
+    //     _self.setData({
+    //       userMobile: userMobile,
+    //     })
+    //     //判断该手机号在不在分享名单里
+    //     _self.isShareByMobile();
+    //   }
+    //
+    // });
   },
 
   //获取活动列表

+ 3 - 1
pages/luckDraw/detail.js

@@ -2,7 +2,8 @@
 import LuckDraw from '../../api/luck-draw'
 import Common from './common'
 import Statistics from '../../components/statistics/index'
-import {getMobileCache, getPhoneNumber as getPhoneNumberSync} from '../../utils/user'
+import {getMobileCache, getPhoneNumberNew as getPhoneNumberSync} from '../../utils/user'
+
 const app = getApp();
 
 const DEFAULT_GIFTS = [
@@ -311,6 +312,7 @@ Page({
 
     // 授权手机号
     getPhoneNumber(e) {
+
         getPhoneNumberSync(e, _ => {
             this.setData({ isLogin: true })
             this.getDrawTimes()

+ 1 - 1
pages/luckDraw/profile.js

@@ -1,7 +1,7 @@
 // pages/luckDraw/profile.js
 import LuckDraw from '../../api/luck-draw'
 import { parseTime } from '../../utils/util'
-import {getMobileCache, getPhoneNumber as getPhoneNumberSync} from '../../utils/user'
+import {getMobileCache, getPhoneNumberNew as getPhoneNumberSync} from '../../utils/user'
 Page({
 
     /**

+ 1 - 1
pages/luckDraw/recordPrize.js

@@ -1,7 +1,7 @@
 // pages/luckDraw/recordPrize.js
 import LuckDraw from '../../api/luck-draw'
 import { parseTime } from '../../utils/util'
-import {getMobileCache, getPhoneNumber as getPhoneNumberSync} from '../../utils/user'
+import {getMobileCache, getPhoneNumberNew as getPhoneNumberSync} from '../../utils/user'
 Page({
 
     /**

+ 21 - 10
pages/receiveCoupon/receiveCoupon.js

@@ -1,6 +1,7 @@
 const { default: activity } = require("../../api/activity");
 const util = require('../../utils/util.js')
 const app = getApp();
+import { getMobileCache, getPhoneNumberNew as getPhoneNumberSync } from '../../utils/user'
 Page({
 
   /**
@@ -149,14 +150,7 @@ Page({
   //获取手机号
   getPhoneNumber(e) {
     let _self = this;
-    var encryptedData = e.detail.encryptedData;
-    console.log(encryptedData);
-    var iv = e.detail.iv;
-    if (!encryptedData || encryptedData.length == 0 || !iv || iv.length == 0) {
-      return;
-    }
-    //获取手机号
-    getApp().doDecodePhone(encryptedData, iv, function () {
+    getPhoneNumberSync(e, _ => {
       let userMobile = activity.getMobileCache();
       if (userMobile.length !== 0) {
         _self.setData({
@@ -164,8 +158,25 @@ Page({
         })
         _self.createOrder();
       }
-
-    });
+    })
+    // let _self = this;
+    // var encryptedData = e.detail.encryptedData;
+    // console.log(encryptedData);
+    // var iv = e.detail.iv;
+    // if (!encryptedData || encryptedData.length == 0 || !iv || iv.length == 0) {
+    //   return;
+    // }
+    // //获取手机号
+    // getApp().doDecodePhone(encryptedData, iv, function () {
+    //   let userMobile = activity.getMobileCache();
+    //   if (userMobile.length !== 0) {
+    //     _self.setData({
+    //       memberMobile: userMobile,
+    //     })
+    //     _self.createOrder();
+    //   }
+    //
+    // });
   },
 
   /**

+ 1 - 1
pages/signIn/activity/activity.js

@@ -2,7 +2,7 @@
 import SignIn from '../../../api/signIn'
 import Statistics from '../../../components/statistics/index'
 import { isEmpty } from '../../../utils/util'
-import { getMobileCache, getPhoneNumber as getPhoneNumberSync } from '../../../utils/user'
+import { getMobileCache, getPhoneNumberNew as getPhoneNumberSync } from '../../../utils/user'
 const app = getApp();
  
 Page({

+ 1 - 1
pages/signIn/record/record.js

@@ -1,7 +1,7 @@
 // pages/signIn/record/record.js
 import SignIn from '../../../api/signIn'
 import { parseTime } from '../../../utils/util'
-import {getMobileCache, getPhoneNumber as getPhoneNumberSync} from '../../../utils/user'
+import {getMobileCache, getPhoneNumberNew as getPhoneNumberSync} from '../../../utils/user'
 Page({
 
     /**

+ 26 - 13
pages/welfareMall/activityInfo/activityInfo.js

@@ -4,6 +4,7 @@ import Activity from '../../../api/activity';
 import Statistics from '../../../components/statistics/index'
 const util = require('../../../utils/util.js');
 const app = getApp();
+import {getMobileCache, getPhoneNumberNew as getPhoneNumberSync} from '../../../utils/user'
 Page({
 
   /**
@@ -135,32 +136,44 @@ Page({
        couponList,
      })
   },
+
+  
   /**
    * 获取手机号
    * @param {*} e 
    */
   getPhoneNumber(e) {
-    // this.setData({
-    //   hideWindowValue:true
-    // })
-    // return;
     let _self = this;
-    var encryptedData = e.detail.encryptedData;
-    var iv = e.detail.iv;
-    if (!encryptedData || encryptedData.length == 0 || !iv || iv.length == 0) {
-      return;
-    }
-    //获取手机号
-    app.doDecodePhone(encryptedData, iv, function () {
+      getPhoneNumberSync(e, async () => {
       let userMobile = Activity.getMobileCache();
       if (userMobile.length !== 0) {
         _self.setData({
           userMobile: userMobile,
         })
         _self.nowBuy();
-      }
+      } 
+  })
+    // this.setData({
+    //   hideWindowValue:true
+    // })
+    // return;
+    // let _self = this;
+    // var encryptedData = e.detail.encryptedData;
+    // var iv = e.detail.iv;
+    // if (!encryptedData || encryptedData.length == 0 || !iv || iv.length == 0) {
+    //   return;
+    // }
+    //获取手机号
+    // app.doDecodePhone(encryptedData, iv, function () {
+    //   let userMobile = Activity.getMobileCache();
+    //   if (userMobile.length !== 0) {
+    //     _self.setData({
+    //       userMobile: userMobile,
+    //     })
+    //     _self.nowBuy();
+    //   }
     
-    });
+    // });
   },
 
   /**

+ 10 - 3
pages/welfareMall/personal/personal.js

@@ -1,7 +1,7 @@
 // pages/welfareMall/personal/personal.js
 import WelfareMall from '../../../api/welfareMall'
 import activity from '../../../api/activity'
-import {getMobileCache, getPhoneNumber as getPhoneNumberSync} from '../../../utils/user'
+import {getMobileCache, getPhoneNumberNew as getPhoneNumberSync} from '../../../utils/user'
 const app = getApp();
 Page({
 
@@ -10,13 +10,20 @@ Page({
    */
   data: {
     isLogin: false,
-    mobileTop: 'TONY WU',
+    mobileTop: '',
     countNum: 0,
     grayTheme:false,
     navigationList:[],
     couponPath: false,
-  },
+    avatarUrl : 'https://mmbiz.qpic.cn/mmbiz/icTdbqWNOwNRna42FI242Lcia07jQodd2FJGIYQfG0LAJGFxM4FbnQP6yfMxBgJ0F3YRqJCJ1aPAK2dQagdusBZg/0'
 
+  },
+  onChooseAvatar(e) {
+    console.log(e.detail)
+    this.setData({
+      avatarUrl: e.detail.avatarUrl 
+    })
+  },
   /**
    * 生命周期函数--监听页面加载
    */

+ 14 - 5
pages/welfareMall/personal/personal.wxml

@@ -3,22 +3,31 @@
   <custom-page head-bg-color="#FFE7E8">
     <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 wx:if="{{!isLogin}}" class="head-personal-logo" src="/images/welfareMall/head-portrait.png" />
+        
+          <image class="head-personal-logo" src="/images/welfareMall/head-portrait.png" />
           <!-- 获取用户头像 -->
           <view class="hat" wx:if="{{isLogin}}"></view>
-          <open-data wx:if="{{isLogin}}" class="head-personal-logo" type="userAvatarUrl"></open-data>
+          <!-- <open-data wx:if="{{isLogin}}" class="head-personal-logo" type="userAvatarUrl"></open-data> -->
           <view class="head-personal-nl flex-column" wx:if="{{isLogin}}">
             <!-- 获取用户微信昵称 -->
-            <open-data class="head-personal-name" type="userNickName" lang="zh_CN"></open-data>
+            <!-- <open-data class="head-personal-name" type="userNickName" lang="zh_CN"></open-data> -->
             <view class="head-personal-login">{{phone.toHide(mobileTop)}}</view>
           </view>
        
           <button class="personal-isLogin" wx:if="{{!isLogin}}" open-type="getPhoneNumber" bindgetphonenumber="getPhoneNumber">登录/注册</button>
-          <image wx:if="{{isLogin}}" src="/images/welfareMall/logout.png" style="height: 30px;width: 30px;margin-left: 90px;" bindtap="logout"></image>
+          <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>
+        <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 - 2
pages/welfareMall/personal/personal.wxss

@@ -89,7 +89,7 @@ page{
 
 .head-personal-login{
   margin-top: 18rpx;
-  font-size: 24rpx;
+  font-size: 26rpx;
   font-weight: 400;
   color: #303030;
 }
@@ -214,7 +214,7 @@ page{
 }
 
 .personal-isLogin{
-  font-size: 38rpx;
+  font-size: 26rpx;
   font-weight: 500;
   color: #303030;
   background-color: transparent;
@@ -260,3 +260,16 @@ page{
   height: 62rpx;
 }
 
+.logout{
+  height: 40rpx;
+  line-height: 40rpx;
+  width: 100rpx;
+  margin-top: 18rpx;
+  margin-left: 12rpx;
+  font-size: 22rpx;
+  text-align: center;
+  color: #E14B3F;
+  border: #E14B3F 2rpx solid;
+  border-radius: 4rpx;
+}
+

+ 14 - 1
utils/user.js

@@ -22,10 +22,23 @@ function getPhoneNumber(e, func) {
       func(getMobileCache())
     });
 }
+function getPhoneNumberNew(e, func) {
+    var code = e.detail.code;
+    console.log(code);
+  
+    if (!code || code.length == 0 ) {
+      return;
+    }
+    //获取手机号
+    getApp().doDecodePhoneNew(code, function () {
+      func(getMobileCache())
+    });
+}
 
 module.exports = {
     getUserInfo,
     getMobileCache,
-    getPhoneNumber
+    getPhoneNumber,
+    getPhoneNumberNew
 }