// app.js const MyApi = require('./Api/api.js'); App({ onLaunch() { const deviceInfo = wx.getDeviceInfo(); console.log({ 登录平台: deviceInfo.platform, 设备品牌: deviceInfo.brand, 设备型号: deviceInfo.model, 内存大小: deviceInfo.memorySize + "MB" }); MyApi.ApiGetConfig() .then(result => { // 将信息存储到本地缓存中 wx.setStorageSync('Config', result); }) .catch(err => { // 失败后执行的代码 console.error("请求失败:"+err); }); 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; this.globalData.HeadiconID= result1.data.HeadiconID; // 将信息存储到本地缓存中 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); MyApi.ApiGetTips() .then(result => { // 将信息存储到本地缓存中 wx.setStorageSync('Tips', result); }) .catch(err => { // 失败后执行的代码 console.error("请求失败:"+err); }); }, globalData: { BaseURL:'https://api.yeomai.site', user_openid: null, YelayMaths_ID: null, IsLogin: null, IsAdministor: null, LastLoginDate: null, UserName: null, NewUser: null, OwnedCourse: null, Tips: null, HeadiconID: null } })