You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
94 lines
3.6 KiB
94 lines
3.6 KiB
<template> |
|
<view class="container"> |
|
<view class="progressBox"><progress :percent="progress" show-info stroke-width="12" /></view> |
|
<text class="textBox">{{ progress >= 100 ? '下载完成' : '下载中....' }}</text> |
|
</view> |
|
</template> |
|
<script> |
|
export default { |
|
data() { |
|
return { |
|
progress: 0 |
|
}; |
|
}, |
|
/* 生命周期函数--监听页面加载 */ |
|
onLoad: function() { |
|
this.doUpData(); |
|
}, |
|
methods: { |
|
doUpData() { |
|
const version = uni.getStorageSync('version'); |
|
let downloadTask = uni.downloadFile({ |
|
url: `${uni.getStorageSync('server-config').rootUrl}/zhgd-rb-mes/pdaAndroid/updateApp/${version}`, |
|
success: downloadResult => { |
|
console.log(downloadResult); |
|
// 下载成功 |
|
if (downloadResult.statusCode === 200) { |
|
uni.showModal({ |
|
title: '', |
|
content: '下载成功,现在安装吗?', |
|
confirmText: '安装', |
|
confirmColor: '#EE8F57', |
|
success: function(res) { |
|
console.log(res); |
|
if (res.confirm) { |
|
plus.runtime.install( |
|
//安装 |
|
downloadResult.tempFilePath, |
|
{ |
|
force: true |
|
}, |
|
function() { |
|
console.log('更新成功'); |
|
// utils.showToast('更新成功,重启中'); |
|
plus.runtime.restart(); |
|
uni.navigateBack(); |
|
}, |
|
e => { |
|
uni.showToast({ |
|
title: '更新失败!!!', |
|
icon: 'none' |
|
}); |
|
console.log('更新失败'); |
|
} |
|
); |
|
} |
|
if (res.cancel) { |
|
uni.reLaunch({ |
|
url: './login' |
|
}); |
|
} |
|
} |
|
}); |
|
} |
|
}, |
|
complete: () => { |
|
// uni.hideLoading(); |
|
} |
|
}); |
|
downloadTask.onProgressUpdate(res => { |
|
// console.log('下载进度' + res.progress); |
|
this.progress = res.progress; |
|
// console.log('已经下载的数据长度' + res.totalBytesWritten); |
|
// console.log('预期需要下载的数据总长度' + res.totalBytesExpectedToWrite); |
|
// // 测试条件,取消下载任务。 |
|
// if (res.progress > 50) { |
|
// // downloadTask.abort(); |
|
// } |
|
}); |
|
} |
|
} |
|
}; |
|
</script> |
|
<style> |
|
.container { |
|
width: 100%; |
|
} |
|
.progressBox { |
|
padding: 50rpx 20rpx; |
|
} |
|
.textBox { |
|
display: flex; |
|
justify-content: center; |
|
} |
|
</style>
|
|
|