<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 => {}
});
});
},