<view>
<view class="codeBox">
<image :src=codeImage alt="" class="imageBox" />
</view>
<view class="orderBox" @click="orderClick">
下载点餐宝
</view>
<view class="progressBox" v-if="update_flag">
<u-line-progress :percent="process" :round="false"></u-line-progress>
</view>
</view>
orderClick() {
this.update_flag = true;
const downloadTask = uni.downloadFile({
url: this.codeUrl,
success: (res) => {
if (res.statusCode == 200) {
this.tempFilePath = res.tempFilePath
} else {
uni.showToast({
title: '下载失败,网络错误',
icon: 'none'
});
}
},
fail: (e) => {
this.update_flag = false;
console.log('下载失败', e);
uni.showToast({
title: '下载失败:' + e.errMsg,
icon: 'none'
});
},
complete: (msg) => {
console.log(msg)
},
});
downloadTask.onProgressUpdate((res) => {
this.process = res.progress;
if (parseInt(this.process) == 100) {
setTimeout(() => {
this.intallApp()
}, 1500)
}
});
},
intallApp() {
plus.runtime.install(
this.tempFilePath, {
force: false
},
() => {
console.log('install success...');
plus.runtime.restart();
},
(e) => {
console.error('install fail...', e);
uni.showToast({
title: '升级失败',
icon: 'none'
});
}
);
},