Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
W
walk_daka_wx
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
穆启卓
walk_daka_wx
Commits
7cbece87
Commit
7cbece87
authored
Apr 02, 2019
by
穆启卓
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
逻辑完善
parent
e4c13551
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
101 additions
and
270 deletions
+101
-270
app.js
app.js
+37
-224
authorization.js
pages/authorization/authorization.js
+5
-0
index.js
pages/index/index.js
+30
-13
index.wxml
pages/index/index.wxml
+14
-14
util.js
utils/util.js
+15
-19
No files found.
app.js
View file @
7cbece87
var
qcloud
=
require
(
'./vendor/qcloud-weapp-client-sdk/index'
);
//
var qcloud = require('./vendor/qcloud-weapp-client-sdk/index');
var
config
=
require
(
'./config'
);
var
Session
=
require
(
'./vendor/qcloud-weapp-client-sdk/lib/session'
);
//
var Session = require('./vendor/qcloud-weapp-client-sdk/lib/session');
var
app
=
null
;
var
isFirstRun
=
true
;
var
getConfigCount
=
0
;
...
...
@@ -53,41 +53,14 @@ App({
userInfo
:
''
,
// 用户后端登录的userInfo
token
:
''
,
// 用户后端登录的token
userAuth
:
false
,
// 用户信息授权(为了拿unionId)
unionAuth
:
false
,
// unionId授权: 如果为false是需要授权,true是不需要
stepAuth
:
false
,
// 步数授权
},
onLaunch
(
options
)
{
// wx.login({
// success:wxres => {
// if (wxres.code) {
// this.globalData.code = wxres.code;
// wx.request({
// url: config.service.hostUrl + "/v1/auth_login",
// data: {
// js_code: wxres.code
// },
// method: 'POST',
// success:myres => {
// if (myres.data.code === 0) {
// this.globalData.userInfo = myres.data.data;
// this.globalData.token = myres.data.data.token;
// } else if (myres.data.data.code === 401) {
// this.globalData.unionAuth = false;
// }
// }
// });
// } else {
// console.log('登录失败!' + res.errMsg)
// }
// }
// })
app
=
this
;
qcloud
.
setLoginUrl
(
config
.
service
.
loginUrl
);
//
qcloud.setLoginUrl(config.service.loginUrl);
if
(
options
.
query
&&
options
.
query
.
rid
)
{
app
.
globalData
.
rid
=
options
.
query
.
rid
...
...
@@ -96,7 +69,7 @@ App({
if
(
options
.
query
&&
options
.
query
.
source
)
{
app
.
globalData
.
launchSource
=
options
.
query
.
source
}
//数据统计-
用户层
级
//数据统计-
设置用户等
级
if
(
options
.
query
&&
options
.
query
.
level
)
{
app
.
globalData
.
userLevel
=
Number
(
options
.
query
.
level
)
+
1
}
...
...
@@ -105,16 +78,15 @@ App({
app
.
globalData
.
scene
=
options
.
scene
}
app
.
globalData
.
localData
=
wx
.
getStorageSync
(
"initData"
)
app
.
setGlobalData
(
JSON
.
parse
(
app
.
globalData
.
localData
||
"{}"
))
app
.
globalData
.
systemInfo
=
app
.
computeSystemInfo
()
// app.globalData.localData = wx.getStorageSync("initData")
// app.setGlobalData(JSON.parse(app.globalData.localData || "{}"))
this
.
setNavBarConfig
();
app
.
globalData
.
systemInfo
=
app
.
computeSystemInfo
();
},
onShow
(
options
)
{
console
.
log
(
"app on
show
:"
,
options
)
console
.
log
(
"app on
show options
:"
,
options
)
const
uid
=
wx
.
getStorageSync
(
'uid'
)
if
(
uid
)
{
app
.
globalData
.
uid
=
uid
...
...
@@ -145,24 +117,17 @@ App({
}
},
// 初始化自定义导航栏的宽高等数据
setNavBarConfig
()
{
getConfigCount
++
;
if
(
getConfigCount
>=
100
)
return
;
try
{
let
res
=
wx
.
getSystemInfoSync
();
if
(
!
res
)
{
if
(
!
res
||
res
.
screenHeight
<=
0
||
res
.
screenWidth
<=
0
||
res
.
windowHeight
<=
0
||
res
.
windowWidth
<=
0
)
{
console
.
log
(
'getConfig Fail'
);
app
.
setNavBarConfig
();
return
;
}
if
(
res
.
screenHeight
<=
0
||
res
.
screenWidth
<=
0
||
res
.
windowHeight
<=
0
||
res
.
windowWidth
<=
0
)
{
console
.
log
(
'getConfig Fail'
);
app
.
setNavBarConfig
();
return
;
}
// console.log('system res', res);
config
.
pixelRate
=
res
.
windowWidth
/
750
;
config
.
platform
=
res
.
platform
;
config
.
statusBarHeight
=
res
.
statusBarHeight
;
...
...
@@ -176,131 +141,15 @@ App({
if
(
res
.
windowHeight
>
750
)
config
.
isAllScreen
=
true
;
config
.
systemHeight
=
res
.
windowHeight
;
app
.
globalData
.
navHeight
=
(
config
.
statusBarHeight
+
config
.
capsuleHeight
)
/
config
.
pixelRate
}
catch
(
e
)
{
console
.
log
(
e
);
}
},
// helper
setGlobalData
:
function
(
data
)
{
console
.
log
(
'Initdata'
,
data
)
app
.
globalData
.
isBeta
=
data
.
isBeta
||
false
app
.
globalData
.
defaultWords
=
data
.
defaultWords
||
app
.
globalData
.
defautWords
app
.
globalData
.
maxWordsLen
=
data
.
maxWordsLen
||
22
app
.
globalData
.
canCustomWords
=
data
.
customWords
==
1
?
true
:
false
app
.
globalData
.
exampleRno
=
data
.
exampleRno
||
"example01"
app
.
globalData
.
maxAmount
=
data
.
maxAmount
||
100
app
.
globalData
.
minAmount
=
data
.
minAmount
||
1
app
.
globalData
.
competedMinNum
=
data
.
competedMinNum
||
2
;
app
.
globalData
.
competedMinAmount
=
data
.
competedMinAmount
||
1
;
app
.
globalData
.
maxNum
=
data
.
maxNum
||
500
app
.
globalData
.
rate
=
data
.
rate
||
0.02
app
.
globalData
.
showContactButton
=
data
.
contactBtn
==
0
?
false
:
true
app
.
globalData
.
indexAd
=
data
.
ad
||
{
adStatus
:
0
};
app
.
globalData
.
cover
=
data
.
cover
||
[];
app
.
globalData
.
imgHost
=
data
.
imgHost
||
''
;
app
.
globalData
.
homeTopImg
=
data
.
homeTopImg
||
'../../images/common/home_img_top.png'
},
getShareTitle
:
function
(
path
,
nickName
=
''
)
{
qcloud
.
request
({
url
:
config
.
service
.
hostUrl
+
"/redpack/getShareTitle?t="
+
new
Date
().
getTime
(),
data
:
{
ver
:
config
.
service
.
version
,
path
:
path
,
nickName
:
nickName
},
header
:
{
'X-WX-Id'
:
Session
.
get
()
?
Session
.
get
().
id
:
'-'
,
'X-WX-Skey'
:
Session
.
get
()
?
Session
.
get
().
skey
:
'-'
},
success
(
result
)
{
if
(
result
.
data
.
uid
&&
result
.
data
.
uid
!=
''
)
{
app
.
globalData
.
uid
=
result
.
data
.
uid
}
app
.
globalData
.
shareTitle
=
result
.
data
.
shareTitle
},
fail
(
error
)
{
wx
.
hideLoading
()
}
});
},
contactHandler
:
function
(
e
,
page
,
sameHandler
)
{
let
path
=
e
.
detail
.
path
const
query
=
e
.
detail
.
query
if
(
!
path
)
{
return
}
// page.route: 不以下划线开头
// path: 以下划线开头
console
.
log
(
"contact page route:"
,
page
.
route
)
console
.
log
(
"contact path:"
,
path
)
if
(
page
&&
path
.
indexOf
(
page
.
route
)
!=
-
1
)
{
// 同一页面, 不跳转
if
(
sameHandler
)
{
sameHandler
(
query
)
}
return
}
var
url
=
path
let
queryArray
=
[]
for
(
let
key
in
query
)
{
if
(
query
.
hasOwnProperty
(
key
))
{
const
s
=
key
+
'='
+
query
[
key
]
queryArray
.
push
(
s
)
}
}
if
(
queryArray
.
length
>
0
)
{
const
queryString
=
queryArray
.
join
(
"&"
)
url
+=
'?'
+
queryString
}
const
tabBarPages
=
[
'/pages/index/index'
]
if
(
path
.
indexOf
(
tabBarPages
[
0
])
==
0
||
path
.
indexOf
(
tabBarPages
[
1
])
==
0
||
path
.
indexOf
(
tabBarPages
[
2
])
==
0
)
{
console
.
log
(
"contact: tab bar page"
)
setTimeout
(
function
()
{
wx
.
reLaunch
({
url
:
url
,
})
},
500
)
}
else
{
console
.
log
(
"contact: not tab bar page"
)
app
.
navigateTo
(
url
)
}
},
compareVersion
:
function
(
v1
,
v2
)
{
v1
=
v1
.
split
(
'.'
)
v2
=
v2
.
split
(
'.'
)
var
len
=
Math
.
max
(
v1
.
length
,
v2
.
length
)
while
(
v1
.
length
<
len
)
{
v1
.
push
(
'0'
)
}
while
(
v2
.
length
<
len
)
{
v2
.
push
(
'0'
)
}
for
(
var
i
=
0
;
i
<
len
;
i
++
)
{
var
num1
=
parseInt
(
v1
[
i
])
var
num2
=
parseInt
(
v2
[
i
])
if
(
num1
>
num2
)
{
return
1
}
else
if
(
num1
<
num2
)
{
return
-
1
}
console
.
log
(
'getConfig Fail'
,
e
);
app
.
setNavBarConfig
();
return
;
}
return
0
},
computeSystemInfo
:
function
()
{
// 初始化用户手机基本数据
computeSystemInfo
()
{
const
info
=
wx
.
getSystemInfoSync
()
var
infoString
=
""
console
.
log
(
'info'
,
info
);
...
...
@@ -311,8 +160,6 @@ App({
app
.
globalData
.
sWidth
=
info
.
screenWidth
app
.
globalData
.
wHeight
=
info
.
windowHeight
//console.log(info.model)
if
(
info
.
screenHeight
/
info
.
screenWidth
>=
812
/
375
)
{
app
.
globalData
.
ifIphoneX
=
true
}
...
...
@@ -331,6 +178,28 @@ App({
return
infoString
},
setGlobalData
(
data
)
{
console
.
log
(
'Initdata'
,
data
)
app
.
globalData
.
isBeta
=
data
.
isBeta
||
false
app
.
globalData
.
defaultWords
=
data
.
defaultWords
||
app
.
globalData
.
defautWords
app
.
globalData
.
maxWordsLen
=
data
.
maxWordsLen
||
22
app
.
globalData
.
canCustomWords
=
data
.
customWords
==
1
?
true
:
false
app
.
globalData
.
exampleRno
=
data
.
exampleRno
||
"example01"
app
.
globalData
.
maxAmount
=
data
.
maxAmount
||
100
app
.
globalData
.
minAmount
=
data
.
minAmount
||
1
app
.
globalData
.
competedMinNum
=
data
.
competedMinNum
||
2
;
app
.
globalData
.
competedMinAmount
=
data
.
competedMinAmount
||
1
;
app
.
globalData
.
maxNum
=
data
.
maxNum
||
500
app
.
globalData
.
rate
=
data
.
rate
||
0.02
app
.
globalData
.
showContactButton
=
data
.
contactBtn
==
0
?
false
:
true
app
.
globalData
.
indexAd
=
data
.
ad
||
{
adStatus
:
0
};
app
.
globalData
.
cover
=
data
.
cover
||
[];
app
.
globalData
.
imgHost
=
data
.
imgHost
||
''
;
app
.
globalData
.
homeTopImg
=
data
.
homeTopImg
||
'../../images/common/home_img_top.png'
},
//数据统计-sourceReport接口调用
reportSource
:
function
(
options
)
{
console
.
log
(
'send sourceReport'
)
...
...
@@ -391,59 +260,4 @@ App({
}
});
},
setUid
:
function
(
uid
)
{
app
.
globalData
.
uid
=
uid
wx
.
setStorage
({
key
:
'uid'
,
data
:
uid
,
})
if
(
app
.
globalData
.
appShowOptions
)
{
console
.
log
(
'setUid**report'
)
app
.
reportSource
(
app
.
globalData
.
appShowOptions
)
app
.
globalData
.
appShowOptions
=
null
}
},
uploadFormId
:
function
(
formId
,
source
)
{
setTimeout
(
function
()
{
qcloud
.
request
({
// 要请求的地址
url
:
config
.
service
.
hostUrl
+
"/user/uploadFormId?t="
+
new
Date
().
getTime
(),
data
:
{
ver
:
config
.
service
.
version
,
formId
:
formId
,
source
:
source
},
header
:
{
'X-WX-Id'
:
Session
.
get
()
?
Session
.
get
().
id
:
'-'
,
'X-WX-Skey'
:
Session
.
get
()
?
Session
.
get
().
skey
:
'-'
},
complete
()
{
//console.log('request complete');
}
});
},
50
)
},
getGuideStatus
()
{
let
count
=
wx
.
getStorageSync
(
'guideCount'
);
if
(
count
&&
count
>=
2
)
{
return
false
}
else
{
return
true
;
}
},
setGuideStatus
()
{
let
count
=
wx
.
getStorageSync
(
'guideCount'
);
console
.
log
(
'count'
,
count
);
if
(
!
count
)
{
count
=
1
;
}
else
{
count
++
;
}
wx
.
setStorageSync
(
'guideCount'
,
count
);
}
});
\ No newline at end of file
pages/authorization/authorization.js
View file @
7cbece87
...
...
@@ -71,6 +71,11 @@ Page({
this
.
setData
({
stepAuth
:
true
});
}
else
{
app
.
globalData
.
stepAuth
=
false
;
this
.
setData
({
stepAuth
:
false
});
}
this
.
checkAuth
();
}
...
...
pages/index/index.js
View file @
7cbece87
...
...
@@ -4,7 +4,6 @@ Page({
data
:
{
userAuth
:
false
,
// 用户信息授权(为了拿unionId)
stepAuth
:
false
,
// 步数授权
getStepLoading
:
false
,
// commitStepPopupShow: false, // 同步步数成功弹窗
activityExplainShow
:
false
,
// 活动说明弹窗
currentSteps
:
0
,
...
...
@@ -40,7 +39,7 @@ Page({
stepAuth
:
app
.
globalData
.
stepAuth
});
if
(
app
.
globalData
.
unionAuth
&&
app
.
globalData
.
stepAuth
)
{
this
.
c
lickStepData
();
this
.
getC
lickStepData
();
}
else
if
(
app
.
globalData
.
stepAuth
)
{
this
.
loadStepData
();
}
...
...
@@ -114,22 +113,23 @@ Page({
},
// 用户点击提交步数打卡1(处理授权情况)
clickStepData
()
{
clickStepData
(
resCheck
=
false
)
{
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
({
title
:
'已是最新步数,建议前往微信运动获取最新步数再返回同步'
,
icon
:
'none'
,
duration
:
2000
});
//
return;
return
;
}
let
needStepAuth
=
()
=>
{
let
needStepAuth
=
(
resCheck
)
=>
{
wx
.
authorize
({
// 调起授权窗口
scope
:
'scope.werun'
,
success
:()
=>
{
// 授权成功
app
.
globalData
.
stepAuth
=
true
;
this
.
clickStepData
();
if
(
resCheck
)
this
.
clickStepData
(
true
);
else
this
.
getClickStepData
();
},
fail
:(
err
)
=>
{
// 授权失败,因为用户拒绝或者用户曾经拒绝过,而且在这里不能直接去到openSetting页,需要通过一个弹窗中转过去
this
.
authorizationFail
();
...
...
@@ -147,10 +147,10 @@ Page({
wx
.
navigateTo
({
url
:
'/pages/authorization/authorization'
});
}
else
if
(
app
.
globalData
.
userAuth
&&
!
app
.
globalData
.
stepAuth
)
{
needStepAuth
();
}
else
if
(
!
app
.
globalData
.
userAuth
&&
app
.
globalData
.
stepAuth
)
{
this
.
showUserInfoPopup
();
}
else
if
(
app
.
globalData
.
userAuth
&&
!
app
.
globalData
.
stepAuth
)
{
needStepAuth
(
true
);
}
else
if
(
app
.
globalData
.
userAuth
&&
app
.
globalData
.
stepAuth
)
{
wx
.
getUserInfo
({
withCredentials
:
true
,
...
...
@@ -226,8 +226,11 @@ Page({
// 用户同意授权
onGotUserInfo
(
event
)
{
console
.
log
(
'onGotUserInfo'
)
this
.
showUserInfoPopup
();
app
.
globalData
.
userAuth
=
true
;
this
.
setData
({
showGetUserInfo
:
!
this
.
data
.
showGetUserInfo
,
userAuth
:
true
});
this
.
sendUserInfo
(
event
.
detail
.
encryptedData
,
event
.
detail
.
iv
);
},
...
...
@@ -263,18 +266,32 @@ Page({
authorizationFail
()
{
console
.
log
(
'authorizationFail'
)
wx
.
showModal
({
content
:
'如需完成步数打卡,
\
n
请点击确定允许微信授权'
,
content
:
'如需完成步数打卡,请点击确定允许微信授权'
,
success
:(
res
)
=>
{
if
(
res
.
confirm
)
{
wx
.
openSetting
({
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'
])
{
app
.
globalData
.
stepAuth
=
true
;
this
.
setData
({
stepAuth
:
true
});
// this.getPageData();
}
else
{
// this.authorizationFail();
app
.
globalData
.
stepAuth
=
false
;
this
.
setData
({
stepAuth
:
false
});
}
}
});
...
...
pages/index/index.wxml
View file @
7cbece87
...
...
@@ -24,7 +24,6 @@
<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-item">{{item.date}}总步数</view>
<view class="date-item">{{item.date_time}}</view>
</view>
<view class="other-step-num">+{{item.step}}</view>
</view>
...
...
@@ -38,12 +37,22 @@
<view class="hr"></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-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>
</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">
...
...
@@ -53,13 +62,4 @@
<navigator class="confirm-btn" hover-class="none" open-type="exit" target="miniProgram">确定</navigator>
</view>
</view>
</view> -->
<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>
\ No newline at end of file
</view> -->
\ No newline at end of file
utils/util.js
View file @
7cbece87
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
=
{
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
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment