123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109 |
- <script>
- import config from './config'
- import store from '@/store'
- import {
- getToken
- } from '@/utils/auth'
- import silenceUpdate from '@/uni_modules/rt-uni-update/js_sdk/silence-update.js' //引入静默更新
- import {
- latestEdition,
- download
- } from '@/api/wms/report.js'
- export default {
- data() {
- return {
- timer: null, // 定义一个全局的定时器变量
- aaa:123,
- };
- },
- onLaunch: function() {
- this.initApp()
- // 设置默认的 toast 显示时间为 3000ms (3秒)
- uni.setStorageSync('toastDuration', '5000')
- },
- mounted() {},
- beforeDestroy() {
- this.clearTimer(); // 组件销毁前清除定时器
- },
- onShow() {
- this.initTimer(); // 解锁时重新初始化定时器
- },
- onHide() {
- this.clearTimer(); // 锁屏时清除定时器
- },
- methods: {
- // 初始化应用
- initApp() {
- // 初始化应用配置
- this.initConfig()
- // 检查用户登录状态
- //#ifdef H5
- this.checkLogin()
- //#endif
- },
- initConfig() {
- this.globalData.config = config
- },
- checkLogin() {
- if (!getToken()) {
- this.$tab.reLaunch('/pages/login')
- }
- },
- initTimer() {
- this.timer = setInterval(() => {
- // 每10分钟查询一次是否新版本
- this.version();
- }, 600000);
- },
- clearTimer() {
- if (this.timer) {
- clearInterval(this.timer);
- this.timer = null;
- }
- },
- version() {
- //获取版本号,必须为数字
- let edition_number = ""
- plus.runtime.getProperty(plus.runtime.appid, (inf) => {
- edition_number = inf.versionCode
- //获取版本号,如果没有缓存的版本号再取app的版本号
- //传参
- let params = {
- edition_number: edition_number
- }
- //查询新版本接口
- latestEdition(params).then(res => {
- if (res.code === 200 && res.data) {
- let baseUrl = uni.getStorageSync("baseUrl");
- res.data.edition_url = res.data.edition_url.replace("${baseUrl}", baseUrl);
- if (res.data.package_type == 1 && res.data.edition_silence == 1) {
- //调用静默更新方法 传入下载地址
- silenceUpdate(res.data)
- } else {
- //跳转更新页面 (注意!!!如果pages.json第一页的代码里有一打开就跳转其他页面的操作,下面这行代码最好写在setTimeout里面设置延时3到5秒再执行)
- uni.navigateTo({
- url: '/uni_modules/rt-uni-update/components/rt-uni-update/rt-uni-update?obj=' +
- JSON.stringify(res.data)
- });
- }
- } else {
- // uni.showToast({
- // title: '已是最新版本',
- // icon: 'none'
- // })
- }
- });
- })
- },
- }
- }
- </script>
- <style lang="scss">
- @import '@/static/scss/index.scss'
- </style>
- <style>
- @import '@/static/iconfont/iconfont-weapp-icon.css'
- </style>
|