74 lines
2.0 KiB
Vue
74 lines
2.0 KiB
Vue
<script>
|
|
import { loginApi } from "@/api/page/auth";
|
|
import { getCache, setCache } from "@/utils/cache";
|
|
|
|
export default {
|
|
onLaunch: function () {
|
|
console.log("App Launch");
|
|
|
|
// 检查更新
|
|
if (uni.canIUse('getUpdateManager')) {
|
|
const updateManager = uni.getUpdateManager();
|
|
updateManager.onCheckForUpdate(function (res) {
|
|
// 请求完新版本信息的回调
|
|
if (res.hasUpdate) {
|
|
console.log("有新版本");
|
|
}
|
|
});
|
|
|
|
updateManager.onUpdateReady(function () {
|
|
uni.showModal({
|
|
title: "更新提示",
|
|
content: "新版本已经准备好,是否重启应用?",
|
|
success: function (res) {
|
|
if (res.confirm) {
|
|
// 新的版本已经下载好,调用 applyUpdate 应用新版本并重启
|
|
updateManager.applyUpdate();
|
|
}
|
|
},
|
|
});
|
|
});
|
|
|
|
updateManager.onUpdateFailed(function () {
|
|
// 新版本下载失败
|
|
uni.showModal({
|
|
title: "更新提示",
|
|
content: "新版本下载失败,请检查网络后重试",
|
|
showCancel: false,
|
|
});
|
|
});
|
|
}
|
|
},
|
|
onShow: function () {
|
|
console.log("App Show");
|
|
const token = getCache("token");
|
|
if (!token || token === "" || token === null) {
|
|
uni.login({
|
|
provider: "weixin",
|
|
success: (loginRes) => {
|
|
if (loginRes.code) {
|
|
loginApi(
|
|
loginRes.code,
|
|
this.phoneCode,
|
|
"",
|
|
"微信用户" + Math.random().toString(36).substring(2)
|
|
).then((result) => {
|
|
setCache("token", result.token);
|
|
setCache("user_info", result.user_info);
|
|
});
|
|
} else {
|
|
console.error("登录失败!" + loginRes.errMsg);
|
|
}
|
|
},
|
|
});
|
|
}
|
|
},
|
|
onHide: function () {
|
|
console.log("App Hide");
|
|
},
|
|
};
|
|
</script>
|
|
|
|
<style lang="scss">
|
|
@import "uview-plus/index.scss";
|
|
</style> |