Commit 9ef9a745 by 陈玉桐

增加授权异步promise

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