提交 f57034bf authored 作者: hexi's avatar hexi

增加token 的非空判断

上级 0be25bf0
...@@ -12,10 +12,10 @@ const config = { ...@@ -12,10 +12,10 @@ const config = {
outSiteLink: 'https://e-learning.ezijing.com', // 正式外链 outSiteLink: 'https://e-learning.ezijing.com', // 正式外链
tenant: 'sofia', tenant: 'sofia',
version: '3.0.5' version: '3.0.5'
} };
/* 请求接口统一 重定义 */ /* 请求接口统一 重定义 */
const requestApi = (obj) => { const requestApi = (obj) => {
let _token = wx.getStorageSync('userSession').sessionKey let _token = wx.getStorageSync('userSession').sessionKey;
if (!_token) { if (!_token) {
wx.reLaunch({ url: '/pages/index/index' }) wx.reLaunch({ url: '/pages/index/index' })
return ; return ;
...@@ -54,7 +54,7 @@ const requestApi = (obj) => { ...@@ -54,7 +54,7 @@ const requestApi = (obj) => {
wx.showToast({ title: JSON.stringify(res), icon: 'none' }) wx.showToast({ title: JSON.stringify(res), icon: 'none' })
} }
}) })
} };
/* 工具方法 - 播放时间 转化 h:m:s */ /* 工具方法 - 播放时间 转化 h:m:s */
const durationToTimeString = (duration) => { const durationToTimeString = (duration) => {
let h = Math.floor(duration / 3600); let h = Math.floor(duration / 3600);
...@@ -66,7 +66,7 @@ const durationToTimeString = (duration) => { ...@@ -66,7 +66,7 @@ const durationToTimeString = (duration) => {
let to = { h: tenify(h), m: tenify(m), s: tenify(s) } let to = { h: tenify(h), m: tenify(m), s: tenify(s) }
let format = 'h:m:s'; let format = 'h:m:s';
return format.replace(/h|m|s/g, k => to[k]).replace(/^00\:/, ''); return format.replace(/h|m|s/g, k => to[k]).replace(/^00\:/, '');
} };
/** /**
* 小程序 - 获取用户信息 * 小程序 - 获取用户信息
...@@ -108,7 +108,7 @@ const miniGetInfo = (callback) => { ...@@ -108,7 +108,7 @@ const miniGetInfo = (callback) => {
}, },
fail: res => { wx.hideLoading(); wx.showToast({ title: '用户凭证code获取失败,请重试', icon: 'none' }); } fail: res => { wx.hideLoading(); wx.showToast({ title: '用户凭证code获取失败,请重试', icon: 'none' }); }
}) })
} };
/** /**
* 登录api - 获取 openId 、userName等内容 * 登录api - 获取 openId 、userName等内容
...@@ -133,11 +133,19 @@ const loginApi = (obj, callback) => { ...@@ -133,11 +133,19 @@ const loginApi = (obj, callback) => {
'apikey': 'pP5ECUqRDLDzuh4qRuJro0L1LPgjLP0N' 'apikey': 'pP5ECUqRDLDzuh4qRuJro0L1LPgjLP0N'
}, },
success: res1 => { success: res1 => {
let _token = res1.data.ticket;
if (!_token) {
wx.reLaunch({ url: '/pages/index/index' })
return ;
}
wx.setStorageSync('userSession', { 'sessionKey': _token });
/* 获取用户信息 */ /* 获取用户信息 */
wx.request({ wx.request({
url: config.URL_PATH1 + '/user/check-access', url: config.URL_PATH1 + '/user/check-access',
data: {}, method: 'GET', header: { data: {}, method: 'GET', header: {
token: res1.data.ticket, token: _token,
tenant: config.tenant, tenant: config.tenant,
'apikey': 'pP5ECUqRDLDzuh4qRuJro0L1LPgjLP0N', 'apikey': 'pP5ECUqRDLDzuh4qRuJro0L1LPgjLP0N',
unionid: res.data.union_id unionid: res.data.union_id
...@@ -158,7 +166,7 @@ const loginApi = (obj, callback) => { ...@@ -158,7 +166,7 @@ const loginApi = (obj, callback) => {
} }
} }
}) })
} };
/** /**
* 小程序 - 判断是否需要再次登录 并 跳转页面 * 小程序 - 判断是否需要再次登录 并 跳转页面
...@@ -182,15 +190,8 @@ const LoginAgainAndJumpPage = (callback) => { ...@@ -182,15 +190,8 @@ const LoginAgainAndJumpPage = (callback) => {
// miniGetInfo((res, obj) => { callback(res, obj); }) // miniGetInfo((res, obj) => { callback(res, obj); })
// } // }
miniGetInfo((res, obj) => { callback(res, obj); }) miniGetInfo((res, obj) => { callback(res, obj); })
} };
module.exports = {
config: config,
requestApi: requestApi,
durationToTimeString: durationToTimeString,
LoginAgainAndJumpPage: LoginAgainAndJumpPage,
}
/** /**
* localStorage 中存放的 各种值 * localStorage 中存放的 各种值
* userSession - 调用 login 获取对应的 sessionKey openId等值 * userSession - 调用 login 获取对应的 sessionKey openId等值
...@@ -198,4 +199,11 @@ module.exports = { ...@@ -198,4 +199,11 @@ module.exports = {
* *
* videoCacheCtrlBar * videoCacheCtrlBar
* audioCacheCtrlBar * audioCacheCtrlBar
*/ */
\ No newline at end of file
module.exports = {
'config': config,
requestApi: requestApi,
durationToTimeString: durationToTimeString,
LoginAgainAndJumpPage: LoginAgainAndJumpPage
};
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论