<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
<title></title>
<script src="js/mui.min.js"></script>
<script src="js/vue.min.js"></script>
<link href="css/mui.min.css" rel="stylesheet"/>
</head>
<body>
<div id="previewpic">
<ul>
<li v-for="item,index in picData" @tap.stop="clickPic(index)">
<img :src="item" alt="">
</li>
</ul>
</div>
</body>
<script type="text/javascript" charset="utf-8">
mui.plusReady(function () {
var vue = new Vue({
el: '#previewpic',
data: {
picData:[
'http://img-cdn-qiniu.dcloud.net.cn/icon1.png',
'http://img-cdn-qiniu.dcloud.net.cn/icon2.png',
'http://img-cdn-qiniu.dcloud.net.cn/icon3.png',
]
},
created:function(){
this.dqbanben();
},
methods:{
clickPic:function(index){
var _this = this;
plus.nativeUI.previewImage(_this.picData,{
current:index, //点击图片时显示图片的索引值
background:'#000', //图片的背景颜色,值为RGB
indicator: 'number',
loop:true
});
},
//检测当前版本号
dqbanben:function(){
var that=this;
//在页面中初始化plus插件
mui.init();
mui.plusReady(function(){
// 获取本地应用资源版本号
mui.ajaxSettings.async = false;
mui.getJSON("manifest.json",null,function(data){
that.wgtVer=data.version.name;
that.checkUpdate();
});
});
},
//检查更新
checkUpdate:function(){
var that=this;
mui.ajax('http://www.xxx.club/test ', {
type:'post',
dataType:'json',
data:{version:that.wgtVer},
success:function (res) {
console.log(JSON.stringify(res))
if(res.res==1){//跟后台传过来的版本号比对,如果版本号不一致
if (navigator.userAgent.match(/(iPhone|iPod|iPad);?/i)) { //如果是苹果手机
plus.nativeUI.confirm("检测到有新版本,是否更新",function(e){
if(e.index==0){ //如果选择更新
window.location.href="itms-services://?action=download-manifest&url=https://ios.17rua.top/static/ios/x5.plist";
//不经过苹果商店下载(不懂得看我的另一篇文章)
plus.nativeUI.showWaiting("正在下载...");
}
},"",["立即更新","以后再说"]);
return;
}else{
plus.nativeUI.confirm("检测到有新版本,是否更新",function(e){
if(e.index==0){
that.downWgt(res.url);//下载文件;
}else{
plus.runtime.quit();//安卓控制不更新退出应用;
}
},"",["立即更新","以后再说"]);
}
plus.storage.setItem('kbj_banben',true);//检验过一次版本就加入缓存,不在检测
}else{
plus.storage.setItem('kbj_banben',true);
return;
}
},
error:function (error) {
console.log(JSON.stringify(error));
alert("请检查网络连接");
}
});
},
//下载资源包
downWgt:function(wgtUrl){
var that=this;
var task=plus.downloader.createDownload( wgtUrl, {}, function(download,status){ //安装到手机的目录
if ( status == 200 ) {
plus.runtime.install(download.filename); // 安装下载的apk文件
} else {
mui.toast("下载更新失败!");
plus.nativeUI.closeWaiting();
}
});
//监听下载
task.addEventListener("statechanged", function (download, status) {
switch (download.state) {
case 2:
plus.nativeUI.showWaiting("正在下载...");
break;
case 3:
//进度条百分比 totalSize为总量,baifen为当前下载的百分比
if(that.totalSize==0){
that.totalSize=parseInt(download.totalSize);
}
if(parseInt(download.downloadedSize/that.totalSize*100)!=that.baifen){
that.baifen=parseInt(download.downloadedSize/that.totalSize*100);
}
break;
case 4:
mui.toast("下载完成");
plus.nativeUI.closeWaiting();
break;
}
});
task.start();
}
}
})
})
</script>
</html>
mui,hbuilder整包更新App
最新推荐文章于 2021-09-19 08:09:59 发布