mui,hbuilder整包更新App

<!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>
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值