// app.js App({ globalData: { // base_url: 'http://192.168.31.112:6544/', // 全局基本接口地址 base_url: 'https://hj.iotposition.com:6544/', // 全局基本接口地址 // base_url: 'http://47.108.70.204:6544/', // 全局基本接口地址 token: null }, onLaunch() { this.checkLogin(res => { console.log('is_login : ', res.is_login); if (!res.is_login) { wx.reLaunch({ url: '/pages/home/home' }) // this.login(); } else { wx.reLaunch({ url: '/pages/index/index' }) // this.login(); } }) }, //微信登录逻辑 login: function () { let _this = this wx.login({ success: (res) => { //console.log("code: " + res.code); wx.request({ url: _this.globalData.base_url + "/wxlogin", header: { 'content-type': 'application/json;charset=UTF-8' }, method: 'POST', data: { code: res.code }, success: (res) => { console.log("token : " + res.data.data) _this.globalData.token = res.data.data wx.setStorage({ key: 'token', data: res.data.data }) }, fail: (error) => { console.error("QwQ请求失败:", error); wx.showToast({ title: '请求失败', icon: 'none', duration: 2000 }); } }) } }) }, //检查是否登录 checkLogin: function (callback) { let _this = this var token = _this.globalData.token if (!token) { token = wx.getStorageSync('token') if (token) { _this.globalData.token = token } else { callback({ is_login: false }) } } // wx.request({ // url: _this.globalData.base_url + "/checkwxlogin", // data: { // token: token // }, // header:{ // Authorization:'Bearer '+ _this.globalData.token // }, // success: (res) => { // console.log(res); // callback({ // is_login: res.data.code == 0 ? true : false // }) // } // }) }, })