| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172 |
- <script>
- import config from './config'
- import store from '@/store'
- import { getToken } from '@/utils/auth'
- export default {
- onLaunch: function() {
- this.initApp()
- },
- methods: {
- // 初始化应用
- initApp() {
- // 初始化应用配置
- this.initConfig()
- // 检查用户登录状态
- //#ifdef H5
- // this.checkLogin()
- //#endif
- this.updateManager();
- },
- initConfig() {
- this.globalData.config = config
- },
- /**
- * 小程序主动更新
- */
- updateManager() {
- const updateManager = uni.getUpdateManager();
- updateManager.onCheckForUpdate(res => {
- // 请求完新版本信息的回调
- // console.log(res.hasUpdate)
- })
- updateManager.onUpdateReady(() => {
- uni.showModal({
- title: '更新提示',
- content: '新版本已经准备好,即将重启应用',
- showCancel: false,
- success(res) {
- if (res.confirm) {
- // 新的版本已经下载好,调用 applyUpdate 应用新版本并重启
- updateManager.applyUpdate()
- }
- }
- })
- })
- updateManager.onUpdateFailed(() => {
- // 新的版本下载失败
- uni.showModal({
- title: '更新提示',
- content: '新版本下载失败',
- showCancel: false
- })
- })
- },
- checkLogin() {
- const pages = uni.getCurrentPages();
- const currentPage = pages[pages.length - 1]; // 当前页面
- const currentPagePath = currentPage.$route.path; // 当前页面的路径
- if (!getToken()) {
- this.$tab.reLaunch('/pages/login')
- }
- }
- }
- }
- </script>
- <style lang="scss">
- @import "@/static/iconfont.css";
- @import '@/static/scss/index.scss'
- </style>
|