66 lines
1.9 KiB
JavaScript
66 lines
1.9 KiB
JavaScript
// app.js
|
|
const MyApi = require('./Api/api.js');
|
|
|
|
App({
|
|
onLaunch() {
|
|
|
|
MyApi.ApiGetUserOpenID()
|
|
.then(result => {
|
|
// 获取code成功后执行的代码
|
|
this.globalData.user_openid = result;
|
|
|
|
// 使用code查询数据库,查到则获取信息,没查到则建立新用户后,再次查询数据库输出结果
|
|
MyApi.ApiGetUserDataFromDB(result)
|
|
.then(result1 => {
|
|
// 成功后执行的代码
|
|
this.globalData.YelayMaths_ID= result1.data.YelayMaths_ID;
|
|
this.globalData.IsLogin= result1.data.是否登录;
|
|
this.globalData.IsAdministor= result1.data.是否管理员;
|
|
this.globalData.LastLoginDate= result1.data.最后登录日期;
|
|
this.globalData.UserName= result1.data.用户名;
|
|
this.globalData.NewUser= result1.result;
|
|
// 将信息存储到本地缓存中
|
|
wx.setStorageSync('UserInfoCache', this.globalData);
|
|
|
|
//查询用户课程数据
|
|
MyApi.ApiGetUserCourseDataFromDB(result)
|
|
.then(result => {
|
|
this.globalData.OwnedCourse = result.data;
|
|
// 将信息存储到本地缓存中
|
|
wx.setStorageSync('UserInfoCache', this.globalData);
|
|
})
|
|
.catch(err => {
|
|
console.log("错误!");
|
|
})
|
|
|
|
|
|
|
|
})
|
|
.catch(err1 => {
|
|
// 失败后执行的代码
|
|
console.error("请求失败:"+err1);
|
|
});
|
|
|
|
})
|
|
.catch(err => {
|
|
// 失败后执行的代码
|
|
console.error("请求失败:"+err);
|
|
});
|
|
|
|
|
|
// 将信息存储到本地缓存中
|
|
wx.setStorageSync('UserInfoCache', this.globalData);
|
|
},
|
|
globalData: {
|
|
BaseURL:'https://api.yeomai.site',
|
|
user_openid: null,
|
|
YelayMaths_ID: null,
|
|
IsLogin: null,
|
|
IsAdministor: null,
|
|
LastLoginDate: null,
|
|
UserName: null,
|
|
NewUser: null,
|
|
OwnedCourse: null
|
|
}
|
|
})
|