import wxRequest from "./utils/request";
App({
globalData: {
baseUrl: "https://******",
},
onShow() {
this.wxUpload()
},
wxLogin() {
return new Promise((resolve, reject) => {
let access_token = wx.getStorageSync('access_token')
if (access_token) {
resolve()
} else {
wx.login({
success: (res) => {
wxRequest(`user/Wxlogin?code=${res.code}`, "", "POST").then(res => {
wx.setStorageSync('user', res.data.data.user)
wx.setStorageSync('access_token', res.data.data.access_token)
resolve(res)
}).catch(err => {
if (err.data.code == -201) {
wx.reLaunch({
url: '../login/login',
})
}
})
}
})
}
})
},
wxUpload() {
const updateManager = wx.getUpdateManager()
updateManager.onCheckForUpdate((res) => {
if (res.hasUpdate) {
updateManager.onUpdateReady(() => {
wx.showModal({
title: '更新提示',
content: '新版本已经准备好,需要重启应用',
showCancel: false,
confirmColor: "#FF9829",
success: (res) => {
updateManager.applyUpdate()
}
})
})
updateManager.onUpdateFailed(() => {
wx.showModal({
title: '已经有新版本了',
content: '新版本已经上线啦,请您删除当前小程序,搜索好顺佳OA',
confirmColor: "#FF9829",
})
})
}
})
},
})