Commit 9ef9a745 by 陈玉桐

增加授权异步promise

parent f9987e18
...@@ -5,44 +5,60 @@ App({ ...@@ -5,44 +5,60 @@ App({
apiUrl: 'https://seex.inner.iouou.cn/AppApi/', apiUrl: 'https://seex.inner.iouou.cn/AppApi/',
}, },
onLaunch: function () { onLaunch: function () {
},
getToken: function () {
let me =this; let me =this;
// 获取本地缓存的token return new Promise(function (resolve, reject) {
wx.getStorage({ // 获取本地缓存的token
key: 'token', wx.getStorage({
fail (res) { key: 'token',
// 没登录(没有token时) fail (res) {
console.log(res.errMsg) // 没登录(没有token时)
wx.login({ console.log(res.errMsg)
success (res) { wx.login({
console.log(res) success (res) {
if (res.code) { console.log(res)
// 发送 res.code 到后台换取 openId, sessionKey, unionId if (res.code) {
wx.request({ // 发送 res.code 到后台换取 openId, sessionKey, unionId
url: me.globalData.apiUrl + 'users/token', wx.request({
method: 'POST', url: me.globalData.apiUrl + 'users/token',
data: { method: 'POST',
code: res.code data: {
}, code: res.code
success: function (res) { },
if(res.data.errno==200){ success: function (res) {
// 获取token并本地缓存 if(res.data.errno==200){
console.log(res.data.data.token) // 获取token并本地缓存
wx.setStorage({ console.log(res.data.data.token)
key: "token", wx.setStorage({
data: res.data.data.token key: "token",
}) data: res.data.data.token
}else{ })
//打印错误信息 let resStatus = {
console.log(res.data.msg) status: 200
}
resolve(resStatus);
}else{
//打印错误信息
console.log(res.data.msg)
reject('error');
}
} }
} })
}) } else {
} else { console.log('获取用户登录态失败!' + res.errMsg);
console.log('登录失败!' + res.errMsg) reject('error');
}
} }
})
},
success(){
let resStatus = {
status: 200
} }
}) resolve(resStatus);
} }
}) })
} });
},
}) })
\ No newline at end of file
{ {
"pages": [ "pages": [
"pages/plan/plan",
"pages/index/index", "pages/index/index",
"pages/historyDetail/historyDetail", "pages/historyDetail/historyDetail",
"pages/user/user", "pages/user/user",
...@@ -7,7 +8,6 @@ ...@@ -7,7 +8,6 @@
"pages/idea/idea", "pages/idea/idea",
"pages/message/message", "pages/message/message",
"pages/updatePlan/updatePlan", "pages/updatePlan/updatePlan",
"pages/plan/plan",
"pages/trainReport/trainReport", "pages/trainReport/trainReport",
"pages/starSort/starSort", "pages/starSort/starSort",
"pages/trainSort/trainSort", "pages/trainSort/trainSort",
......
...@@ -258,7 +258,7 @@ ...@@ -258,7 +258,7 @@
<!-- 内容 --> <!-- 内容 -->
<view id="mustUpdateCon"> <view id="mustUpdateCon">
<view id="mustUpdateTitle">尊敬的家长您好</view> <view id="mustUpdateTitle">尊敬的家长您好</view>
<view id="mustUpdateDes">因您长时间未更新视力信息,眼保仪已被暂时锁定,请您立即前往"训练计划"更新“视力数据”进行解锁!</view> <view id="mustUpdateDes">因您长时间未更新视力信息,眼保仪已被暂时锁定。为了保障孩子的训练成效,请您立即前往"训练计划"更新“视力数据”!</view>
</view> </view>
<!-- 按钮组 --> <!-- 按钮组 -->
<view id="mustUpdateBtn"> <view id="mustUpdateBtn">
......
...@@ -40,8 +40,8 @@ Page({ ...@@ -40,8 +40,8 @@ Page({
// 解绑 // 解绑
unbundle() { unbundle() {
wx.showModal({ wx.showModal({
title: '删除提示', title: '解绑提示',
content: '删除后无法恢复,是否删除?', content: '解除绑定设备后,家长端部分功能将无法使用。',
success (res) { success (res) {
if (res.confirm) { if (res.confirm) {
console.log('用户点击确定') console.log('用户点击确定')
...@@ -60,7 +60,9 @@ Page({ ...@@ -60,7 +60,9 @@ Page({
// 请求成功后关闭Loading // 请求成功后关闭Loading
wx.hideLoading(); wx.hideLoading();
if(res.data.errno==200){ if(res.data.errno==200){
wx.redirectTo({
url: '/pages/index/index'
})
}else{ }else{
wx.showModal({ wx.showModal({
title: '提示', title: '提示',
......
...@@ -108,6 +108,156 @@ Page({ ...@@ -108,6 +108,156 @@ Page({
} }
} }
} }
if(res.data.data.trainingList[0].type=='单词训练'){
// 请求前加Loading
wx.showLoading({
title: '加载中',
mask: true
})
wx.request({
url: app.globalData.apiUrl + 'Trainings/publisher',
method: 'POST',
data: {
token: wx.getStorageSync('token'),
},
success: function (res) {
// // 请求成功后关闭Loading
// wx.hideLoading();
if(res.data.errno==200){
me.setData({
teachArray: res.data.data.list,
})
wx.request({
url: app.globalData.apiUrl + 'Trainings/book',
method: 'POST',
data: {
token: wx.getStorageSync('token'),
publisherId: res.data.data.list[0].id
},
success: function (res) {
// 请求成功后关闭Loading
// wx.hideLoading();
if(res.data.errno==200){
me.setData({
bookArray: res.data.data.data,
})
wx.request({
url: app.globalData.apiUrl + 'Trainings/chapter',
method: 'POST',
data: {
token: wx.getStorageSync('token'),
bookId: res.data.data.data[0].id
},
success: function (res) {
// 请求成功后关闭Loading
wx.hideLoading();
if(res.data.errno==200){
me.setData({
unitArray: res.data.data.data,
})
}else{
wx.showModal({
title: '提示',
showCancel: false,
content: res.data.msg
})
}
}
})
}else{
wx.showModal({
title: '提示',
showCancel: false,
content: res.data.msg
})
}
}
})
}else{
wx.showModal({
title: '提示',
showCancel: false,
content: res.data.msg
})
}
}
})
}
if(res.data.data.trainingList[1].type=='单词训练'){
// 请求前加Loading
wx.showLoading({
title: '加载中',
mask: true
})
wx.request({
url: app.globalData.apiUrl + 'Trainings/publisher',
method: 'POST',
data: {
token: wx.getStorageSync('token'),
},
success: function (res) {
// // 请求成功后关闭Loading
// wx.hideLoading();
if(res.data.errno==200){
me.setData({
teachArray: res.data.data.list,
})
wx.request({
url: app.globalData.apiUrl + 'Trainings/book',
method: 'POST',
data: {
token: wx.getStorageSync('token'),
publisherId: res.data.data.list[0].id
},
success: function (res) {
// 请求成功后关闭Loading
// wx.hideLoading();
if(res.data.errno==200){
me.setData({
bookArray: res.data.data.data,
})
wx.request({
url: app.globalData.apiUrl + 'Trainings/chapter',
method: 'POST',
data: {
token: wx.getStorageSync('token'),
bookId: res.data.data.data[0].id
},
success: function (res) {
// 请求成功后关闭Loading
wx.hideLoading();
if(res.data.errno==200){
me.setData({
unitArraySecond: res.data.data.data,
})
}else{
wx.showModal({
title: '提示',
showCancel: false,
content: res.data.msg
})
}
}
})
}else{
wx.showModal({
title: '提示',
showCancel: false,
content: res.data.msg
})
}
}
})
}else{
wx.showModal({
title: '提示',
showCancel: false,
content: res.data.msg
})
}
}
})
}
}else{ }else{
wx.showModal({ wx.showModal({
title: '提示', title: '提示',
......
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