From 674cd7a9c2ec8c61086b93f0a9cc1fc50e7f9b6c Mon Sep 17 00:00:00 2001 From: Jerry Yan <792602257@qq.com> Date: Sun, 27 Oct 2019 21:34:28 +0800 Subject: [PATCH] =?UTF-8?q?=E7=89=88=E6=9C=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- js/common.js | 8 ++--- js/index.js | 3 +- js/start.js | 65 +++++++++++++++++++++++--------------- templete/my_help_sale.html | 5 +-- 4 files changed, 48 insertions(+), 33 deletions(-) diff --git a/js/common.js b/js/common.js index 729859d..c19d22c 100644 --- a/js/common.js +++ b/js/common.js @@ -1,10 +1,10 @@ var is_app = 1; var imgUrl = 'http://img.zgqlg.com.cn/'; -// var webUrl = 'http://www.zgqlg.com.cn/'; -// var webUrl1 = 'http://www.zgqlg.com.cn/'; +var webUrl = 'http://www.zgqlg.com.cn/'; +var webUrl1 = 'http://www.zgqlg.com.cn/'; // var imgUrl = 'http://qlg.tsgz.moe:233/'; -var webUrl = 'http://qlg.tsgz.moe:233/'; -var webUrl1 = 'http://qlg.tsgz.moe:233/'; +// var webUrl = 'http://qlg.tsgz.moe:233/'; +// var webUrl1 = 'http://qlg.tsgz.moe:233/'; var cssUrl = localStorage.getItem("cssUrl"); var jsUrl = localStorage.getItem("jsUrl"); var version = localStorage.getItem("version"); diff --git a/js/index.js b/js/index.js index 893bf5a..49d3940 100644 --- a/js/index.js +++ b/js/index.js @@ -57,9 +57,8 @@ mui.plusReady(function() { if (!localStorage.getItem('isFirstDownlodad')) { localStorage.setItem('isFirstDownlodad', true); - } - mui.ajax('http://qlg.tsgz.moe:233/get_version_new.php?' + Math.random(), { + mui.ajax('http://www.zgqlg.com.cn/get_version_new.php?' + Math.random(), { data: {}, dataType: 'json', //服务器返回json格式数据 type: 'post', //HTTP请求类型 diff --git a/js/start.js b/js/start.js index f4b00f5..e4f433e 100644 --- a/js/start.js +++ b/js/start.js @@ -39,40 +39,18 @@ function init(data) { } }); } else if(/android/.test(ua)) { - if(apk_version > ver) { if(must_update == 0) { if(confirm("发现新版本:V" + apk_version + "是否更新")) { - var dtask = plus.downloader.createDownload(apkUrl, {}, function(d, status) { - if(status == 200) { - plus.nativeUI.toast("正在准备环境,请稍后!"); - sleep(1000); - var path = d.filename; //下载apk - plus.runtime.install(path); // 自动安装apk文件 - } else { - mui.alert('版本更新失败:' + status); - } - }); - dtask.start(); + downloadUpdate(apkUrl) } } else { if(confirm("发现新版本:V" + apk_version + "是否更新")) { - var dtask = plus.downloader.createDownload(apkUrl, {}, function(d, status) { - if(status == 200) { - plus.nativeUI.toast("正在准备环境,请稍后!"); - sleep(1000); - var path = d.filename; //下载apk - plus.runtime.install(path); // 自动安装apk文件 - } else { - mui.alert('版本更新失败:' + status); - } - }); - dtask.start(); + downloadUpdate(apkUrl) } else { plus.runtime.quit(); } } - } else { // console.log('当前版本号已是最新'); return; @@ -82,7 +60,44 @@ function init(data) { }) }) }; - +function downloadUpdate(apkUrl){ + let waiting = plus.nativeUI.showWaiting("正在下载更新包"); + var dtask = plus.downloader.createDownload(apkUrl, {}, function(d, status) { + if(status == 200) { + waiting.close() + plus.nativeUI.toast("正在准备环境,请稍后!"); + var path = d.filename; //下载apk + plus.runtime.install(path,{},function(){ + plus.nativeUI.alert("应用资源更新完成!",function(){ + plus.runtime.restart(); + }); + },function(e){ + plus.nativeUI.alert("更新失败["+e.code+"]:"+e.message); + }); // 自动安装apk文件 + } else { + waiting.setTitle("下载失败") + setTimeout(function(){waiting.close()}, 2000) + mui.alert('版本更新失败:' + status); + } + }); + dtask.start(); + dtask.addEventListener("statechanged",function(download, status) { + if(download.state != 4){ + var text = "("+(download.downloadedSize*100/download.totalSize).toFixed(2)+"%)" + waiting.setTitle('正在下载'+text) + } + if(download.state == 4){ + // 下载完成 + if(status == 200){ + waiting.close() + }else{ + waiting.setTitle("下载失败") + setTimeout(function(){waiting.close()}, 2000) + } + console.log("Download success: " + download.getFileName()); + } + },false) +} function jumpPage(ipxSizeBottom) { //跳转页面 diff --git a/templete/my_help_sale.html b/templete/my_help_sale.html index f180841..e294852 100644 --- a/templete/my_help_sale.html +++ b/templete/my_help_sale.html @@ -21,8 +21,9 @@