Commit 7cbece87 by 穆启卓

逻辑完善

parent e4c13551
...@@ -71,6 +71,11 @@ Page({ ...@@ -71,6 +71,11 @@ Page({
this.setData({ this.setData({
stepAuth: true stepAuth: true
}); });
} else {
app.globalData.stepAuth = false;
this.setData({
stepAuth: false
});
} }
this.checkAuth(); this.checkAuth();
} }
......
...@@ -4,7 +4,6 @@ Page({ ...@@ -4,7 +4,6 @@ Page({
data: { data: {
userAuth: false, // 用户信息授权(为了拿unionId) userAuth: false, // 用户信息授权(为了拿unionId)
stepAuth: false, // 步数授权 stepAuth: false, // 步数授权
getStepLoading: false,
// commitStepPopupShow: false, // 同步步数成功弹窗 // commitStepPopupShow: false, // 同步步数成功弹窗
activityExplainShow: false, // 活动说明弹窗 activityExplainShow: false, // 活动说明弹窗
currentSteps: 0, currentSteps: 0,
...@@ -40,7 +39,7 @@ Page({ ...@@ -40,7 +39,7 @@ Page({
stepAuth: app.globalData.stepAuth stepAuth: app.globalData.stepAuth
}); });
if (app.globalData.unionAuth && app.globalData.stepAuth) { if (app.globalData.unionAuth && app.globalData.stepAuth) {
this.clickStepData(); this.getClickStepData();
} else if (app.globalData.stepAuth) { } else if (app.globalData.stepAuth) {
this.loadStepData(); this.loadStepData();
} }
...@@ -114,22 +113,23 @@ Page({ ...@@ -114,22 +113,23 @@ Page({
}, },
// 用户点击提交步数打卡1(处理授权情况) // 用户点击提交步数打卡1(处理授权情况)
clickStepData() { clickStepData(resCheck = false) {
console.log('clickStepData') console.log('clickStepData')
if (!this.data.isFirstReq && wx.getStorageSync('getStepLoading') && Date.now() - wx.getStorageSync('getStepLoading') < 60000) { if (!resCheck && !this.data.isFirstReq && wx.getStorageSync('getStepLoading') && Date.now() - wx.getStorageSync('getStepLoading') < 60000) {
wx.showToast({ wx.showToast({
title: '已是最新步数,建议前往微信运动获取最新步数再返回同步', title: '已是最新步数,建议前往微信运动获取最新步数再返回同步',
icon: 'none', icon: 'none',
duration: 2000 duration: 2000
}); });
// return; return;
} }
let needStepAuth = () => { let needStepAuth = (resCheck) => {
wx.authorize({ // 调起授权窗口 wx.authorize({ // 调起授权窗口
scope: 'scope.werun', scope: 'scope.werun',
success:() => { // 授权成功 success:() => { // 授权成功
app.globalData.stepAuth = true; app.globalData.stepAuth = true;
this.clickStepData(); if (resCheck) this.clickStepData(true);
else this.getClickStepData();
}, },
fail:(err) => { // 授权失败,因为用户拒绝或者用户曾经拒绝过,而且在这里不能直接去到openSetting页,需要通过一个弹窗中转过去 fail:(err) => { // 授权失败,因为用户拒绝或者用户曾经拒绝过,而且在这里不能直接去到openSetting页,需要通过一个弹窗中转过去
this.authorizationFail(); this.authorizationFail();
...@@ -147,10 +147,10 @@ Page({ ...@@ -147,10 +147,10 @@ Page({
wx.navigateTo({ wx.navigateTo({
url: '/pages/authorization/authorization' url: '/pages/authorization/authorization'
}); });
} else if (app.globalData.userAuth && !app.globalData.stepAuth) {
needStepAuth();
} else if (!app.globalData.userAuth && app.globalData.stepAuth) { } else if (!app.globalData.userAuth && app.globalData.stepAuth) {
this.showUserInfoPopup(); this.showUserInfoPopup();
} else if (app.globalData.userAuth && !app.globalData.stepAuth) {
needStepAuth(true);
} else if (app.globalData.userAuth && app.globalData.stepAuth) { } else if (app.globalData.userAuth && app.globalData.stepAuth) {
wx.getUserInfo({ wx.getUserInfo({
withCredentials: true, withCredentials: true,
...@@ -226,8 +226,11 @@ Page({ ...@@ -226,8 +226,11 @@ Page({
// 用户同意授权 // 用户同意授权
onGotUserInfo(event) { onGotUserInfo(event) {
console.log('onGotUserInfo') console.log('onGotUserInfo')
this.showUserInfoPopup();
app.globalData.userAuth = true; app.globalData.userAuth = true;
this.setData({
showGetUserInfo: !this.data.showGetUserInfo,
userAuth: true
});
this.sendUserInfo(event.detail.encryptedData, event.detail.iv); this.sendUserInfo(event.detail.encryptedData, event.detail.iv);
}, },
...@@ -263,18 +266,32 @@ Page({ ...@@ -263,18 +266,32 @@ Page({
authorizationFail() { authorizationFail() {
console.log('authorizationFail') console.log('authorizationFail')
wx.showModal({ wx.showModal({
content: '如需完成步数打卡,\n请点击确定允许微信授权', content: '如需完成步数打卡,请点击确定允许微信授权',
success:(res) => { success:(res) => {
if (res.confirm) { if (res.confirm) {
wx.openSetting({ wx.openSetting({
success:(res) => { success:(res) => {
if (res.authSetting['scope.userInfo']) {
app.globalData.userAuth = true;
this.setData({
userAuth: true
});
} else {
app.globalData.userAuth = false;
this.setData({
userAuth: false
});
}
if (res.authSetting['scope.werun']) { if (res.authSetting['scope.werun']) {
app.globalData.stepAuth = true;
this.setData({ this.setData({
stepAuth: true stepAuth: true
}); });
// this.getPageData();
} else { } else {
// this.authorizationFail(); app.globalData.stepAuth = false;
this.setData({
stepAuth: false
});
} }
} }
}); });
......
...@@ -24,7 +24,6 @@ ...@@ -24,7 +24,6 @@
<image class="status-mark" src="/images/index/sy_{{item.status===1?'wancheng':'shibai'}}.png" wx:if="{{item.status}}"></image> <image class="status-mark" src="/images/index/sy_{{item.status===1?'wancheng':'shibai'}}.png" wx:if="{{item.status}}"></image>
<view class="date-container"> <view class="date-container">
<view class="date-item">{{item.date}}总步数</view> <view class="date-item">{{item.date}}总步数</view>
<view class="date-item">{{item.date_time}}</view>
</view> </view>
<view class="other-step-num">+{{item.step}}</view> <view class="other-step-num">+{{item.step}}</view>
</view> </view>
...@@ -38,12 +37,22 @@ ...@@ -38,12 +37,22 @@
<view class="hr"></view> <view class="hr"></view>
<view class="content-title title1">运动步数为0怎么办?</view> <view class="content-title title1">运动步数为0怎么办?</view>
<view class="content-text">请检查是否关注微信运动公众号,如已关注请继续行走;</view> <view class="content-text">请检查是否关注微信运动公众号,如已关注请继续行走;</view>
<view class="content-text">如未关注,则进入微信【添加好友】-搜索【微信运动】找到公众号并关注,进入公众号后你会收到一条提示是否要让微信访问我们的活动记录点击“好”即可。</view> <view class="content-text">如未关注,则进入微信【添加好友】搜索【微信运动】找到公众号并关注,进入公众号后你会收到一条提示是否要让微信访问我们的活动记录点击“好”即可。</view>
<view class="content-title title2">如何参与步数打卡?</view> <view class="content-title title2">如何参与步数打卡?</view>
<view class="content-text">关注公众号【XXXX】,点击菜单栏【打卡入口】,成功报名活动后,活动结束24点前登录小程序同步最新步数。</view> <view class="content-text">关注公众号【步步运动赚】,点击菜单栏【打卡入口】,成功报名活动后,活动结束24点前登录小程序同步最新步数。</view>
<image class="activity-explain-close-btn" src="/images/index/pop_ic_close.png" bindtap="changeActivityExplainShow"></image> <image class="activity-explain-close-btn" src="/images/index/pop_ic_close.png" bindtap="changeActivityExplainShow"></image>
</view> </view>
</view> </view>
<!-- 用戶信息授权,为了拿unionId -->
<view class="commit-step-popup-bg" wx:if="{{showGetUserInfo}}">
<view class="commit-step-popup">
<view class="popup-content">请允许授权获取步数数据</view>
<view class="popup-btn-container">
<view class="cancel-btn" bindtap="showUserInfoPopup">取消</view>
<button class="confirm-btn" plain open-type="getUserInfo" bindgetuserinfo="onGotUserInfo">确定</button>
</view>
</view>
</view>
<!-- 同步步数成功弹窗 --> <!-- 同步步数成功弹窗 -->
<!-- <view class="commit-step-popup-bg" wx:if="{{commitStepPopupShow}}"> <!-- <view class="commit-step-popup-bg" wx:if="{{commitStepPopupShow}}">
<view class="commit-step-popup"> <view class="commit-step-popup">
...@@ -53,13 +62,4 @@ ...@@ -53,13 +62,4 @@
<navigator class="confirm-btn" hover-class="none" open-type="exit" target="miniProgram">确定</navigator> <navigator class="confirm-btn" hover-class="none" open-type="exit" target="miniProgram">确定</navigator>
</view> </view>
</view> </view>
</view> --> </view> -->
<view class="commit-step-popup-bg" wx:if="{{showGetUserInfo}}"> \ No newline at end of file
<view class="commit-step-popup">
<view class="popup-content">请允许授权获取步数数据</view>
<view class="popup-btn-container">
<view class="cancel-btn" bindtap="showUserInfoPopup">取消</view>
<button class="confirm-btn" plain open-type="getUserInfo" bindgetuserinfo="onGotUserInfo">确定</button>
</view>
</view>
</view>
\ No newline at end of file
function formatTime(date) {
var year = date.getFullYear()
var month = date.getMonth() + 1
var day = date.getDate()
var hour = date.getHours()
var minute = date.getMinutes()
var second = date.getSeconds()
return [year, month, day].map(formatNumber).join('/') + ' ' + [hour, minute, second].map(formatNumber).join(':')
}
function formatNumber(n) {
n = n.toString()
return n[1] ? n : '0' + n
}
module.exports = { module.exports = {
formatTime: formatTime formatTime(date) {
} var year = date.getFullYear()
var month = date.getMonth() + 1
var day = date.getDate()
var hour = date.getHours()
var minute = date.getMinutes()
var second = date.getSeconds()
var formatNumber = n => {
n = n.toString()
return n[1] ? n : '0' + n
}
return [year, month, day].map(formatNumber).join('/') + ' ' + [hour, minute, second].map(formatNumber).join(':')
}
}
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment