feat: app更新移到login_.vue,引入下载进度
This commit is contained in:
parent
c7e16e8168
commit
041bf0cf7f
|
@ -150,14 +150,21 @@
|
|||
</view>
|
||||
</view>
|
||||
</view>
|
||||
<u-popup :round="10" v-model="dShow" mode="center" border-radius="14">
|
||||
<view style="margin: 30rpx">
|
||||
下载中 请勿退出 {{percentVal}}%
|
||||
</view>
|
||||
|
||||
</u-popup >
|
||||
</view>
|
||||
|
||||
</template>
|
||||
|
||||
<script>
|
||||
export default {
|
||||
data() {
|
||||
return {
|
||||
dShow: false,
|
||||
percentVal: 0,
|
||||
cateAggForm: {
|
||||
start_create: '',
|
||||
is_handled: false,
|
||||
|
@ -189,6 +196,7 @@
|
|||
this.showHeader = false;
|
||||
this.statusHeight = plus.device.uuid; //uniapp打包安卓调用设备唯一标识方法
|
||||
// #endif
|
||||
this.checkVersion()
|
||||
},
|
||||
onShow() {
|
||||
if(this.vuex_user.type==='visitor'||this.vuex_user.type==='driver'){
|
||||
|
@ -205,6 +213,71 @@
|
|||
|
||||
},
|
||||
methods: {
|
||||
checkVersion() {
|
||||
let that = this;
|
||||
uni.getSystemInfo({
|
||||
success(res) {
|
||||
that.$u.vuex('vuex_version', res.appVersion)
|
||||
// #ifdef APP-PLUS
|
||||
if (res.platform == 'android') {
|
||||
that.$u.api.apkCheck().then(res1 => {
|
||||
// console.log(res.appVersion, 2, res1.version)
|
||||
if (res.appVersion < res1.version) {
|
||||
uni.showModal({
|
||||
title: "版本更新",
|
||||
content: '有新的版本发布, 请下载新版本',
|
||||
confirmText: '立即更新',
|
||||
cancelText: '稍后进行',
|
||||
success: function(res2) {
|
||||
if (res2.confirm) {
|
||||
let fullurl = res1.file
|
||||
if(res1.file.indexOf("http") == -1){
|
||||
fullurl = that.vuex_host + res1.file
|
||||
}
|
||||
that.dShow = true // show变量控制一个下载进度弹框(这个UI样式自己写即可)
|
||||
// 创建一个下载任务,并根据后端返回的apk静态资源地址filePath进行下载
|
||||
var dtask = plus.downloader.createDownload(fullurl, {}, function(d, status) {
|
||||
// 下载完成
|
||||
if (status == 200) {
|
||||
that.dShow = false // 下载完成再把下载进度弹框关闭即可
|
||||
plus.runtime.install(plus.io.convertLocalFileSystemURL(d
|
||||
.filename), {}, {}, function(error) {
|
||||
uni.showToast({
|
||||
title: '安装失败',
|
||||
duration: 1500
|
||||
});
|
||||
})
|
||||
} else {
|
||||
uni.showToast({
|
||||
title: '更新失败',
|
||||
duration: 1500
|
||||
});
|
||||
}
|
||||
});
|
||||
function onStateChanged(download, status) {
|
||||
|
||||
if (status == 200) {
|
||||
const totalSize=download.totalSize
|
||||
let nowSize=download.downloadedSize
|
||||
that.percentVal= nowSize / 17700000 * 100 > 99? 99 : (nowSize / 17700000 * 100).toFixed(0)
|
||||
}
|
||||
|
||||
}
|
||||
dtask.addEventListener("statechanged", onStateChanged, false);
|
||||
dtask.start();
|
||||
}
|
||||
else{
|
||||
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
})
|
||||
}
|
||||
// #endif
|
||||
}
|
||||
})
|
||||
},
|
||||
getTicket() {
|
||||
let that = this;
|
||||
that.ticketList = []
|
||||
|
|
Loading…
Reference in New Issue