apps.js 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. var _config = {url : 'http://58.244.255.94/trs_data/'}
  2. var checkUrl= _config.url + "trsdataAction!checkUpdate.action";
  3. //需要传递当前的版本
  4. function checkUpdate( wgtVer ){
  5. plus.nativeUI.showWaiting("检测更新...");
  6. mui.ajax( checkUrl , { dataType : "json", type : 'POST',
  7. data : {ver : wgtVer},
  8. success : function(json){
  9. plus.nativeUI.closeWaiting();
  10. if( json.success ==true ){
  11. //可以升级
  12. plus.nativeUI.confirm("检测到更新的版本,是否下载升级?",
  13. function(event){
  14. if(event.index ==0){
  15. console.log('下载地址:'+_config.url + json.url)
  16. downWgt(_config.url + json.url); //下载更新版的地址
  17. }
  18. } ,'系统消息',['马上升级','下次再说']);
  19. } else{
  20. plus.nativeUI.toast("无新版本可更新!");
  21. }
  22. },
  23. error : function(xhr, error){
  24. plus.nativeUI.closeWaiting();
  25. plus.nativeUI.toast('检测更新失败!') ;
  26. }
  27. }) ;
  28. }
  29. // 下载wgt文件
  30. function downWgt(wgtUrl){
  31. plus.nativeUI.showWaiting("下载更新文件...");
  32. plus.downloader.createDownload( wgtUrl, {filename:"_doc/update/"}, function(d,status){
  33. if ( status == 200 ) {
  34. //console.log("下载wgt成功:"+d.filename);
  35. installWgt(d.filename); // 安装wgt包
  36. } else {
  37. //console.log("下载wgt失败!");
  38. plus.nativeUI.alert("下载更新失败!");
  39. }
  40. plus.nativeUI.closeWaiting();
  41. }).start();
  42. }
  43. // 更新应用资源
  44. function installWgt(path){
  45. plus.nativeUI.showWaiting("安装更新文件...");
  46. plus.runtime.install(path,{},function(){
  47. plus.nativeUI.closeWaiting();
  48. plus.nativeUI.alert("应用资源更新完成!",function(){
  49. plus.runtime.restart();
  50. });
  51. },function(e){
  52. plus.nativeUI.closeWaiting();
  53. plus.nativeUI.alert("安装更新文件失败["+e.code+"]:"+e.message);
  54. });
  55. }