// An highlighted block
<template>
<view class="staruppage">
<image class="staruppage_img" src="/static/login/startup.png" mode=""></image>
<view v-if="active" class="staruppage_zhe"></view>
<view v-if="active" class="staruppage_update animated bounceInDown">
<view class="staruppage_update_one">
<view class="staruppage_update_one_img">
<image class="staruppage_update_one_img_on animated flip" src="/static/icon.png" mode=""></image>
</view>
<!-- 发现新版本 -->
<view class="staruppage_update_one_title" v-if="!textatus">
发现新版本 {{VersionName}}
</view>
<view class="staruppage_update_one_title" v-if="textatus">
升级APP
</view>
<view class="staruppage_update_one_title_need" v-if="textatus">
正在为您更新,请耐心等待...
</view>
<view class="staruppage_update_one_text" v-if="!textatus">
{{msg}}
</view>
<Progress v-if="textatus" class="Progress" :Width="num" Type="sparkle"></Progress>
<view @tap="update" class="staruppage_update_one_btn" v-if="!textatus">
立即升级
</view>
</view>
</view>
</view>
</template>
<script>
import Progress from "@/components/Progress-Bar/Progress-Bar.vue"//更新进度组件
export default {
components: {
Progress
},
data() {
return {
active:false,
textatus:false,
url:"",
msg:"",
num:0,
VersionName:0
}
},
onLoad() {
// #ifdef APP-PLUS
var server = "xxxxxxxxxxxxxx"; //检查更新地址
var version=plus.runtime.version
console.log(version)
var req = { //升级检测数据
"version": "xxxxxxx",//版本号
};
uni.request({
url: server,
data: req,
header:{
'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8'
},
success: (res) => {
console.log(res)
//后台返回的下载apk链接
this.url=res.data.Url
console.log(this.url)
// 整包更新
if (res.data.Version!==version) {
//打开提示更新的面板
this.active=true
}
}
})
// #endif
},
methods: {
update(){//更新按钮
this.textatus=true
this.updatenext()
},
updatenext(){
//如果是ios
if (plus.os.name.toLowerCase() == 'ios') {
// 跳转到下载页面
plus.runtime.openURL(this.url)
} else {//如果是安卓
var dtask = plus.downloader.createDownload(
this.url, {},
(d, status)=>{
uni.showToast({
title: '下载完成',
mask: false,
duration: 1000
});
// 下载完成
if (status == 200) {
plus.runtime.install(plus.io.convertLocalFileSystemURL(d.filename), {}, e => e, (error)=>{
uni.showToast({
title: '安装失败-01',
mask: false,
duration: 1500
});
})
} else {
uni.showToast({
title: '更新失败-02',
mask: false,
duration: 1500
});
}
});
try {
dtask.start(); // 开启下载的任务
this.nowD= 0;
dtask.addEventListener('statechanged',(task,status)=>{
// 给下载任务设置一个监听 并根据状态 做操作
switch (task.state) {
case 1:
break;
case 2:
break;
case 3:
this.num = parseInt(//更新进度
(parseFloat(task.downloadedSize) /
parseFloat(task.totalSize)) *
100
);
break;
case 4:
plus.nativeUI.closeWaiting();
//下载完成
break;
}
});
} catch (err) {
plus.nativeUI.closeWaiting();
uni.showToast({
title: '更新失败-03',
mask: false,
duration: 1500
});
}
}
}
}
}
</script>
uniapp版本更新
最新推荐文章于 2024-03-03 17:45:26 发布