Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
K
Kindergarten
Project
Project
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
张杰
Kindergarten
Commits
9307bb35
Commit
9307bb35
authored
Dec 26, 2018
by
张杰
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
家长首页填充部分数据
parent
f9e80485
Hide whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
796 additions
and
119 deletions
+796
-119
parrent.js
api/parrent.js
+14
-0
request.js
api/request.js
+303
-0
app.json
app.json
+2
-1
index.js
pages/home/parents/index.js
+74
-9
index.wxml
pages/home/parents/index.wxml
+60
-107
project.config.json
project.config.json
+1
-1
auth.js
utils/auth.js
+71
-0
self.js
utils/self.js
+23
-0
util.js
utils/util.js
+248
-1
No files found.
api/parrent.js
0 → 100644
View file @
9307bb35
var
request
=
require
(
'./request.js'
)
module
.
exports
=
{
queryStudentRecord
(
pageNumber
,
pageSize
,
studentId
)
{
var
params
=
{
pageNumber
:
pageNumber
,
pageSize
:
pageSize
,
studentId
:
studentId
}
return
request
.
post
(
'/preschool/wxsite/parents/queryStudentRecord.do'
,
params
)
}
}
api/request.js
0 → 100644
View file @
9307bb35
'use strict'
;
var
utils
=
require
(
'../utils/util.js'
);
var
auth
=
require
(
'../utils/auth.js'
);
// 网络异常代码
const
ERR_NET_ERROR
=
-
99999
;
const
ERR_ACCESS_TOKEN_EXPIRED
=
20
;
const
ERR_NOT_ACCESS_TOKEN
=
21
;
// 取开发环境系统配置
var
DEF_APP_CONFIG
=
{
appId
:
"wxfc3355043e579968"
,
// 勾芒小程序测试号
// 开发环境
domain
:
'http://192.168.1.135:8080'
,
baseUrl
:
"http://192.168.1.135:8080"
// 川哥本地环境
// domain: 'http://192.168.199.198:8080',
// baseUrl: "http://192.168.199.198:8080/wxmall/wxsite",
// 谢贝本地环境
// domain: 'http://192.168.199.153:9090',
// baseUrl: "http://192.168.199.153:9090/wxmall/wxsite"
}
const
extConfig
=
wx
.
getExtConfigSync
?
wx
.
getExtConfigSync
()
:
DEF_APP_CONFIG
;
const
APP_ID
=
extConfig
.
appId
||
DEF_APP_CONFIG
.
appId
;
const
BASE_URL
=
extConfig
.
baseUrl
||
DEF_APP_CONFIG
.
baseUrl
;
const
APP_VERSION
=
'wxapp-1.4.45'
;
// 当前小程序版本
const
API_VERSION
=
'0.0.4'
;
// 当前API版本
const
DOMAIN
=
DEF_APP_CONFIG
.
domain
// 当前域名
const
WXA_APPID
=
DEF_APP_CONFIG
.
appId
;
// 当前小程序的appid
var
OS_VERSION
=
''
;
// 当前微信操作系统版本
wx
.
getSystemInfo
({
success
:
function
(
res
)
{
OS_VERSION
=
'wxapp-'
+
res
.
version
;
}
})
/**
* APP配置
*/
module
.
exports
.
APP_ID
=
APP_ID
;
module
.
exports
.
DOMAIN
=
DOMAIN
;
module
.
exports
.
BASE_URL
=
BASE_URL
;
/**
* 执行http请求
*/
module
.
exports
.
request
=
function
(
url
,
method
=
'GET'
,
data
=
{},
contentType
=
'json'
,
dataType
=
'json'
)
{
const
self
=
this
var
headers
=
{};
if
(
contentType
==
'json'
)
{
headers
[
'content-type'
]
=
'application/json'
;
}
else
{
headers
[
'content-type'
]
=
'application/x-www-form-urlencoded'
;
}
try
{
var
value
=
wx
.
getStorageSync
(
'wj_wxa_formId'
)
if
(
value
)
{
headers
[
'wxa-form-id'
]
=
value
;
wx
.
removeStorageSync
(
'wj_wxa_formId'
)
}
}
catch
(
e
)
{
console
.
log
(
e
)
}
headers
[
'app-version'
]
=
APP_VERSION
;
headers
[
'os-version'
]
=
OS_VERSION
;
headers
[
'api-version'
]
=
API_VERSION
;
headers
[
'wxa-appid'
]
=
WXA_APPID
;
// 添加access token,暂不支持刷新access token
var
tokens
=
auth
.
getTokens
();
if
(
tokens
&&
tokens
.
accessToken
)
{
headers
[
'access-token'
]
=
tokens
.
accessToken
}
function
onSucc
(
res
,
resolve
,
reject
)
{
var
ok
=
(
res
.
statusCode
>=
200
&&
res
.
statusCode
<
300
);
if
(
!
ok
)
{
reject
({
code
:
ERR_NET_ERROR
,
msg
:
'网络错误'
});
return
;
}
var
userData
=
res
.
data
;
if
(
userData
.
code
==
0
)
{
// 如果成功,直接返回
if
(
userData
.
obj
==
null
)
{
wx
.
hideLoading
()
// wx.showToast({
// title: userData.msg,
// icon: 'none',
// duration: 2000
// })
resolve
(
userData
.
msg
)
}
else
{
resolve
(
userData
.
obj
);
}
}
else
{
if
(
userData
.
code
!=
ERR_ACCESS_TOKEN_EXPIRED
)
{
if
(
userData
.
code
!=
ERR_NOT_ACCESS_TOKEN
)
{
// 直接失败
reject
(
userData
);
}
else
{
userData
=
{
...
userData
,
msg
:
'您还没有登录哦~'
}
reject
(
userData
);
}
}
else
{
// 特别处理Access Token已过期的异常: 重新登录后重放请求
const
postData
=
data
;
self
.
login
().
then
(
data
=>
{
self
.
request
(
url
,
method
,
postData
,
contentType
,
dataType
)
.
then
(
function
(
data
)
{
resolve
(
data
);
}).
catch
(
function
(
err
)
{
reject
(
err
);
});
}).
catch
(
err
=>
{
if
(
err
.
code
===
'23001'
)
{
reject
({
msg
:
"信息已过期,请刷新当前页面"
})
}
else
{
reject
(
err
);
}
})
}
}
}
return
new
Promise
(
function
(
resolve
,
reject
)
{
if
(
!
utils
.
isHideLoading
())
{
wx
.
showLoading
({
title
:
'加载中...'
,
mask
:
true
});
}
wx
.
request
({
url
:
BASE_URL
+
url
,
method
:
method
,
dataType
:
dataType
,
data
:
data
,
header
:
headers
,
success
:
function
(
res
)
{
onSucc
(
res
,
resolve
,
reject
);
},
fail
:
function
(
res
)
{
console
.
error
(
BASE_URL
+
url
+
' 请求失败返回: '
,
res
);
var
msg
=
res
.
errMsg
;
if
(
msg
.
indexOf
(
"request:fail"
)
>=
0
)
{
msg
=
"网络错误"
;
}
reject
({
code
:
-
1
,
msg
:
msg
});
},
complete
:
function
()
{
wx
.
hideLoading
();
}
});
});
}
/**
* 小程序内部用户登录
*
* @return code
*/
function
wx_login
()
{
return
new
Promise
(
function
(
resolve
,
reject
)
{
wx
.
login
({
success
:
function
(
res
)
{
console
.
debug
(
'!!!微信登录返回结果-----'
+
JSON
.
stringify
(
res
));
if
(
res
.
code
)
{
resolve
(
res
.
code
);
}
else
{
reject
({
code
:
-
1
,
msg
:
res
.
errMsg
});
}
},
fail
:
function
(
res
)
{
reject
({
code
:
-
1
,
msg
:
res
.
errMsg
});
}
});
});
}
/**
* 小程序内部取得用户信息
*
* @return 用户信息
*/
function
wx_getUserInfo
()
{
return
new
Promise
(
function
(
resolve
,
reject
)
{
wx
.
getUserInfo
({
success
:
function
(
res
)
{
resolve
(
res
);
},
fail
:
function
(
res
)
{
if
(
res
.
errMsg
===
'getUserInfo:fail scope unauthorized'
)
{
wx
.
clearStorage
();
wx
.
startPullDownRefresh
({
success
:
function
()
{
wx
.
stopPullDownRefresh
();
}
})
return
;
}
reject
({
code
:
-
1
,
msg
:
res
.
errMsg
});
}
})
});
}
/**
* 用户登录
*
* @param decryptUserInfo 是否解密用户信息
* @return 用户信息,如果返回的 #member字段为空,说明当前粉丝没有绑定手机号, 还不是会员。
*/
module
.
exports
.
login
=
function
(
decryptUserInfo
=
true
)
{
var
self
=
this
;
var
loginCode
=
''
;
return
wx_login
()
.
then
(
function
(
code
)
{
loginCode
=
code
;
return
wx_getUserInfo
()
})
.
then
(
function
(
res
)
{
var
encryptedUserInfo
=
null
;
decryptUserInfo
&&
(
encryptedUserInfo
=
{
encryptedData
:
res
.
encryptedData
,
iv
:
res
.
iv
});
var
req
=
{
appid
:
APP_ID
,
code
:
loginCode
,
encryptedUserInfo
:
encryptedUserInfo
};
return
self
.
post
(
'/wxa/user/login'
,
req
);
})
.
then
(
function
(
data
)
{
// 保存登录结果
auth
.
setTokens
(
data
);
return
data
;
});
}
/**
* HTTP GET
*/
module
.
exports
.
get
=
function
(
url
,
data
)
{
return
this
.
request
(
url
,
'GET'
,
data
);
}
/**
* HTTP POST
*/
module
.
exports
.
post
=
function
(
url
,
data
)
{
return
this
.
request
(
url
,
'POST'
,
data
);
}
/**
* HTTP PUT
*/
module
.
exports
.
put
=
function
(
url
,
data
)
{
return
this
.
request
(
url
,
'PUT'
,
data
);
}
/**
* HTTP DELETE
*/
module
.
exports
.
delete
=
function
(
url
,
data
)
{
return
this
.
request
(
url
,
'DELETE'
,
data
);
}
/**
* dev config
*/
module
.
exports
.
config
=
function
()
{
return
DEF_APP_CONFIG
}
\ No newline at end of file
app.json
View file @
9307bb35
{
"pages"
:[
"pages/home/reviewer/index"
,
"pages/home/parents/index"
,
"pages/home/teacher/index"
,
"pages/home/reviewer/index"
,
"pages/add_record/index"
,
"pages/review_student/index"
],
...
...
pages/home/parents/index.js
View file @
9307bb35
// pages/home/parents/index.js
const
request
=
require
(
'../../../api/parrent.js'
)
Page
({
/**
* 页面的初始数据
*/
data
:
{
page
:
0
,
pageSize
:
15
,
records
:
[],
recordTypes
:
{
"diet_morning"
:
'早餐'
,
"diet_afternoon"
:
"午餐"
,
"diet_milk"
:
"牛奶"
,
"diet_evening"
:
"晚餐"
,
"diet_morning_more"
:
"上午加餐"
,
"diet_afternoon_more"
:
"下午加餐"
,
"diet_water"
:
"喝水"
,
"diet_milk"
:
"饮用牛奶"
,
"sleep_time"
:
"睡觉时间"
,
"wc_pee"
:
"小便"
,
"wc_poo"
:
"便"
,
"wc_diaper"
:
"换尿布"
}
},
/**
* 生命周期函数--监听页面加载
*/
onLoad
:
function
(
options
)
{
onLoad
:
function
(
options
)
{
const
that
=
this
request
.
queryStudentRecord
(
that
.
data
.
page
,
that
.
data
.
pageSize
,
'4028048267c0236e0167c02b63100004'
).
then
(
res
=>
{
console
.
log
(
res
)
var
record
=
res
[
'records'
]
var
templist
=
this
.
data
.
records
for
(
var
i
=
0
;
i
<
record
.
length
;
i
++
)
{
var
item
=
record
[
i
]
// 饮食
var
dietRecords
=
item
[
'dietRecord'
]
for
(
var
j
=
0
;
j
<
dietRecords
.
length
;
j
++
)
{
var
diet
=
dietRecords
[
j
]
diet
.
z_recordType
=
that
.
data
.
recordTypes
[
diet
.
recordType
]
}
// 睡觉
var
sleepRecord
=
item
[
"sleepRecord"
]
for
(
var
j
=
0
;
j
<
sleepRecord
.
length
;
j
++
)
{
var
r
=
sleepRecord
[
j
]
r
.
z_recordType
=
that
.
data
.
recordTypes
[
r
.
recordType
]
}
// wc
var
wcRecord
=
item
[
"wcRecord"
]
for
(
var
j
=
0
;
j
<
wcRecord
.
length
;
j
++
)
{
var
r
=
wcRecord
[
j
]
r
.
z_recordType
=
that
.
data
.
recordTypes
[
r
.
recordType
]
}
console
.
log
(
item
)
templist
.
push
(
item
)
}
this
.
setData
({
records
:
templist
,
page
:
res
[
'paging'
][
'page'
]
})
})
},
/**
* 生命周期函数--监听页面初次渲染完成
*/
onReady
:
function
()
{
onReady
:
function
()
{
},
/**
* 生命周期函数--监听页面显示
*/
onShow
:
function
()
{
onShow
:
function
()
{
},
/**
* 生命周期函数--监听页面隐藏
*/
onHide
:
function
()
{
onHide
:
function
()
{
},
/**
* 生命周期函数--监听页面卸载
*/
onUnload
:
function
()
{
onUnload
:
function
()
{
},
/**
* 页面相关事件处理函数--监听用户下拉动作
*/
onPullDownRefresh
:
function
()
{
onPullDownRefresh
:
function
()
{
},
/**
* 页面上拉触底事件的处理函数
*/
onReachBottom
:
function
()
{
onReachBottom
:
function
()
{
},
/**
* 用户点击右上角分享
*/
onShareAppMessage
:
function
()
{
onShareAppMessage
:
function
()
{
}
})
\ No newline at end of file
pages/home/parents/index.wxml
View file @
9307bb35
...
...
@@ -9,115 +9,68 @@
<view class='kg-separater'></view>
<scroll-view style='height:calc(100vh - 200rpx)' scroll-y='true'>
<view class='timeline-cell'>
<view class='timeline-line-container'>
<view class='timeline-line'></view>
<image class='timeline-cycle' src='/src/img/timeline-cycle.jpeg'></image>
</view>
<view class='kg-quantity-cell timeline-content'>
<view class='kg-flex-row' style='margin-bottom:20rpx;'>
<text class='kg-text-title'>2018-09-11 星期二</text>
<text class='kg-text-normal-gray'>王xx老师记录</text>
</view>
<template is='imgTextView' data="{{img:'eat',text:'饮食'}}"> </template>
<view class='kg-flex-row timeline-content-detail'>
<text class='kg-text-normal-gray'>早餐</text>
<text class='kg-text-normal-gray'>正常</text>
</view>
<view class='kg-flex-row timeline-content-detail'>
<text class='kg-text-normal-gray'>早餐</text>
<text class='kg-text-normal-gray'>正常</text>
</view>
<view class='kg-flex-row timeline-content-detail'>
<text class='kg-text-normal-gray'>早餐</text>
<text class='kg-text-normal-gray'>正常</text>
</view>
<view class='kg-separater' style='height:2rpx;margin-left:100rpx;margin-right:0rpx;'></view>
<!-- 睡觉 -->
<template is='imgTextView' data="{{img:'sleep',text:'睡觉'}}"> </template>
<view class='kg-flex-row timeline-content-detail'>
<text class='kg-text-normal-gray'>午睡</text>
<text class='kg-text-normal-gray'>50分钟</text>
</view>
<view class='kg-separater' style='height:2rpx;margin-left:100rpx;margin-right:0rpx;'></view>
<!-- wc -->
<template is='imgTextView' data="{{img:'wc',text:'WC'}}"> </template>
<view class='kg-flex-row timeline-content-detail'>
<text class='kg-text-normal-gray'>pee</text>
<text class='kg-text-normal-gray'>4次</text>
</view>
<view class='kg-flex-row timeline-content-detail'>
<text class='kg-text-normal-gray'>poo</text>
<text class='kg-text-normal-gray'>4次</text>
</view>
<view class='kg-flex-row timeline-content-detail'>
<text class='kg-text-normal-gray'>diaper</text>
<text class='kg-text-normal-gray'>4次</text>
</view>
<view class='kg-separater' style='height:2rpx;margin-left:100rpx;margin-right:0rpx;'></view>
<!-- 今日照片 -->
<template is='imgTextView' data="{{img:'today',text:'今日照片'}}"> </template>
<view class='home-student-picture-item' style='margin-left:40rpx;'>
<image src='/src/img/student_picture.png' class='home-student-picture' mode='aspectFill'></image>
<image src='/src/img/student_picture.png' class='home-student-picture' mode='aspectFill'></image>
<image src='/src/img/student_picture.png' class='home-student-picture' mode='aspectFill'></image>
</view>
</view>
</view>
<view wx:for="{{records}}">
<view class='timeline-cell'>
<view class='timeline-line-container'>
<view class='timeline-line'></view>
<image class='timeline-cycle' src='/src/img/timeline-cycle.jpeg'></image>
</view>
<view class='kg-quantity-cell timeline-content'>
<view class='kg-flex-row' style='margin-bottom:20rpx;'>
<text class='kg-text-title'>{{item.recordDate}}</text>
<text class='kg-text-normal-gray'>{{item.teacher}}记录</text>
</view>
<view class='timeline-cell'>
<view class='timeline-line-container'>
<view class='timeline-line'></view>
<image class='timeline-cycle' src='/src/img/timeline-cycle.jpeg'></image>
</view>
<view class='kg-quantity-cell timeline-content'>
<view class='kg-flex-row' style='margin-bottom:20rpx;'>
<text class='kg-text-title'>2018-09-11 星期二</text>
<text class='kg-text-normal-gray'>王xx老师记录</text>
</view>
<template is='imgTextView' data="{{img:'eat',text:'饮食'}}"> </template>
<view class='kg-flex-row timeline-content-detail'>
<text class='kg-text-normal-gray'>早餐</text>
<text class='kg-text-normal-gray'>正常</text>
</view>
<view class='kg-flex-row timeline-content-detail'>
<text class='kg-text-normal-gray'>早餐</text>
<text class='kg-text-normal-gray'>正常</text>
</view>
<view class='kg-flex-row timeline-content-detail'>
<text class='kg-text-normal-gray'>早餐</text>
<text class='kg-text-normal-gray'>正常</text>
</view>
<view class='kg-separater' style='height:2rpx;margin-left:100rpx;margin-right:0rpx;'></view>
<!-- 睡觉 -->
<template is='imgTextView' data="{{img:'sleep',text:'睡觉'}}"> </template>
<view class='kg-flex-row timeline-content-detail'>
<text class='kg-text-normal-gray'>午睡</text>
<text class='kg-text-normal-gray'>50分钟</text>
</view>
<view class='kg-separater' style='height:2rpx;margin-left:100rpx;margin-right:0rpx;'></view>
<!-- wc -->
<template is='imgTextView' data="{{img:'wc',text:'WC'}}"> </template>
<view class='kg-flex-row timeline-content-detail'>
<text class='kg-text-normal-gray'>pee</text>
<text class='kg-text-normal-gray'>4次</text>
</view>
<view class='kg-flex-row timeline-content-detail'>
<text class='kg-text-normal-gray'>poo</text>
<text class='kg-text-normal-gray'>4次</text>
</view>
<view class='kg-flex-row timeline-content-detail'>
<text class='kg-text-normal-gray'>diaper</text>
<text class='kg-text-normal-gray'>4次</text>
</view>
<view class='kg-separater' style='height:2rpx;margin-left:100rpx;margin-right:0rpx;'></view>
<!-- 今日照片 -->
<template is='imgTextView' data="{{img:'today',text:'今日照片'}}"> </template>
<view class='home-student-picture-item' style='margin-left:40rpx;'>
<image src='/src/img/student_picture.png' class='home-student-picture' mode='aspectFill'></image>
<image src='/src/img/student_picture.png' class='home-student-picture' mode='aspectFill'></image>
<image src='/src/img/student_picture.png' class='home-student-picture' mode='aspectFill'></image>
<!-- 饮食 -->
<view wx:for="{{item.dietRecord}}" wx:for-item="dietItem" wx:for-index="dietIndex">
<view wx:if="{{dietIndex == 0}}">
<template is='imgTextView' data="{{img:'eat',text:'饮食'}}"> </template>
</view>
<view class='kg-flex-row timeline-content-detail'>
<text class='kg-text-normal-gray'>{{dietItem.z_recordType}}</text>
<text class='kg-text-normal-gray'>正常</text>
</view>
</view>
<!-- 睡觉 -->
<view wx:for="{{item.sleepRecord}}" wx:for-item="sleepItem" wx:for-index="sleepIndex">
<view wx:if="{{sleepIndex == 0}}">
<view class='kg-separater' style='height:2rpx;margin-left:80rpx;margin-right:0rpx;'></view>
<template is='imgTextView' data="{{img:'sleep',text:'睡觉'}}"> </template>
</view>
<view class='kg-flex-row timeline-content-detail'>
<text class='kg-text-normal-gray'>{{sleepItem.z_recordType}}</text>
<text class='kg-text-normal-gray'>{{sleepItem.value}}分钟</text>
</view>
</view>
<!-- wc -->
<view wx:for="{{item.wcRecord}}" wx:for-item="wcItem" wx:for-index="wcIndex">
<view wx:if="{{wcIndex == 0}}">
<view class='kg-separater' style='height:2rpx;margin-left:80rpx;margin-right:0rpx;'></view>
<template is='imgTextView' data="{{img:'wc',text:'WC'}}"> </template>
</view>
<view class='kg-flex-row timeline-content-detail'>
<text class='kg-text-normal-gray'>{{wcItem.z_recordType}}</text>
<text class='kg-text-normal-gray'>{{wcItem.value}}次</text>
</view>
</view>
<view class='kg-separater' style='height:2rpx;margin-left:80rpx;margin-right:0rpx;'></view>
<!-- 今日照片 -->
<template is='imgTextView' data="{{img:'today',text:'今日照片'}}"> </template>
<view class='home-student-picture-item' style='margin-left:40rpx;'>
<image src='/src/img/student_picture.png' class='home-student-picture' mode='aspectFill'></image>
<image src='/src/img/student_picture.png' class='home-student-picture' mode='aspectFill'></image>
<image src='/src/img/student_picture.png' class='home-student-picture' mode='aspectFill'></image>
</view>
</view>
</view>
</view>
</scroll-view>
\ No newline at end of file
project.config.json
View file @
9307bb35
...
...
@@ -4,7 +4,7 @@
"ignore"
:
[]
},
"setting"
:
{
"urlCheck"
:
tru
e
,
"urlCheck"
:
fals
e
,
"es6"
:
true
,
"postcss"
:
true
,
"minified"
:
true
,
...
...
utils/auth.js
0 → 100644
View file @
9307bb35
/**
* 用以持久化和获取access token
*/
const
KEY_ACCESS_TOKENS
=
"__access_tokens__"
;
const
KEY_USER
=
"__user__"
;
/**
* 设置当前用户
*
* @param loginUser 当前登录用户(引用memberService文件调用login()接口的返回值,需含有member信息)
*/
module
.
exports
.
setUser
=
function
(
loginUser
)
{
// 保存当前用户
wx
.
setStorageSync
(
KEY_USER
,
loginUser
)
// 同时保存access token
this
.
setTokens
(
loginUser
);
}
/**
* 取得当前用户
*/
module
.
exports
.
getUser
=
function
()
{
return
wx
.
getStorageSync
(
KEY_USER
)
}
/**
* 保存access tokens
*
* @params tokens {
* "accessToken": "33333",
* "expiresIn": 7200,
* "refreshToken": "4444",
* "refreshExpiresIn": 14400
* },传null表示清空access token
*/
module
.
exports
.
setTokens
=
function
(
tokens
)
{
if
(
!
tokens
)
{
this
.
clearTokens
();
return
}
try
{
wx
.
setStorageSync
(
KEY_ACCESS_TOKENS
,
{
"accessToken"
:
tokens
.
accessToken
,
"expiresTo"
:
new
Date
().
getTime
()
+
parseInt
(
tokens
.
expiresIn
)
*
1000
,
"refreshToken"
:
tokens
.
refreshToken
,
"refreshExpiresTo"
:
new
Date
().
getTime
()
+
parseInt
(
tokens
.
refreshExpiresIn
)
*
1000
})
}
catch
(
e
)
{
}
}
/**
* 清除access tokens
*/
module
.
exports
.
clearTokens
=
function
()
{
try
{
wx
.
removeStorageSync
({
key
:
KEY_ACCESS_TOKENS
})
}
catch
(
e
)
{
}
}
/**
* 取得access tokens
*/
module
.
exports
.
getTokens
=
function
()
{
return
wx
.
getStorageSync
(
KEY_ACCESS_TOKENS
)
}
utils/self.js
0 → 100644
View file @
9307bb35
var
barcode
=
require
(
'../libs/barcode'
);
var
qrcode
=
require
(
'../libs/qrcode'
);
function
convert_length
(
length
)
{
return
Math
.
round
(
wx
.
getSystemInfoSync
().
windowWidth
*
length
/
750
);
}
function
barc
(
id
,
code
,
width
,
height
)
{
barcode
.
code128
(
wx
.
createCanvasContext
(
id
),
code
,
convert_length
(
width
),
convert_length
(
height
))
}
function
qrc
(
id
,
code
,
width
,
height
)
{
qrcode
.
api
.
draw
(
code
,
{
ctx
:
wx
.
createCanvasContext
(
id
),
width
:
convert_length
(
width
),
height
:
convert_length
(
height
)
})
}
module
.
exports
=
{
barcode
:
barc
,
qrcode
:
qrc
}
\ No newline at end of file
utils/util.js
View file @
9307bb35
/**
* 工具类
*/
const
request
=
require
(
'../api/request.js'
)
/**
* 是否隐藏loading
*/
var
_hide_loading
;
const
formatTime
=
date
=>
{
const
year
=
date
.
getFullYear
()
const
month
=
date
.
getMonth
()
+
1
...
...
@@ -9,11 +20,247 @@ const formatTime = date => {
return
[
year
,
month
,
day
].
map
(
formatNumber
).
join
(
'/'
)
+
' '
+
[
hour
,
minute
,
second
].
map
(
formatNumber
).
join
(
':'
)
}
const
formatDate
=
date
=>
{
const
year
=
date
.
getFullYear
()
const
month
=
date
.
getMonth
()
+
1
const
day
=
date
.
getDate
()
return
[
year
,
month
,
day
].
map
(
formatNumber
).
join
(
'-'
)
}
const
formatNumber
=
n
=>
{
n
=
n
.
toString
()
return
n
[
1
]
?
n
:
'0'
+
n
}
// 计算两个经纬度之间的距离
const
distance
=
(
la1
,
lo1
,
la2
,
lo2
)
=>
{
var
La1
=
la1
*
Math
.
PI
/
180.0
;
var
La2
=
la2
*
Math
.
PI
/
180.0
;
var
La3
=
La1
-
La2
;
var
Lb3
=
lo1
*
Math
.
PI
/
180.0
-
lo2
*
Math
.
PI
/
180.0
;
var
s
=
2
*
Math
.
asin
(
Math
.
sqrt
(
Math
.
pow
(
Math
.
sin
(
La3
/
2
),
2
)
+
Math
.
cos
(
La1
)
*
Math
.
cos
(
La2
)
*
Math
.
pow
(
Math
.
sin
(
Lb3
/
2
),
2
)));
s
=
s
*
6378.137
;
//地球半径
s
=
Math
.
round
(
s
*
10000
)
/
10000
;
// console.log("计算结果",s)
return
s
}
//小于10的格式化函数
function
timeFormat
(
param
)
{
return
param
<
10
?
'0'
+
param
:
param
;
}
//倒计时函数
function
countDown
(
teamBuyTimeList
)
{
// 获取当前时间,同时得到活动结束时间数组
const
that
=
this
let
newTime
=
new
Date
().
getTime
()
/
1000
;
let
teamBuyTimeInfoList
=
teamBuyTimeList
;
let
countDownArr
=
[];
// 对结束时间进行处理渲染到页面
teamBuyTimeInfoList
.
forEach
(
o
=>
{
// iOS不兼容?
// let endTime = new Date(o).getTime();
// ios 转换时间戳???
let
date
=
o
.
openTeamTime
.
substr
(
0
,
10
)
//2017-02-27
let
hour
=
o
.
openTeamTime
.
substr
(
11
,
2
)
==
'00'
?
0
:
o
.
openTeamTime
.
substr
(
11
,
2
).
replace
(
/
\b(
0+
)
/gi
,
""
)
let
minute
=
o
.
openTeamTime
.
substr
(
14
,
2
)
==
'00'
?
0
:
o
.
openTeamTime
.
substr
(
14
,
2
).
replace
(
/
\b(
0+
)
/gi
,
""
)
let
second
=
o
.
openTeamTime
.
substr
(
17
,
2
)
==
'00'
?
0
:
o
.
openTeamTime
.
substr
(
17
,
2
).
replace
(
/
\b(
0+
)
/gi
,
""
)
let
timestamp
=
parseInt
(
new
Date
(
date
).
getTime
()
/
1000
)
+
parseInt
(
o
.
duration
)
+
parseInt
(
hour
)
*
3600
+
parseInt
(
minute
)
*
60
+
parseInt
(
second
)
-
28800
//别问我为什么-28800,只能告诉你实践出真知
//var endNewTime = timestampFormat(timestamp)//timestampFormat:自定义的将时间戳转换为刚刚,昨天16:42等表达的方法
let
endTime
=
timestamp
let
obj
=
null
;
// 如果活动未结束,对时间进行处理
if
(
endTime
-
newTime
>
0
)
{
let
time
=
(
endTime
-
newTime
);
// 获取天、时、分、秒
let
day
=
parseInt
(
time
/
(
60
*
60
*
24
));
let
hou
=
parseInt
(
time
%
(
60
*
60
*
24
)
/
3600
)
+
parseInt
(
day
*
24
);
let
min
=
parseInt
(
time
%
(
60
*
60
*
24
)
%
3600
/
60
);
let
sec
=
parseInt
(
time
%
(
60
*
60
*
24
)
%
3600
%
60
);
obj
=
{
//day: this.timeFormat(day),
hou
:
timeFormat
(
hou
),
min
:
timeFormat
(
min
),
sec
:
timeFormat
(
sec
)
}
}
else
{
//活动已结束,全部设置为'00'
obj
=
{
//day: '00',
hou
:
'00'
,
min
:
'00'
,
sec
:
'00'
}
}
countDownArr
.
push
(
obj
)
})
// 渲染,然后每隔一秒执行一次倒计时函数
return
countDownArr
}
// 处理 Access Token 已过期
function
handleLoginStatus
(
error
)
{
if
(
error
.
code
!==
20
)
{
wx
.
showToast
({
title
:
error
.
msg
,
icon
:
'none'
,
duration
:
2000
})
}
}
const
timestampToTime
=
timestamp
=>
{
var
date
=
new
Date
(
timestamp
);
//时间戳为10位需*1000,时间戳为13位的话不需乘1000
var
Y
=
date
.
getFullYear
()
+
'-'
;
var
M
=
(
date
.
getMonth
()
+
1
<
10
?
'0'
+
(
date
.
getMonth
()
+
1
)
:
date
.
getMonth
()
+
1
)
+
'-'
;
var
D
=
formatNumber
(
date
.
getDate
())
+
' '
;
var
h
=
formatNumber
(
date
.
getHours
())
+
':'
;
var
m
=
formatNumber
(
date
.
getMinutes
())
+
':'
;
var
s
=
formatNumber
(
date
.
getSeconds
());
return
Y
+
M
+
D
+
h
+
m
+
s
;
}
/**
* base64解码
* 配合decodeURIComponent使用
*/
function
base64_decode
(
input
)
{
var
base64EncodeChars
=
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/="
;
var
output
=
""
;
var
chr1
,
chr2
,
chr3
;
var
enc1
,
enc2
,
enc3
,
enc4
;
var
i
=
0
;
input
=
input
.
replace
(
/
[^
A-Za-z0-9
\+\/\=]
/g
,
""
);
while
(
i
<
input
.
length
)
{
enc1
=
base64EncodeChars
.
indexOf
(
input
.
charAt
(
i
++
));
enc2
=
base64EncodeChars
.
indexOf
(
input
.
charAt
(
i
++
));
enc3
=
base64EncodeChars
.
indexOf
(
input
.
charAt
(
i
++
));
enc4
=
base64EncodeChars
.
indexOf
(
input
.
charAt
(
i
++
));
chr1
=
(
enc1
<<
2
)
|
(
enc2
>>
4
);
chr2
=
((
enc2
&
15
)
<<
4
)
|
(
enc3
>>
2
);
chr3
=
((
enc3
&
3
)
<<
6
)
|
enc4
;
output
=
output
+
String
.
fromCharCode
(
chr1
);
if
(
enc3
!=
64
)
{
output
=
output
+
String
.
fromCharCode
(
chr2
);
}
if
(
enc4
!=
64
)
{
output
=
output
+
String
.
fromCharCode
(
chr3
);
}
}
return
utf8_decode
(
output
);
}
function
utf8_decode
(
utftext
)
{
// utf-8解码
var
string
=
''
;
let
i
=
0
;
let
c
=
0
;
let
c1
=
0
;
let
c2
=
0
;
while
(
i
<
utftext
.
length
)
{
c
=
utftext
.
charCodeAt
(
i
);
if
(
c
<
128
)
{
string
+=
String
.
fromCharCode
(
c
);
i
++
;
}
else
if
((
c
>
191
)
&&
(
c
<
224
))
{
c1
=
utftext
.
charCodeAt
(
i
+
1
);
string
+=
String
.
fromCharCode
(((
c
&
31
)
<<
6
)
|
(
c1
&
63
));
i
+=
2
;
}
else
{
c1
=
utftext
.
charCodeAt
(
i
+
1
);
c2
=
utftext
.
charCodeAt
(
i
+
2
);
string
+=
String
.
fromCharCode
(((
c
&
15
)
<<
12
)
|
((
c1
&
63
)
<<
6
)
|
(
c2
&
63
));
i
+=
3
;
}
}
return
string
;
}
const
getAccessToken
=
()
=>
{
return
wx
.
getStorageSync
(
'__access_tokens__'
).
accessToken
}
const
uploadPath
=
()
=>
{
return
`
${
request
.
DOMAIN
}
/wxmall/wxsite/file/upload`
}
module
.
exports
=
{
formatTime
:
formatTime
/**
* 设置loading显示隐藏标识
*/
setHideLoading
:
function
(
val
)
{
if
(
val
)
{
_hide_loading
=
true
;
}
else
{
_hide_loading
=
false
;
}
return
_hide_loading
;
},
/**
* 隐藏下一次远程请求的loading
*/
isHideLoading
:
function
()
{
var
b
=
_hide_loading
;
_hide_loading
=
false
;
return
b
},
/**
* 格式化日期
*/
formatTime
:
formatTime
,
/**
* 计算两个经纬度之间的距离
*/
distance
:
distance
,
/**
* 小于10的格式化函数
*/
timeFormat
:
timeFormat
,
/**
* 倒计时函数
* @param openTeamTime 开始时间
* @param duration //持续时间
*/
countDown
:
countDown
,
/**
* 处理 Access Token 已过期
*/
handleLoginStatus
:
handleLoginStatus
,
/**
* 获取Access Token
*/
getAccessToken
:
getAccessToken
,
/**
*
*/
formatDate
:
formatDate
,
/**
* 处理后台上传的图片在前端的显示
*/
handleImgShow
(
imgId
)
{
return
`
${
request
.
DOMAIN
}
/wxmall/commonController.do?viewFile&fileid=
${
imgId
}
`
},
/**
* 时间戳转换时间
*/
timestampToTime
:
timestampToTime
,
/**
* 获取图片上传路径
*/
uploadPath
:
uploadPath
,
/**
* base64解码
*/
base64_decode
:
base64_decode
}
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