index.html 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <meta charset="utf-8">
  5. <meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
  6. <title></title>
  7. <script src="js/mui.min.js"></script>
  8. <link href="css/mui.min.css" rel="stylesheet" />
  9. <link rel="stylesheet" type="text/css" href="widget/artDialog/6.0.5/css/ui-dialog.min.css">
  10. <style>
  11. .ui-dialog-content {
  12. overflow: auto;
  13. }
  14. </style>
  15. <script type="text/javascript" charset="utf-8">
  16. mui.init();
  17. </script>
  18. </head>
  19. <body >
  20. <script src="js/common_http.js" type="text/javascript" charset="utf-8"></script>
  21. <script src="js/jquery/2.1.3/jquery.js" type="text/javascript" charset="utf-8"></script>
  22. <script src="widget/artDialog/6.0.5/js/dialog-plus.min.js"></script>
  23. <script type="text/javascript">
  24. var wgtVer = null;
  25. var latestVersion = "";
  26. function plusReady() {
  27. if(isdemo == true){
  28. plus.nativeUI.toast("友情提醒:当前使用版本是演示版本");
  29. }
  30. // 获取本地应用资源版本号
  31. plus.runtime.getProperty(plus.runtime.appid, function(inf){
  32. wgtVer = inf.version;
  33. console.log("当前应用版本:" + wgtVer);
  34. if(plus.os.name == "iOS") {
  35. // 检测app小版本的更新
  36. checkUpgrade();
  37. } else if(plus.os.name == "Android") {
  38. // 先检测大版本的更新,如果没有再检测app小版本的更新
  39. checkVersion();
  40. }
  41. //judgePage();
  42. });
  43. }
  44. mui.plusReady(plusReady);
  45. /*
  46. * 在安卓条件下检查版本
  47. */
  48. function checkVersion() {
  49. plus.nativeUI.showWaiting();
  50. mui.ajax(server + 'version/app', {
  51. data: {
  52. version: 0,//获取当前版本的所有信息,然后以version_int号来校验升级信息
  53. code: "app_doc"
  54. },
  55. dataType: 'json', //服务器返回json格式数据
  56. type: 'post', //HTTP请求类型
  57. timeout: 10000, //超时时间设置为10秒;
  58. success: function(res) {
  59. console.log(JSON.stringify(res));
  60. plus.nativeUI.closeWaiting();
  61. if(res.status == 200) {
  62. latestVersion = res.data.version_str;
  63. if(res.data && res.data.version_int && (res.data.version_int > curr_app_version)) {
  64. var info = {
  65. version : res.data.version_str,
  66. size : res.data.size,
  67. updateContent : res.data.info
  68. };
  69. confirmUpgrade(info, function() {
  70. console.log("下载升级app...");
  71. plus.runtime.openURL(res.data.url); // 下载升级包
  72. judgePage();
  73. });
  74. }
  75. else {
  76. // 没有大版本时就检测小版本的升级
  77. checkUpgrade();
  78. }
  79. } else {
  80. judgePage();
  81. }
  82. },
  83. error: function(xhr, type, errorThrown) {
  84. if(type == "timeout" || type == "abort" || type == "error") {
  85. //mui.confirm("网络异常,请稍后重试!", "", ["退出"], function() {
  86. // plus.runtime.quit();
  87. //});
  88. plus.nativeUI.toast("网络错误: 无法进行版本升级检测!");
  89. plus.nativeUI.closeWaiting();
  90. }
  91. judgePage();
  92. }
  93. });
  94. }
  95. // 检测app小版本的更新
  96. function checkUpgrade(){
  97. plus.nativeUI.showWaiting();
  98. mui.ajax(server + 'version/app', {
  99. data: {
  100. version: 0,//资源包不以version_int号来校验升级信息,而以version_str判断.version_str不相同就会升级。
  101. code: "wgt"
  102. },
  103. dataType: 'json', //服务器返回json格式数据
  104. type: 'post', //HTTP请求类型
  105. timeout: 10000, //超时时间设置为10秒;
  106. success: function(res) {
  107. console.log(JSON.stringify(res));
  108. plus.nativeUI.closeWaiting();
  109. if(res.status == 200) {
  110. if(res.data && res.data.version_str && wgtVer && (res.data.version_str != wgtVer)) {
  111. var info = {
  112. version : res.data.version_str,
  113. size : res.data.size,
  114. updateContent : res.data.info
  115. };
  116. confirmUpgrade(info, function() {
  117. console.log("下载升级包...");
  118. downWgt(res.data.url); // 下载升级包
  119. });
  120. } else {
  121. judgePage();
  122. }
  123. } else {
  124. judgePage();
  125. }
  126. },
  127. error: function(xhr, type, errorThrown) {
  128. if(type == "timeout" || type == "abort" || type == "error") {
  129. plus.nativeUI.toast("网络错误: 无法进行版本升级检测!");
  130. plus.nativeUI.closeWaiting();
  131. }
  132. judgePage();
  133. }
  134. });
  135. }
  136. // 下载wgt文件
  137. function downWgt(wgtUrl){
  138. plus.nativeUI.showWaiting("正在下载升级文件...");
  139. plus.downloader.createDownload( wgtUrl, {filename:"_doc/update/"}, function(d,status){
  140. plus.nativeUI.closeWaiting();
  141. if ( status == 200 ) {
  142. console.log("下载升级文件成功:" + d.filename);
  143. installWgt(d.filename); // 安装wgt包
  144. } else {
  145. console.log("下载升级文件失败!");
  146. plus.nativeUI.alert("下载升级文件失败!");
  147. judgePage();
  148. }
  149. }).start();
  150. }
  151. // 更新应用资源
  152. function installWgt(path){
  153. plus.nativeUI.showWaiting("正在安装升级文件...");
  154. plus.runtime.install(path,{},function(){
  155. plus.nativeUI.closeWaiting();
  156. console.log("升级成功!");
  157. plus.nativeUI.alert("升级完成,请点击确定对App进行重启!",function(){
  158. plus.runtime.restart();
  159. });
  160. },function(e){
  161. plus.nativeUI.closeWaiting();
  162. plus.nativeUI.toast("升级失败!错误信息[" + e.code + "]:" + e.message);
  163. console.log("升级失败["+e.code+"]:"+e.message);
  164. judgePage();
  165. });
  166. }
  167. function confirmUpgrade(info, callback) {
  168. $(document.body).css('background','')
  169. if (info == null) {
  170. info = {};
  171. }
  172. /*
  173. var info = {
  174. version : 'V1.3.0',
  175. size : 5,
  176. updateContent : '1.新增签约分析功能<br>2.界面优化<br>3.修复已知Bug'
  177. }
  178. */
  179. var msg = '';
  180. msg += '<div><div align=left>检测到新版本';
  181. if (info.version != null) {
  182. msg += '<b>';
  183. msg += 'V';
  184. msg += info.version;
  185. msg += '</b>';
  186. }
  187. msg += ',如不更新,可能导致系统无法正常使用,是否更新? <br><b>温馨提示:</b>本次更新将消耗';
  188. if (info.size != undefined) {
  189. msg += info.size;
  190. msg += 'M';
  191. } else {
  192. msg += '一些';
  193. }
  194. msg += '数据流量,建议在wifi环境下更新。</div><p></p>';
  195. if (info.updateContent != null) {
  196. msg += '<div align=center><b><font size="4">本次更新内容</font></b><br></div><div align=left>';
  197. msg += info.updateContent;
  198. msg += '</div>';
  199. }
  200. dialog({
  201. height: $(window).height()-100,
  202. content: msg,
  203. okValue:'立即更新',
  204. ok: function (){
  205. callback();
  206. },
  207. cancelValue: '关闭并退出',
  208. cancel: function () {
  209. plus.runtime.quit();
  210. if (plus.os.name == "iOS") {
  211. mui.toast('请按HOME键退出应用');
  212. }
  213. }
  214. }).showModal();
  215. }
  216. function judgePage() {
  217. var userAgent = plus.storage.getItem("userAgent");
  218. if(userAgent) {
  219. var agent = JSON.parse(userAgent)
  220. agent.appVersion = wgtVer;
  221. if(latestVersion) {
  222. agent.latestVersion = latestVersion;
  223. }
  224. plus.navigator.setUserAgent(JSON.stringify(agent));
  225. } else {
  226. // var IMEI=plus.device.imei;
  227. var UUID = plus.device.uuid;
  228. var userAgentObj = {
  229. "id": "",
  230. "uid": "",
  231. "imei": UUID,
  232. "token": "",
  233. "appVersion":wgtVer,
  234. "platform": 2 //2代表医生端
  235. };
  236. if(latestVersion) {
  237. userAgentObj.latestVersion = latestVersion;
  238. }
  239. userAgent = JSON.stringify(userAgentObj);
  240. plus.navigator.setUserAgent(userAgent);
  241. plus.storage.setItem("userAgent", userAgent);
  242. }
  243. /*
  244. * 判断是否第一次登陆
  245. */
  246. var flag = plus.storage.getItem("flag");
  247. if(flag) {
  248. // mui.openWindow({
  249. // url: "html/home/html/main.html",
  250. // id: "main",
  251. // sho
  252. // });
  253. // mui.openWindow('html/home/html/admin.html', 'admin', {
  254. //
  255. // });
  256. mui.openWindow({
  257. url:'html/home/html/main.html',
  258. id:"main",
  259. show:{
  260. autoShow:true,//页面loaded事件发生后自动显示,默认为true
  261. aniShow: false,//页面显示动画,默认为”slide-in-right“;
  262. duration:0//页面动画持续时间,Android平台默认100毫秒,iOS平台默认200毫秒;
  263. },
  264. waiting:{
  265. autoShow:false
  266. }
  267. })
  268. } else {
  269. // mui.openWindow('html/login/html/login.html', 'login');
  270. var loginWv = plus.webview.create("html/login/html/login.html", "login", {
  271. softinputMode: "adjustResize"
  272. });
  273. plus.webview.show(loginWv);
  274. }
  275. }
  276. /*window.addEventListener('resume', function() {
  277. plusReady();
  278. });*/
  279. </script>
  280. </body>
  281. </html>