//app.js
const updateManager = wx.getUpdateManager()
updateManager.onCheckForUpdate(function (res) {
// 请求完新版本信息的回调
console.log(res.hasUpdate)
})
updateManager.onUpdateReady(function () {
wx.showModal({
title: '更新提示',
content: '新版本已经准备好,是否重启应用?',
success: function (res) {
if (res.confirm) {
// 新的版本已经下载好,调用 applyUpdate 应用新版本并重启
updateManager.applyUpdate()
}
}
})
})
updateManager.onUpdateFailed(function () {
// 新版本下载失败
})
App({
data: {
domain: "https://gjapi.xueyayun.cn/",
//domain: "https://ludehealth.com:8082/lude",
encryptedData: null,
iv: null,
frends: wx.getStorageSync("frends"),
soundSwitch: !0
},
globalData: {
userInfo: null,
url:'https://gjapi.xueyayun.cn/'
},
isIphoneX: function() {
return wx.getSystemInfoSync().model.indexOf("iPhone X") >= 0;
},
onLaunch: function () {
// 展示本地存储能力
//var logs = wx.getStorageSync('logs') || []
// logs.unshift(Date.now())
// wx.setStorageSync('logs', logs)
// 登录
/*wx.login({
success: res => {
console.log('已登陆')
// 发送 res.code 到后台换取 openId, sessionKey, unionId
}
})*/
// 获取用户信息
wx.getSetting({
success: res => {
if (res.authSetting['scope.userInfo']) {
// 已经授权,可以直接调用 getUserInfo 获取头像昵称,不会弹框
wx.getUserInfo({
success: res => {
// 可以将 res 发送给后台解码出 unionId
this.globalData.userInfo = res.userInfo
// 由于 getUserInfo 是网络请求,可能会在 Page.onLoad 之后才返回
// 所以此处加入 callback 以防止这种情况
if (this.userInfoReadyCallback) {
this.userInfoReadyCallback(res)
}
}
})
}
}
})
},
getLogin:function(e){
var that = this
wx.login({
success(res) {
if (res.code) {
console.log(res.code);
// 发起网络请求
wx.request({
url: that.globalData.url + 'api/onlogin',
method: 'post',
data: {
code: res.code,
userInfo: e.userInfo
},
header: {
'content-type': 'application/json' // 默认值
},
success(res) {
console.log(res.data);
if (res.data.result == 1) {
try {
wx.setStorage({
key: "skey", //res.data.uid
data: res.data.skey
})
} catch (e) {
}
} else {
console.log(res.data.msg);
}
}
})
} else {
console.log('登录失败!' + res.errMsg)
}
}
})
},
isLogin() { //是否登陆
var that = this;
var skey = wx.getStorageSync('skey')
console.log(skey)
if (skey) {
//that.doLogin();
// 检查 session_key 是否过期
//wx.checkSession({
// session_key 有效(未过期)
// success: function () {
// 业务逻辑处理
// },
// session_key 过期
// fail: function () {
// console.log('失败登陆');
// session_key过期,重新登录
// that.doLogin();
// }
// });
} else {
console.log('未登陆');
//需要登陆
that.doLogin();
}
},
issLogin(url) { //是否登陆
var that = this;
var skey = wx.getStorageSync('skey')
console.log(skey)
if (skey) {
wx.switchTab({
url: "../" + url + "/" + url,
});
// 检查 session_key 是否过期
/*wx.checkSession({
// session_key 有效(未过期)
success: function () {
// 业务逻辑处理
console.log(url);
wx.switchTab({
url: "../" + url + "/" + url,
});
},
// session_key 过期
fail: function () {
// session_key过期,重新登录
that.doLogin();
}
});*/
} else {
console.log('未登陆');
//需要登陆
wx.showModal({
title: "温馨提示",
content: "未登陆,请先点击授权登陆",
showCancel: false,
success: function (t) {
}
});
}
},
doLogin(){
wx.showModal({
title: "温馨提示",
content: "您尚未登陆,请先前往个人中心登陆",
showCancel: false,
success: function (t) {
t.confirm && wx.switchTab({
url: "../user/user"
});
}
});
}
})