当前位置:网站首页>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
边栏推荐
- Simple application of parallel search set (red alarm)
- 4 个最常见的自动化测试挑战及应对措施
- 使用zerotier让异地设备组局域网
- 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)
- Barcode generation and decoding, QR code generation and decoding
- !!!!!!!!!!!!!!!!!!
- Jupyter notebook crawling web pages
- Three 之 three.js (webgl)简单实现根据点绘制线/弧线(基于LineGeometry / Line2 / LineMaterial,绘制两点基于圆心的弧线段)
- 2021 年 25 大 DevOps 工具(下)
- 学习笔记:Unity CustomSRP-10-Point and Spot Shadows
猜你喜欢
4 most common automated test challenges and Countermeasures
何时适合进行自动化测试?(下)
C#测试调用PaddleSharp模块识别图片文字
Summary of MySQL knowledge points
Modèle axé sur le domaine DDD (III) - gestion des transactions à l'aide de Saga
如何在Word中添加漂亮的代码块 | 很全的方法整理和比较
What are the most popular recruitment technical skills in 2022? You can't think of it
The WebService interface writes and publishes calls to the WebService interface (I)
2021-10-25
引入精益管理方式,需要提前做到这九点
随机推荐
Minimum spanning tree -- unblocked project hdu1863
Summary of MySQL knowledge points
Data security has become a hidden danger. Let's see how vivo can make "user data" armor again
Golang memory escape
领域驱动模型DDD(三)——使用Saga管理事务
Pandas to_ SQL function pit avoidance guide "with correct code to run"
The WebService interface writes and publishes calls to the WebService interface (I)
mariadb数据库的主从复制
C language hash dictionary and notes
Locks and transactions in MySQL
MySQL circularly adds sequence numbers according to the values of a column
Asynchronous iterator & asynchronous generator & asynchronous context manager
Swing display time (click once to display once)
[untitled] kimpei kdboxpro's cool running lantern coexists with beauty and strength
好的测试数据管理,到底要怎么做?
App Store年交易额100万美元只缴15%佣金,中小开发者心里很矛盾
Qingdao agile tour, coming!
Three 之 three.js (webgl)模型的删除/场景的清空/内存的释放 的简单整理
Data management of basic operation of mairadb database
Anti crawler (0): are you still climbing naked with selenium? You're being watched! Crack webdriver anti crawler