body
<view class="bbgxw" v-if="isgx==1">
<view class="bbgx">
<view class="bbgx1">
版本更新提示
</view>
<view class="bbgx2">
发现新版本,快去更新体验吧~
<view class="">
</view>
{{bbh}}
</view>
<view class="gxjd" v-if="isgxjd==1">
<view class="gxjdin" :style="{ jdt + '%' }">
</view>
</view>
<view class="gxjdx" v-if="isgxjd==1">
更新进度:{{jdt}}%
</view>
<view class="bbgx3">
<view class="bbgx31" @tap="quxiao" v-if="isgxjd==0">
下次再说
</view>
<view class="bbgx32" @tap="queding" v-if="isgxjd==0">
立即更新
</view>
</view>
</view>
</view>
css
.bbgxw{
100%;
height: 100%;
position: fixed;
left: 0;
top: 0;
background: rgba(0,0,0,0.5);
z-index: 9999999999;
}
.bbgx{
80%;
height: auto;
background-color: white;
border-radius: 8px;
margin: 0 auto;
margin-top: 200px;
}
.bbgx1{
color: #474F66;
text-align: center;
font-size: 16px;
height: 50px;
100%;
font-weight: bold;
line-height: 50px;
}
.bbgx2{
color: #7A8299;
text-align: center;
font-size: 14px;
height: auto;
90%;
font-weight: 400;
line-height: 30px;
margin: 10px auto;
margin-top: 0px;
}
.bbgx3{
color: #7A8299;
text-align: center;
font-size: 14px;
height:55px;
100%;
font-weight: 400;
line-height: 20px;
margin: 0px auto;
position: relative;
}
.bbgx31{
position: absolute;
36%;
top: 10px;
left: 7%;
height: 30px;
box-sizing: border-box;
line-height: 28px;
text-align: center;
font-size: 14px;
border-radius: 15px;
color: #2385FB;
border: 1px solid #2385FB;
}
.bbgx32{
position: absolute;
36%;
top: 10px;
right: 7%;
height: 30px;
box-sizing: border-box;
line-height: 28px;
background-color: #2385FB;
text-align: center;
font-size: 14px;
border-radius: 15px;
color: #fff;
border: 1px solid #2385FB;
}
.gxjd{
86%;
height: 6px;
border-radius: 3px;
margin: 0 auto;
background: #EDEDED;
position: relative;
overflow: hidden;
}
.gxjdin{
0%;
height: 6px;
border-radius: 3px;
position: absolute;
left: 0;
top: 0;
background: linear-gradient(to right,#4DA5FE,#2D83F4);
}
.gxjdx{
height: 30px;
line-height: 30px;
color: #7A8299;
text-align: center;
font-size: 14px;
height: auto;
90%;
font-weight: 400;
line-height: 30px;
margin: 10px auto;
margin-top: 0px;
}
data
bbh:"",
xzurl:"",
isgx:0,
isgxjd:0,
jdt:0,
onShow() {
// #ifdef APP-PLUS
this.gxck()
// #endif
},
method
quxiao(){
this.isgx=0
},
queding(){
// 获取应用版本号
let version = plus.runtime.version;
console.log(version)
//plus.runtime.openURL(this.xzurl)
if(1){
//整包
/*
权限
<uses-permission android:name="android.permission.INSTALL_PACKAGES"/>
<uses-permission android:name="android.permission.REQUEST_INSTALL_PACKAGES"/>
*/
plus.runtime.openURL(this.xzurl)
}else{
let _this = this
_this.isgxjd=1
// 创建下载任务
const downloadTask = uni.downloadFile({
url: _this.xzurl,
success: (res) => {
if (res.statusCode === 200) {
_this.isgx=0
_this.isgxjd=0
var watiting = plus.nativeUI.showWaiting("安装中...")
// watiting.setTitle("安装中...");
// console.log('>>>>>tempFilePath', res.tempFilePath)
plus.runtime.install(res.tempFilePath, {
force: true
}, function (succ) {
// console.log('install success...');
plus.nativeUI.closeWaiting();
plus.nativeUI.alert('更新完成!', function () {
// 热更新完成自动重启
plus.runtime.restart();
});
}, function (e) {
plus.nativeUI.closeWaiting();
plus.nativeUI.alert('更新失败,点击确认手动更新', function () {
plus.runtime.openURL(_this.xzurl);
plus.runtime.quit();
});
console.error('install fail...', e);
});
}
}
});
downloadTask.onProgressUpdate((res) => {
console.log('下载进度' + res.progress);
// console.log('已经下载的数据长度' + res.totalBytesWritten);
// console.log('预期需要下载的数据总长度' + res.totalBytesExpectedToWrite);
_this.jdt=res.progress
});
}
},
gxck(){
if(0){
this.isgx=0
}else{
this.isgx=1
}
this.bbh='1.0.2'
this.xzurl='https://e1624fbe-0b72-486b-91b2-292a62708202.apk'
uni.request({
url: '',
method: 'GET',
data: {
'token':uni.getStorageSync('token'),
},
success: res => {
//console.log(444)
//console.log(res);
//let version = plus.runtime.version;
},
fail: () => {
},
complete: () => {
}
});
},