uni-app app版本自动更新

<view class="z-index center" v-if="is_update_app">
		<view class="update-box ">
			<view class="box-versions">
				<view class="box-versions-txt1">发现新版本</view>
			</view>
			<view class="versions-context">
				<view class="context-text1">最新版本:{{versions}}</view>
				<view class="context-text1">版本大小:20M</view>
				<view class="context-text1">发布时间:2023-02-01</view>
				<view class="context-text1"></view>
			</view>
			<view class="progress-box " v-if="update_type == 0 && is_update">
				<progress class="progress" border-radius="35px" :percent="prpgress_num" activeColor="#1c89d6" show-info
					stroke-width="10" />
				<view class="progress-des">资源下载中({{download_num_ed}}/{{download_num}}M)</view>
			</view>
			<view class="update-btn" @tap.stop="downloadBtn" v-if="!is_update">立即更新</view>
            <image  class="update-btn-img"src="/static/catalog/logoBig.png" mode="">
		</view>
	</view>
//确定更新
			downloadBtn: function() {
				var ug = plus.os.name; // 安卓手机返回Android
				if (ug != 'Android') {
					plus.runtime.openURL(this.update_url);
					// document.location.href = this.update_url; // 更新地址ios 固定地址
					return
				}
				//整包更新打开浏览器
				if (this.update_type == 1) {
					plus.runtime.openURL(this.update_url);
					this.closeUpdate()
					return
				}

				this.is_update = true
				//下载更新文件
				let that = this
				const downloadTask = uni.downloadFile({
					url: that.update_url,
					success: res => {
						if (res.statusCode == 200) {
							that.installBtn(res.tempFilePath);
							return;
						}
					}
				});

				downloadTask.onProgressUpdate(res => {
					this.prpgress_num = res.progress;
					this.download_num_ed = (res.totalBytesWritten / Math.pow(1024.00, 2)).toFixed(2);
					this.download_num = (res.totalBytesExpectedToWrite / Math.pow(1024.00, 2)).toFixed(2);
				});
			},

			//点击安装
			installBtn: function(path) {
				plus.runtime.install(path, {
					force: false
				}, res => {
					this.$emit('updateClose', {})
					//更新完重启app
					plus.runtime.restart();
				}, err => {
					//重置更新的参数
					this.prpgress_num = 0
					this.download_num_ed = 0
					this.download_num = 0
					this.is_update = false
					this.$emit('updateClose', {})
					uni.showModal({
						title: '更新失败',
						content: err.message,
						showCancel: false,
						success: res => {}
					});

				});
			},

  • 2
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值