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