123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299 |
- <!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>
- <link href="css/mui.min.css" rel="stylesheet" />
- <link rel="stylesheet" type="text/css" href="widget/artDialog/6.0.5/css/ui-dialog.min.css">
- <style>
- .ui-dialog-content {
- overflow: auto;
- }
- </style>
- <script type="text/javascript" charset="utf-8">
- mui.init();
- </script>
- </head>
- <body >
- <script src="js/common_http.js" type="text/javascript" charset="utf-8"></script>
- <script src="js/jquery/2.1.3/jquery.js" type="text/javascript" charset="utf-8"></script>
- <script src="widget/artDialog/6.0.5/js/dialog-plus.min.js"></script>
- <script type="text/javascript">
- var wgtVer = null;
- var latestVersion = "";
- function plusReady() {
- if(isdemo == true){
- plus.nativeUI.toast("友情提醒:当前使用版本是演示版本");
- }
-
- // 获取本地应用资源版本号
- plus.runtime.getProperty(plus.runtime.appid, function(inf){
- wgtVer = inf.version;
- console.log("当前应用版本:" + wgtVer);
-
- if(plus.os.name == "iOS") {
- // 检测app小版本的更新
- checkUpgrade();
- } else if(plus.os.name == "Android") {
- // 先检测大版本的更新,如果没有再检测app小版本的更新
- checkVersion();
- }
- //judgePage();
- });
- }
- mui.plusReady(plusReady);
- /*
- * 在安卓条件下检查版本
- */
- function checkVersion() {
- plus.nativeUI.showWaiting();
-
- mui.ajax(server + 'version/app', {
- data: {
- version: 0,//获取当前版本的所有信息,然后以version_int号来校验升级信息
- code: "app_doc"
- },
- dataType: 'json', //服务器返回json格式数据
- type: 'post', //HTTP请求类型
- timeout: 10000, //超时时间设置为10秒;
- success: function(res) {
- console.log(JSON.stringify(res));
- plus.nativeUI.closeWaiting();
- if(res.status == 200) {
- latestVersion = res.data.version_str;
- if(res.data && res.data.version_int && (res.data.version_int > curr_app_version)) {
- var info = {
- version : res.data.version_str,
- size : res.data.size,
- updateContent : res.data.info
- };
- confirmUpgrade(info, function() {
- console.log("下载升级app...");
- plus.runtime.openURL(res.data.url); // 下载升级包
- judgePage();
- });
- }
- else {
- // 没有大版本时就检测小版本的升级
- checkUpgrade();
- }
- } else {
- judgePage();
- }
- },
- error: function(xhr, type, errorThrown) {
- if(type == "timeout" || type == "abort" || type == "error") {
- //mui.confirm("网络异常,请稍后重试!", "", ["退出"], function() {
- // plus.runtime.quit();
- //});
- plus.nativeUI.toast("网络错误: 无法进行版本升级检测!");
- plus.nativeUI.closeWaiting();
- }
- judgePage();
- }
- });
- }
- // 检测app小版本的更新
- function checkUpgrade(){
- plus.nativeUI.showWaiting();
- mui.ajax(server + 'version/app', {
- data: {
- version: 0,//资源包不以version_int号来校验升级信息,而以version_str判断.version_str不相同就会升级。
- code: "wgt"
- },
- dataType: 'json', //服务器返回json格式数据
- type: 'post', //HTTP请求类型
- timeout: 10000, //超时时间设置为10秒;
- success: function(res) {
- console.log(JSON.stringify(res));
- plus.nativeUI.closeWaiting();
- if(res.status == 200) {
- if(res.data && res.data.version_str && wgtVer && (res.data.version_str != wgtVer)) {
- var info = {
- version : res.data.version_str,
- size : res.data.size,
- updateContent : res.data.info
- };
- confirmUpgrade(info, function() {
- console.log("下载升级包...");
- downWgt(res.data.url); // 下载升级包
- });
- } else {
- judgePage();
- }
- } else {
- judgePage();
- }
- },
- error: function(xhr, type, errorThrown) {
- if(type == "timeout" || type == "abort" || type == "error") {
- plus.nativeUI.toast("网络错误: 无法进行版本升级检测!");
- plus.nativeUI.closeWaiting();
- }
- judgePage();
- }
- });
- }
-
- // 下载wgt文件
- function downWgt(wgtUrl){
- plus.nativeUI.showWaiting("正在下载升级文件...");
- plus.downloader.createDownload( wgtUrl, {filename:"_doc/update/"}, function(d,status){
- plus.nativeUI.closeWaiting();
- if ( status == 200 ) {
- console.log("下载升级文件成功:" + d.filename);
- installWgt(d.filename); // 安装wgt包
- } else {
- console.log("下载升级文件失败!");
- plus.nativeUI.alert("下载升级文件失败!");
-
- judgePage();
- }
- }).start();
- }
-
- // 更新应用资源
- function installWgt(path){
- plus.nativeUI.showWaiting("正在安装升级文件...");
- plus.runtime.install(path,{},function(){
- plus.nativeUI.closeWaiting();
- console.log("升级成功!");
- plus.nativeUI.alert("升级完成,请点击确定对App进行重启!",function(){
- plus.runtime.restart();
- });
- },function(e){
- plus.nativeUI.closeWaiting();
- plus.nativeUI.toast("升级失败!错误信息[" + e.code + "]:" + e.message);
- console.log("升级失败["+e.code+"]:"+e.message);
- judgePage();
- });
- }
-
- function confirmUpgrade(info, callback) {
-
- $(document.body).css('background','')
- if (info == null) {
- info = {};
- }
- /*
- var info = {
- version : 'V1.3.0',
- size : 5,
- updateContent : '1.新增签约分析功能<br>2.界面优化<br>3.修复已知Bug'
- }
- */
- var msg = '';
- msg += '<div><div align=left>检测到新版本';
- if (info.version != null) {
- msg += '<b>';
- msg += 'V';
- msg += info.version;
- msg += '</b>';
- }
- msg += ',如不更新,可能导致系统无法正常使用,是否更新? <br><b>温馨提示:</b>本次更新将消耗';
- if (info.size != undefined) {
- msg += info.size;
- msg += 'M';
- } else {
- msg += '一些';
- }
- msg += '数据流量,建议在wifi环境下更新。</div><p></p>';
- if (info.updateContent != null) {
- msg += '<div align=center><b><font size="4">本次更新内容</font></b><br></div><div align=left>';
- msg += info.updateContent;
- msg += '</div>';
- }
-
- dialog({
- height: $(window).height()-100,
- content: msg,
- okValue:'立即更新',
- ok: function (){
- callback();
- },
- cancelValue: '关闭并退出',
- cancel: function () {
- plus.runtime.quit();
- if (plus.os.name == "iOS") {
- mui.toast('请按HOME键退出应用');
- }
- }
- }).showModal();
-
- }
-
- function judgePage() {
- var userAgent = plus.storage.getItem("userAgent");
- if(userAgent) {
- var agent = JSON.parse(userAgent)
- agent.appVersion = wgtVer;
- if(latestVersion) {
- agent.latestVersion = latestVersion;
- }
- plus.navigator.setUserAgent(JSON.stringify(agent));
- } else {
- // var IMEI=plus.device.imei;
- var UUID = plus.device.uuid;
- var userAgentObj = {
- "id": "",
- "uid": "",
- "imei": UUID,
- "token": "",
- "appVersion":wgtVer,
- "platform": 2 //2代表医生端
- };
-
- if(latestVersion) {
- userAgentObj.latestVersion = latestVersion;
- }
- userAgent = JSON.stringify(userAgentObj);
- plus.navigator.setUserAgent(userAgent);
- plus.storage.setItem("userAgent", userAgent);
- }
- /*
- * 判断是否第一次登陆
- */
- var flag = plus.storage.getItem("flag");
- if(flag) {
- // mui.openWindow({
- // url: "html/home/html/main.html",
- // id: "main",
- // sho
- // });
- // mui.openWindow('html/home/html/admin.html', 'admin', {
- //
- // });
- mui.openWindow({
- url:'html/home/html/main.html',
- id:"main",
- show:{
- autoShow:true,//页面loaded事件发生后自动显示,默认为true
- aniShow: false,//页面显示动画,默认为”slide-in-right“;
- duration:0//页面动画持续时间,Android平台默认100毫秒,iOS平台默认200毫秒;
- },
- waiting:{
- autoShow:false
- }
- })
- } else {
- // mui.openWindow('html/login/html/login.html', 'login');
- var loginWv = plus.webview.create("html/login/html/login.html", "login", {
- softinputMode: "adjustResize"
- });
- plus.webview.show(loginWv);
- }
- }
- /*window.addEventListener('resume', function() {
- plusReady();
- });*/
- </script>
- </body>
- </html>
|