|
|
<template>
|
|
|
<view class="updateVersion">
|
|
|
<view class="bg">
|
|
|
<view class="updateTitle">
|
|
|
<text style="text-align: center;color: #35655f;font-size: 32rpx;padding-top: 48rpx;">发现新版本,{{versiondata.newversion}}来啦</text>
|
|
|
</view>
|
|
|
<scroll-view scroll-y class="updateContent">
|
|
|
<text style="font-size: 28rpx;color: #323233;line-height: 40rpx;">{{versiondata.upgradetext}}</text>
|
|
|
</scroll-view>
|
|
|
<view class="bottomBtnWrap">
|
|
|
<view class="bottomBtn" @click="download">
|
|
|
<text style="font-size: 28rpx;text-align: center;line-height: 72rpx;color: #fff;">{{downloadTxt}}({{versiondata.packagesize}})</text>
|
|
|
</view>
|
|
|
</view>
|
|
|
<image style="width: 188rpx;height: 106rpx;position: fixed;left: 8rpx;top: 76rpx;" src="../../../static/image/Vector_1@2x.png" mode=""></image>
|
|
|
<image style="width: 102rpx;height: 76rpx;position: fixed;left: 156rpx;top: 107rpx;" src="../../../static/image/Vector@2x.png" mode=""></image>
|
|
|
<image style="width: 240rpx;height: 212rpx;position: fixed;left: 197rpx;top: 0;" src="../../../static/image/huojian_1@2x.png" mode=""></image>
|
|
|
<image style="width: 128rpx;height: 80rpx;position: fixed;right: 120rpx;top: 118rpx;" src="../../../static/image/Vector_2@2x.png" mode=""></image>
|
|
|
<image style="width: 180rpx;height: 116rpx;position: fixed;right: 8rpx;top: 54rpx;" src="../../../static/image/Vector_3@2x.png" mode=""></image>
|
|
|
</view>
|
|
|
<view class="closeBtn" @click="closeUpdateVersion">
|
|
|
<image style="width: 44rpx;height: 44rpx;" src="../../../static/image/guanbi-70_1@2x.png" mode=""></image>
|
|
|
</view>
|
|
|
</view>
|
|
|
</template>
|
|
|
|
|
|
<script>
|
|
|
var apiUrl = 'http://app.zhaodizhu.cn/api'
|
|
|
var version = '1.0'//当前应用版本
|
|
|
export default {
|
|
|
data(){
|
|
|
return{
|
|
|
downloadTxt:'立即升级',
|
|
|
versiondata:{}
|
|
|
}
|
|
|
},
|
|
|
onLoad() {
|
|
|
uni.request({
|
|
|
url:apiUrl + '/common/init',
|
|
|
method:'GET',
|
|
|
data:{
|
|
|
version:version
|
|
|
},
|
|
|
success: (res) => {
|
|
|
console.log('版本',res)
|
|
|
this.versiondata = res.data.data.versiondata
|
|
|
}
|
|
|
})
|
|
|
},
|
|
|
methods:{
|
|
|
closeUpdateVersion(){
|
|
|
const subNVue = uni.getSubNVueById('updateVersion')
|
|
|
// 关闭 nvue 子窗体
|
|
|
subNVue.hide('fade-out',500)
|
|
|
},
|
|
|
download(){
|
|
|
const subNVue = uni.getSubNVueById('updateVersion')
|
|
|
// 关闭 nvue 子窗体
|
|
|
subNVue.hide('fade-out',500)
|
|
|
if (plus.os.name.toLowerCase() == 'ios') {
|
|
|
// 跳转到下载页面
|
|
|
plus.runtime.openURL(this.versiondata.downloadurl)
|
|
|
} else {
|
|
|
var dtask = plus.downloader.createDownload(
|
|
|
this.versiondata.downloadurl, {},
|
|
|
function(d, status) {
|
|
|
uni.showToast({
|
|
|
title: '下载完成',
|
|
|
mask: false,
|
|
|
duration: 1000
|
|
|
});
|
|
|
// 下载完成
|
|
|
if (status == 200) {
|
|
|
plus.runtime.install(plus.io.convertLocalFileSystemURL(d.filename), {}, e => e, function(error) {
|
|
|
uni.showToast({
|
|
|
title: '安装失败',
|
|
|
mask: false,
|
|
|
duration: 1500
|
|
|
});
|
|
|
})
|
|
|
} else {
|
|
|
uni.showToast({
|
|
|
title: '更新失败',
|
|
|
mask: false,
|
|
|
duration: 1500
|
|
|
});
|
|
|
}
|
|
|
});
|
|
|
try {
|
|
|
dtask.start(); // 开启下载的任务
|
|
|
var prg = 0;
|
|
|
var showLoading = plus.nativeUI.showWaiting("正在下载"); //创建一个showWaiting对象
|
|
|
dtask.addEventListener('statechanged', function(
|
|
|
task,
|
|
|
status
|
|
|
) {
|
|
|
// 给下载任务设置一个监听 并根据状态 做操作
|
|
|
switch (task.state) {
|
|
|
case 1:
|
|
|
showLoading.setTitle("正在下载");
|
|
|
break;
|
|
|
case 2:
|
|
|
showLoading.setTitle("已连接到服务器");
|
|
|
break;
|
|
|
case 3:
|
|
|
prg = parseInt(
|
|
|
(parseFloat(task.downloadedSize) /
|
|
|
parseFloat(task.totalSize)) *
|
|
|
100
|
|
|
);
|
|
|
showLoading.setTitle(" 正在下载" + prg + "% ");
|
|
|
break;
|
|
|
case 4:
|
|
|
plus.nativeUI.closeWaiting();
|
|
|
//下载完成
|
|
|
break;
|
|
|
}
|
|
|
});
|
|
|
} catch (err) {
|
|
|
plus.nativeUI.closeWaiting();
|
|
|
uni.showToast({
|
|
|
title: '更新失败',
|
|
|
mask: false,
|
|
|
duration: 1500
|
|
|
});
|
|
|
}
|
|
|
}
|
|
|
/* if(this.downloadTxt == '下载中'){
|
|
|
return
|
|
|
}
|
|
|
this.downloadTxt = '下载中'
|
|
|
const downloadTask = uni.downloadFile({
|
|
|
url: this.versiondata.downloadurl, //仅为示例,并非真实的资源
|
|
|
success: (res) => {
|
|
|
if (res.statusCode === 200) {
|
|
|
console.log('下载成功');
|
|
|
}
|
|
|
}
|
|
|
});
|
|
|
downloadTask.onProgressUpdate((res) => {
|
|
|
console.log('下载进度' + res.progress);
|
|
|
console.log('已经下载的数据长度' + res.totalBytesWritten);
|
|
|
console.log('预期需要下载的数据总长度' + res.totalBytesExpectedToWrite);
|
|
|
|
|
|
// 测试条件,取消下载任务。
|
|
|
if (res.progress > 50) {
|
|
|
downloadTask.abort();
|
|
|
}
|
|
|
}); */
|
|
|
/* console.log('11111111111111111',this.versiondata.downloadurl)
|
|
|
uni.downloadFile({
|
|
|
url: this.versiondata.downloadurl, //仅为示例,并非真实的资源
|
|
|
success: (res) => {
|
|
|
console.log('下载成功',res);
|
|
|
if (res.statusCode === 200) {
|
|
|
console.log('下载成功');
|
|
|
}
|
|
|
},
|
|
|
fail: (err) => {
|
|
|
console.log('下载失败',err)
|
|
|
}
|
|
|
}); */
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
</script>
|
|
|
|
|
|
<style lang="scss" scoped>
|
|
|
.updateVersion{
|
|
|
padding-top: 157rpx;
|
|
|
.bg{
|
|
|
position: relative;
|
|
|
width: 622rpx;
|
|
|
height: 424rpx;
|
|
|
border-radius: 30rpx;
|
|
|
background-color: #fff;
|
|
|
.updateTitle{
|
|
|
height: 112rpx;
|
|
|
}
|
|
|
.updateContent{
|
|
|
height: 192rpx;
|
|
|
padding: 0 48rpx;
|
|
|
}
|
|
|
.bottomBtnWrap{
|
|
|
height: 120rpx;
|
|
|
flex-direction: row;
|
|
|
justify-content: center;
|
|
|
align-items: center;
|
|
|
.bottomBtn{
|
|
|
width: 526rpx;
|
|
|
height: 72rpx;
|
|
|
opacity: 1;
|
|
|
background-color: #82c7c2;
|
|
|
border-radius: 36rpx;
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
.closeBtn{
|
|
|
width: 622rpx;
|
|
|
height: 120rpx;
|
|
|
flex-direction: row;
|
|
|
align-items: flex-end;
|
|
|
justify-content: center;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
|
|
|
</style> |
...
|
...
|
|