Commit 9ef9a745 by 陈玉桐

增加授权异步promise

parent f9987e18
...@@ -5,7 +5,10 @@ App({ ...@@ -5,7 +5,10 @@ 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;
return new Promise(function (resolve, reject) {
// 获取本地缓存的token // 获取本地缓存的token
wx.getStorage({ wx.getStorage({
key: 'token', key: 'token',
...@@ -31,18 +34,31 @@ App({ ...@@ -31,18 +34,31 @@ App({
key: "token", key: "token",
data: res.data.data.token data: res.data.data.token
}) })
let resStatus = {
status: 200
}
resolve(resStatus);
}else{ }else{
//打印错误信息 //打印错误信息
console.log(res.data.msg) 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",
......
...@@ -355,6 +355,7 @@ Page({ ...@@ -355,6 +355,7 @@ Page({
rightEye: '', rightEye: '',
leftEye: '', leftEye: '',
imgUrls: [], imgUrls: [],
bindDeviceStatus: '',//是否绑定设备 1绑定,0未绑定
indicatorDots: true, indicatorDots: true,
autoplay: false, autoplay: false,
interval: 5000, interval: 5000,
...@@ -408,12 +409,12 @@ Page({ ...@@ -408,12 +409,12 @@ Page({
}) })
}, },
onReady() { onReady() {
// setTimeout(function () {
// // 获取 chartWeek 实例的方式
// console.log(chartWeek)
// }, 2000);
let me = this; let me = this;
app.getToken().then(function (res) {
if (res.status == 200){
// 请求前加Loading // 请求前加Loading
console.log(wx.getStorageSync('token'))
wx.showLoading({ wx.showLoading({
title: '加载中', title: '加载中',
mask: true mask: true
...@@ -466,7 +467,7 @@ Page({ ...@@ -466,7 +467,7 @@ Page({
me.setData({ me.setData({
imgUrls: res.data.data.focusMap, imgUrls: res.data.data.focusMap,
bindDeviceStatus: res.data.data.bindDeviceStatus,
teenageName: res.data.data.teenageList[0].name, teenageName: res.data.data.teenageList[0].name,
gender: res.data.data.teenageList[0].gender, gender: res.data.data.teenageList[0].gender,
age: res.data.data.teenageList[0].age, age: res.data.data.teenageList[0].age,
...@@ -569,20 +570,41 @@ Page({ ...@@ -569,20 +570,41 @@ Page({
} }
} }
}) })
}else{
console.log(res);
}
});
}, },
onHide() { onHide() {
}, },
// 权限设置 // 个人设置
set:function(){ set:function(){
if(this.data.bindDeviceStatus==1){
wx.navigateTo({ wx.navigateTo({
url: '/pages/setting/setting' url: '/pages/setting/setting'
}) })
}else{
wx.showModal({
title: '提示',
showCancel: false,
content: "您未绑定设备部分功能将无法使用"
})
}
}, },
// 训练计划 // 训练计划
plan:function(){ plan:function(){
if(this.data.bindDeviceStatus==1){
wx.navigateTo({ wx.navigateTo({
url: '/pages/plan/plan' url: '/pages/plan/plan'
}) })
}else{
wx.showModal({
title: '提示',
showCancel: false,
content: "您未绑定设备部分功能将无法使用"
})
}
}, },
// 小目标 // 小目标
target:function(){ target:function(){
...@@ -592,6 +614,7 @@ Page({ ...@@ -592,6 +614,7 @@ Page({
}, },
// 立即关机 // 立即关机
PowerOff: function () { PowerOff: function () {
if(this.data.bindDeviceStatus==1){
wx.showModal({ wx.showModal({
title: '控制提示', title: '控制提示',
content: '关机后使用机器时需要再次开机,是否确认关机?', content: '关机后使用机器时需要再次开机,是否确认关机?',
...@@ -633,6 +656,13 @@ Page({ ...@@ -633,6 +656,13 @@ Page({
} }
} }
}) })
}else{
wx.showModal({
title: '提示',
showCancel: false,
content: "您未绑定设备部分功能将无法使用"
})
}
}, },
// 刷新获取设备屏幕图片 // 刷新获取设备屏幕图片
refresh: function () { refresh: function () {
...@@ -676,27 +706,59 @@ Page({ ...@@ -676,27 +706,59 @@ Page({
preventTouchMove() {}, preventTouchMove() {},
// 个人中心 // 个人中心
toMine() { toMine() {
if(this.data.bindDeviceStatus==1){
wx.navigateTo({ wx.navigateTo({
url: '/pages/mine/mine' url: '/pages/mine/mine'
}) })
}else{
wx.showModal({
title: '提示',
showCancel: false,
content: "您未绑定设备部分功能将无法使用"
})
}
}, },
// 训练报告 // 训练报告
trainReport() { trainReport() {
if(this.data.bindDeviceStatus==1){
wx.navigateTo({ wx.navigateTo({
url: '/pages/trainReport/trainReport' url: '/pages/trainReport/trainReport'
}) })
}else{
wx.showModal({
title: '提示',
showCancel: false,
content: "您未绑定设备部分功能将无法使用"
})
}
}, },
// 训练排行 // 训练排行
toTrainSort() { toTrainSort() {
if(this.data.bindDeviceStatus==1){
wx.navigateTo({ wx.navigateTo({
url: '/pages/trainSort/trainSort' url: '/pages/trainSort/trainSort'
}) })
}else{
wx.showModal({
title: '提示',
showCancel: false,
content: "您未绑定设备部分功能将无法使用"
})
}
}, },
// 光明之星 // 光明之星
toStarSort() { toStarSort() {
if(this.data.bindDeviceStatus==1){
wx.navigateTo({ wx.navigateTo({
url: '/pages/starSort/starSort' url: '/pages/starSort/starSort'
}) })
}else{
wx.showModal({
title: '提示',
showCancel: false,
content: "您未绑定设备部分功能将无法使用"
})
}
}, },
// 稍后前往 // 稍后前往
lastGo: function () { lastGo: function () {
......
...@@ -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