Commit 9ef9a745 by 陈玉桐

增加授权异步promise

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