<template>
|
<view class="mains">
|
<view class="hl" v-if="showTc">
|
<view class="mask"></view>
|
<view class="main">
|
<view class="vers">版本号:{{vers}}</view>
|
<view class="download">{{fieldTwo}}</view>
|
<view class="download_btn" v-if="!waitLine" @tap="upOn">立即升级</view>
|
<view class="download_line" v-if="waitLine">
|
<progress :percent="loadPercent" stroke-width="20" active="true" active-mode="forwards" activeColor="#4587ff" backgroundColor="#a5c8ff"/>
|
<view style="height: 30px;width: 100%; font-size: 26rpx;font-weight: bold; text-align: center;margin-top: -20px;color: #FFFFFF;">下载中,请稍后...</view>
|
</view>
|
</view>
|
</view>
|
</view>
|
|
</template>
|
<script>
|
import { getUserInfo,getToken } from '@/utils/auth';
|
export default {
|
data() {
|
return {
|
serverUrl: uni.getStorageSync('serverUrl')||'http://47.96.97.237/API',
|
showTc:false,
|
// 版本更新
|
loadPercent:0,
|
waitLine: false,
|
timer:'',
|
fieldTwo:'',
|
vers:'',
|
};
|
},
|
props: {
|
|
},
|
created() {
|
// #ifdef APP-PLUS
|
if(uni.getSystemInfoSync().platform !=='ios'){
|
this.update();
|
}else if(uni.getSystemInfoSync().platform =='ios'){
|
uni.showToast({
|
title:'请使用安卓手机,以免发生兼容性问题',
|
icon:'none'
|
})
|
}
|
//#endif
|
},
|
methods: {
|
update() {
|
var _this = this;
|
uni.request({
|
url:_this.serverUrl + '/LMES/AppUpdate',
|
data: { type:'' },
|
success: result => {
|
console.log(1111111,result)
|
// "DowloadPath": 整包更新下载地址,
|
// "HotDowloadPath": 最新热更新下载地址,
|
// "VersionNumber": "最新整包版本",
|
// "HotVersionNumber": "最新版本",
|
// "Content": ""
|
if (result.data.count == 1) {
|
var datas = result.data.data[0]
|
uni.setStorageSync('remarkURL',datas.DowloadPath)
|
plus.runtime.getProperty(plus.runtime.appid, function(inf) {
|
console.log(inf)
|
_this.vers = datas.HotVersionNumber
|
uni.setStorageSync('vers','V' + inf.version)
|
console.log(datas.HotVersionNumber,inf.versionCode,datas.HotVersionNumber > inf.versionCode)
|
if(datas.HotVersionNumber > inf.versionCode){
|
var configType = datas.VersionNumber
|
_this.fieldTwo = datas.Content
|
if(configType > inf.versionCode ){
|
_this.showTc = true
|
console.log(configType,_this.showTc,_this.fieldTwo)
|
}else{
|
uni.showLoading({
|
title:'发现新资源,正在下载中...',
|
mask:true,
|
})
|
uni.downloadFile({
|
url: datas.HotDowloadPath,
|
success: (downloadResult) => {
|
if (downloadResult.statusCode === 200) {
|
uni.hideLoading()
|
plus.runtime.install(downloadResult.tempFilePath, {
|
force: false
|
}, function() {
|
console.log('install success...');
|
plus.runtime.restart();
|
}, function(e) {
|
console.error('install fail...');
|
});
|
}
|
}
|
});
|
}
|
}
|
});
|
}
|
},
|
})
|
},
|
upOn(){
|
this.doUpData();
|
this.loadPercent = 0
|
},
|
doUpData() {
|
this.waitLine = true
|
uni.hideTabBar()
|
this.timer = setInterval(() => {
|
if(this.loadPercent<98){
|
this.loadPercent = this.loadPercent + 1
|
}
|
}, 400);
|
uni.downloadFile({//执行下载
|
url: uni.getStorageSync('remarkURL'), //下载地址
|
success: downloadResult => {//下载成功
|
this.loadPercent = 100
|
this.waitLine = false
|
this.showTc = false
|
uni.showTabBar()
|
if (downloadResult.statusCode == 200) {
|
uni.showModal({
|
title: '',
|
content: '下载成功,确定现在重启吗?',
|
confirmText: '确定',
|
cancelText: '取消',
|
confirmColor: '#4587ff',
|
success: function(res) {
|
this.waitLine = false
|
if (res.confirm == true) {
|
plus.runtime.install(//安装
|
downloadResult.tempFilePath, {
|
force: true
|
},
|
function(res) {
|
utils.showToast('更新成功,重启中...');
|
plus.runtime.restart();
|
}
|
);
|
}else{
|
uni.showModal({
|
content:'更新失败',
|
confirmText:'确认',
|
cancelText:'取消',
|
})
|
}
|
}
|
});
|
}else{
|
this.waitLine = false
|
uni.showModal({
|
content: '请重新下载更新',
|
confirmText:'确认',
|
cancelText:'取消',
|
})
|
}
|
},
|
fail: downloadResult => {//下载失败
|
this.waitLine = false
|
uni.showModal({
|
content:'请重新下载更新',
|
confirmText:'确认',
|
cancelText: '取消',
|
})
|
}
|
});
|
},
|
}
|
};
|
</script>
|
<style scoped lang="scss">
|
.hl{
|
position: fixed;
|
top: 0;
|
left: 0;
|
width: 100vw;
|
height: 100vh;
|
z-index: 9999;
|
.mask{
|
position: absolute;
|
width: 100vw;
|
height: 100vh;
|
background: rgba(#000, .3);
|
}
|
.main{
|
width: 550rpx;
|
height: 730rpx;
|
position: absolute;
|
top: 20vh;
|
left: 100rpx;
|
background-image: url('/static/images/newVer.png');
|
background-position: center;
|
background-repeat: no-repeat;
|
background-size: cover;
|
.vers{
|
margin: 180rpx 0 0 50rpx;
|
color: #fff;
|
font-size: 38rpx;
|
font-weight: bold;
|
}
|
.download{
|
width: 480rpx;
|
margin: 0 auto;
|
margin-top: 150rpx;
|
font-size: 30rpx;
|
color: #333;
|
}
|
.download_btn{
|
width: 420rpx;
|
height: 68rpx;
|
line-height: 68rpx;
|
position: absolute;
|
left: 80rpx;
|
bottom: 40rpx;
|
border-radius: 40rpx;
|
background-color: #4587ff;
|
text-align: center;
|
color: #fff;
|
font-size: 32rpx;
|
box-shadow: 0 2rpx 2rpx 1rpx #1a3562;
|
}
|
.download_line{
|
width: 80%;
|
position: absolute;
|
bottom: 20rpx;
|
left: 10%;
|
}
|
}
|
}
|
</style>
|