Преглед изворни кода

开发绑定手机号相关功能

bayi пре 2 година
родитељ
комит
9f81697c77

+ 4 - 0
api/user.js

@@ -27,4 +27,8 @@ module.exports = {
   setFans: (data, method = 'post') => request('/fans', method, data),
   // 获取收藏列表
   getFavoritesList: data => request('/favorites', 'get', data),
+  // 用code获取手机号
+  exchangePhone: data => request('/v3/user/phoneNumber', 'get', data),
+  // 绑定手机号
+  bindPhone: data => request('/v3/user/bindMobile', 'post', data),
 }

+ 19 - 1
components/readingTips/index.js

@@ -7,7 +7,9 @@ import {
   buyNum,
   buyVip,
   getMyInfo,
-  getVipInfo
+  getVipInfo,
+  exchangePhone,
+  bindPhone
 } from '~/api/user'
 const app = getApp()
 
@@ -66,6 +68,22 @@ Component({
         vipTime,
       })
     },
+    async getPhoneNumber({
+      detail
+    }) {
+      let mobile = await exchangePhone({
+        code: detail.code
+      })
+      await bindPhone({
+        mobile
+      })
+      this.setUserInfo()
+      wx.showToast({
+        title: '绑定成功!已获得7天VIP',
+        icon: "none",
+        duration: 2000
+      })
+    },
     // 调起广告
     rewardedVideo() {
       if (this.data.tasks.length != 3 || this.data.tasks[2].completed) {

+ 14 - 2
components/readingTips/index.less

@@ -111,18 +111,30 @@
   }
 
   .bindNumber {
-    padding: 22rpx 30rpx;
     margin-top: 20rpx;
+    height: 100rpx;
+    padding: 0rpx 24rpx;
     display: flex;
     align-items: center;
-    background: url('http://reader-wx.ai160.com/images/reader/v3/year.png') no-repeat;
+    justify-content: space-between;
+    background: url('http://reader-wx.ai160.com/images/reader/v3/phone.png') no-repeat;
     background-size: cover;
+    font-size: 30rpx;
     border-radius: 20rpx;
 
     .desc {
       color: white;
+      margin-left: 120rpx;
     }
 
+    .bindBtn {
+      background-color: white;
+      color: #FC614E;
+      padding: 6rpx 24rpx;
+      font-size: 30rpx;
+      font-weight: bold;
+      border-radius: 25rpx;
+    }
   }
 
   .surplus {

+ 4 - 4
components/readingTips/index.wxml

@@ -31,10 +31,10 @@
         </view>
       </view>
     </view>
-    <!--     <view class="bindNumber">
-      <view class="desc">绑定手机号赠7天VIP</view>
-      <view class="bindBtn">立即绑定</view>
-    </view> -->
+    <view class="bindNumber" wx:if="{{!userInfo.user.mobile}}">
+      <view class="desc">绑定手机号赠7天VIP</view>
+      <button class="resetBtn bindBtn" open-type="getPhoneNumber" bindgetphonenumber="getPhoneNumber">立即绑定</button>
+    </view>
     <!-- 剩余使用次数 -->
     <view class="surplus">
       <view class="title">剩余使用次数:</view>

+ 14 - 2
components/readingTips/index.wxss

@@ -94,16 +94,28 @@
   background-color: #7D320A;
 }
 .attr_box .bindNumber {
-  padding: 22rpx 30rpx;
   margin-top: 20rpx;
+  height: 100rpx;
+  padding: 0rpx 24rpx;
   display: flex;
   align-items: center;
-  background: url('http://reader-wx.ai160.com/images/reader/v3/year.png') no-repeat;
+  justify-content: space-between;
+  background: url('http://reader-wx.ai160.com/images/reader/v3/phone.png') no-repeat;
   background-size: cover;
+  font-size: 30rpx;
   border-radius: 20rpx;
 }
 .attr_box .bindNumber .desc {
   color: white;
+  margin-left: 120rpx;
+}
+.attr_box .bindNumber .bindBtn {
+  background-color: white;
+  color: #FC614E;
+  padding: 6rpx 24rpx;
+  font-size: 30rpx;
+  font-weight: bold;
+  border-radius: 25rpx;
 }
 .attr_box .surplus {
   margin-top: 20rpx;

+ 8 - 0
components/videoPreview/index.less

@@ -35,10 +35,18 @@
         }
 
         .time {
+          display: flex;
+          align-items: center;
           margin-top: 4rpx;
           font-size: 26rpx;
           color: rgba(0, 0, 0, 0.6);
         }
+
+        .playNum {
+          margin: 4rpx 4rpx 0rpx 30rpx;
+          width: 30rpx;
+          height: 30rpx;
+        }
       }
     }
 

+ 3 - 1
components/videoPreview/index.wxml

@@ -5,7 +5,9 @@
       <image src="{{videoInfoCopy.user.avatar}}" class="avatar" bindtap="jumpUserInfo" />
       <view class="wH-left-user">
         <view class="nickname textOver">{{videoInfoCopy.user.nickName||videoInfoCopy.user.eid}}</view>
-        <view class="time">{{videoInfoCopy.userRead.day}} <text style="margin-left: 20rpx;">播放 {{videoInfo.userRead.playAmount}}</text></view>
+        <view class="time">{{videoInfoCopy.userRead.day}}
+          <image src="/static/play3.png" class="playNum" /> {{filters.numFilter(videoInfo.userRead.playAmount)}}
+        </view>
       </view>
     </view>
     <!-- 用户本人作品的右侧 -->

+ 7 - 0
components/videoPreview/index.wxss

@@ -33,10 +33,17 @@
   color: #000;
 }
 .work .workHead .wH-left .wH-left-user .time {
+  display: flex;
+  align-items: center;
   margin-top: 4rpx;
   font-size: 26rpx;
   color: rgba(0, 0, 0, 0.6);
 }
+.work .workHead .wH-left .wH-left-user .playNum {
+  margin: 4rpx 4rpx 0rpx 30rpx;
+  width: 30rpx;
+  height: 30rpx;
+}
 .work .workHead .wH-right {
   display: flex;
   align-items: center;

+ 26 - 5
pages/my/index.js

@@ -1,13 +1,15 @@
 import {
   getProducts,
   getTasks,
-  submitTask
+  submitTask,
 } from '~/api/global'
 import {
   buyVip,
   buyNum,
   getMyInfo,
-  getVipInfo
+  getVipInfo,
+  exchangePhone,
+  bindPhone
 } from '~/api/user'
 const app = getApp()
 Page({
@@ -92,7 +94,8 @@ Page({
       wx.hideLoading()
       wx.showToast({
         title: "支付失败,请重试",
-        icon: "none"
+        icon: "none",
+        duration: 3000
       })
     }
     let {
@@ -121,7 +124,8 @@ Page({
       fail(res) {
         wx.showToast({
           title: "支付失败",
-          icon: "none"
+          icon: "none",
+          duration: 3000
         })
       }
     })
@@ -136,9 +140,26 @@ Page({
     })
     wx.showToast({
       title: id == '1' ? '签到成功!' : id == 3 ? "观看成功!" : "",
-      icon: "none"
+      icon: "none",
+      duration: 2000
+    })
+    this.setUserInfo()
+  },
+  async getPhoneNumber({
+    detail
+  }) {
+    let mobile = await exchangePhone({
+      code: detail.code
+    })
+    await bindPhone({
+      mobile
     })
     this.setUserInfo()
+    wx.showToast({
+      title: '绑定成功!已获得7天VIP',
+      icon: "none",
+      duration: 2000
+    })
   },
   jump({
     currentTarget

+ 27 - 0
pages/my/index.less

@@ -255,6 +255,33 @@
     }
   }
 
+  .bindNumber {
+    margin-top: 20rpx;
+    height: 100rpx;
+    padding: 0rpx 24rpx;
+    display: flex;
+    align-items: center;
+    justify-content: space-between;
+    background: url('http://reader-wx.ai160.com/images/reader/v3/phone.png') no-repeat;
+    background-size: cover;
+    font-size: 30rpx;
+    border-radius: 20rpx;
+
+    .desc {
+      color: white;
+      margin-left: 120rpx;
+    }
+
+    .bindBtn {
+      background-color: white;
+      color: #FC614E;
+      padding: 6rpx 24rpx;
+      font-size: 30rpx;
+      font-weight: bold;
+      border-radius: 25rpx;
+    }
+  }
+
   .surplus {
     margin-top: 20rpx;
     padding: 22rpx 30rpx;

+ 5 - 1
pages/my/index.wxml

@@ -20,7 +20,7 @@
           </view>
         </view>
       </view>
-      <!-- <button open-type="getPhoneNumber" bindgetphonenumber="getPhoneNumber">输入手机号</button> -->
+
     </view>
     <view class="below sectionBoxs">
       <view class="sBox" bindtap='jump' data-url="/pages/follow/index">
@@ -87,6 +87,10 @@
       </view>
     </view>
   </view>
+  <view class="bindNumber" wx:if="{{userInfo.user&&!userInfo.user.mobile}}">
+    <view class="desc">绑定手机号赠7天VIP</view>
+    <button class="resetBtn bindBtn" open-type="getPhoneNumber" bindgetphonenumber="getPhoneNumber">立即绑定</button>
+  </view>
   <!-- 剩余使用次数 -->
   <view class="surplus">
     <view class="title">剩余使用次数:</view>

+ 24 - 0
pages/my/index.wxss

@@ -210,6 +210,30 @@
   color: white;
   background-color: #7D320A;
 }
+.container .bindNumber {
+  margin-top: 20rpx;
+  height: 100rpx;
+  padding: 0rpx 24rpx;
+  display: flex;
+  align-items: center;
+  justify-content: space-between;
+  background: url('http://reader-wx.ai160.com/images/reader/v3/phone.png') no-repeat;
+  background-size: cover;
+  font-size: 30rpx;
+  border-radius: 20rpx;
+}
+.container .bindNumber .desc {
+  color: white;
+  margin-left: 120rpx;
+}
+.container .bindNumber .bindBtn {
+  background-color: white;
+  color: #FC614E;
+  padding: 6rpx 24rpx;
+  font-size: 30rpx;
+  font-weight: bold;
+  border-radius: 25rpx;
+}
 .container .surplus {
   margin-top: 20rpx;
   padding: 22rpx 30rpx;