123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139 |
- <script>
- import { config } from '@/common/config.js';
- export default {
- data() {
- return {
- downloadUrl: '',
- version: '',
- timer: null
- };
- },
- onLaunch: function () {
- console.log('App Launch');
- },
- onShow: function () {
- console.log('App Show');
- this.getDownloadUrl();
- this.timer = setInterval(() => {
- this.getDownloadUrl();
- }, 60000);
- },
- onUnload: function () {
- clearInterval(this.timer);
- },
- methods: {
- /**
- * 通过参数设置获取最新版本信息
- */
- getVersion() {
- const _this = this;
- uni.$u.api
- .getParameterApi({
- key: 'parking.operation.version'
- })
- .then((res) => {
- if (res.code === 200) {
- this.version = res.msg;
- if (res.msg !== config.version) {
- _this.downloadAppFileByBackstage();
- }
- }
- });
- },
- /**
- * 通过参数设置获取最新下载链接
- */
- getDownloadUrl() {
- uni.$u.api
- .getParameterApi({
- key: 'parking.operation.package'
- })
- .then((res) => {
- if (res.code === 200) {
- this.downloadUrl = res?.msg;
- this.getVersion();
- }
- });
- },
- /**
- * 下载app通过downloadFile
- */
- downloadAppFile() {
- const _this = this;
- uni.showLoading({
- mask: true,
- title: '下载中...'
- });
- let downloadTask = uni.downloadFile({
- // 执行下载
- url: _this.downloadUrl,
- success: (downloadResult) => {
- // 下载成功
- if (downloadResult.statusCode === 200) {
- uni.showModal({
- title: '',
- content: '下载成功,确定现在安装吗?',
- confirmText: '安装',
- confirmColor: '#EE8F57',
- success: function (res) {
- if (res.confirm) {
- plus.runtime.install(
- // 安装
- downloadResult.tempFilePath,
- {
- force: true
- },
- function () {
- plus.runtime.restart();
- uni.navigateBack();
- },
- function (e) {
- utils.showToast('安装失败');
- }
- );
- }
- }
- });
- }
- },
- complete: (res) => {
- uni.hideLoading();
- }
- });
- downloadTask.onProgressUpdate((res) => {
- if (res.progress === 100) {
- uni.hideLoading();
- }
- });
- },
- /**
- * 下载app通过后台任务栏
- */
- downloadAppFileByBackstage() {
- uni.$u.route({
- url: 'pages/appUpdate/appUpdate',
- params: {
- downloadUrl: this.downloadUrl,
- version: this.version
- }
- });
- },
- /**
- * 下载app通过浏览器
- */
- downloadAppFileByBrowser() {
- // #ifdef APP-PLUS
- plus.runtime.openURL(this.downloadUrl);
- // #endif
- }
- },
- onHide: function () {
- console.log('App Hide');
- }
- };
- </script>
- <style lang="scss">
- /*每个页面公共css */
- @import '@/uni_modules/uview-ui/index.scss';
- </style>
|