当前位置:网站首页>Uniapp hot update with progress bar
Uniapp hot update with progress bar
2022-04-23 05:20:00 【Lora_ 0925】
Be careful : In the use of plus.runtime.install when , If the update is not successful , Please put force Set to true
App.vue file
onLaunch() {
this.HotUpdate();
},
methods: {
HotUpdate() {
// #ifdef APP
let data ={
version:"1.1.0",// Online version
Url:url,// Download update file address
};
plus.runtime.getProperty(plus.runtime.appid, function(widgetInfo) {
let linevison = Number(data.version.replace(/\./g, ""));
let localvsion = Number(widgetInfo.version.replace(/\./g, ""));
if (linevison > localvsion) {
uni.reLaunch({
url: `/pages/UpdatePage/UpdatePage?Url=${data.Url}`,
success: (e) => {
plus.navigator.closeSplashscreen();
},
fail(e) {
plus.navigator.closeSplashscreen();
}
})
} else {
plus.nativeUI
.closeWaiting();
plus.navigator.closeSplashscreen();
}
});
// #endif
},
}
pages/UpdatePage /UpdatePage.vue file
<template>
<view class="update">
<text> Updating, please wait ...</text>
<view class="progress-box">
<progress :percent="percent" show-info stroke-width="6" activeColor="#409eff" backgroundColor="#EBEBEB" />
</view>
</view>
</template>
<script>
export default {
data() {
return {
percent: 0,
Url: ''
}
},
onLoad(option) {
if (option.Url) {
this.Url= option.Url;
this.download()
}
},
methods: {
download() {
let dtask = uni.downloadFile({
url: this.Url,
success: (downloadResult) => {
if (downloadResult.statusCode === 200) {
plus.runtime.install(
downloadResult
.tempFilePath, {
force: true
},
() => {
plus.nativeUI.showWaiting(" The update is successful ");
setTimeout(() => {
plus.nativeUI
.closeWaiting();
plus.runtime.restart();
}, 500);
},
function(e) {
plus.nativeUI.showWaiting(" Installation failed ");
setTimeout(() => {
plus.nativeUI
.closeWaiting();
uni.switchTab({
url: "/pages/index/index"
})
}, 1000);
console.error('install fail...');
});
}
},
fail: (e) => {
plus.nativeUI.closeWaiting();
plus.nativeUI.showWaiting(" Download failed ");
setTimeout(() => {
plus.nativeUI
.closeWaiting();
this.navTo("/pages/index/index");
}, 1000);
}
})
dtask.onProgressUpdate((res) => {
this.percent = res.progress;
})
}
}
}
</script>
<style lang="scss">
/deep/.uni-progress-bar {
border-radius: 200rpx;
.uni-progress-inner-bar {
border-radius: 200rpx;
}
.uni-progress-inf {
color: #606266;
}
}
</style>
<style lang="scss" scoped>
.update {
width: 100vw;
height: 100vh;
background-size: 100% 98%;
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
.progress-box {
margin-top: 10rpx;
width: 75%;
}
}
</style>
版权声明
本文为[Lora_ 0925]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204220546439887.html
边栏推荐
- Basic use of sqlyog
- Flip coin (Blue Bridge Cup)
- Power consumption parameters of Jinbei household mute box series
- Three of three JS (webgl) is simple to draw lines / arcs according to points (based on linegeometry / line2 / linematerial, draw two arc segments based on the center of the circle)
- 青岛敏捷之旅,来了!
- Anti crawler (0): are you still climbing naked with selenium? You're being watched! Crack webdriver anti crawler
- Laravel routing settings
- Minimum spanning tree -- unblocked project hdu1863
- Open source rule engine - Ice: dedicated to solving flexible and complex hard coding problems
- 我这位老程序员对时代危险和机遇的一点感悟?
猜你喜欢
狼叔来找翻译人员了--plato--持续翻译中.....
Three 之 three.js (webgl)简单实现根据点绘制线/弧线(基于LineGeometry / Line2 / LineMaterial,绘制两点基于圆心的弧线段)
Using PHP post temporary file mechanism to upload arbitrary files
My old programmer's perception of the dangers and opportunities of the times?
引入精益管理方式,需要提前做到这九点
Laravel database
JS array common methods
Routing parameters
MySQL external connection, internal connection, self connection, natural connection, cross connection
Redis persistence
随机推荐
Three 之 three.js (webgl)旋转属性函数的简单整理,以及基于此实现绕轴旋转的简单案例
Power consumption parameters of Jinbei household mute box series
Routing parameters
Unique primary key ID of tidb sub table -- solution to failure of sequence and Gorm to obtain primary key
How to add beautiful code blocks in word | a very complete method to sort out and compare
2022年最热门的招聘技术技能是什么,您绝对想不到
configmap
Semi synchronous replication of MariaDB
日志简介和构建web应用
Redis persistence
Study notes: unity customsrp-11-post processing --- bloom
Interesting prime number problem hdu5750
JSP -- Introduction to JSP
Chapter III project schedule management of information system project manager summary
Traversal of tree
工具在数字化转型中扮演了什么样的角色?
Open source rule engine - Ice: dedicated to solving flexible and complex hard coding problems
d.ts---更详细的知识还是需要看官网的介绍(声明文件章节)
Chapter II project scope management of information system project manager summary
The WebService interface writes and publishes calls to the WebService interface (I)