feat: app更新移到login_.vue,引入下载进度

This commit is contained in:
caoqianming 2023-04-12 08:40:56 +08:00
parent c7e16e8168
commit 041bf0cf7f
1 changed files with 74 additions and 1 deletions

View File

@ -150,14 +150,21 @@
</view> </view>
</view> </view>
</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> </template>
<script> <script>
export default { export default {
data() { data() {
return { return {
dShow: false,
percentVal: 0,
cateAggForm: { cateAggForm: {
start_create: '', start_create: '',
is_handled: false, is_handled: false,
@ -189,6 +196,7 @@
this.showHeader = false; this.showHeader = false;
this.statusHeight = plus.device.uuid; //uniapp this.statusHeight = plus.device.uuid; //uniapp
// #endif // #endif
this.checkVersion()
}, },
onShow() { onShow() {
if(this.vuex_user.type==='visitor'||this.vuex_user.type==='driver'){ if(this.vuex_user.type==='visitor'||this.vuex_user.type==='driver'){
@ -205,6 +213,71 @@
}, },
methods: { 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 // showUI
// apkfilePath
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() { getTicket() {
let that = this; let that = this;
that.ticketList = [] that.ticketList = []