appupgrade.js 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. import api from '@/common/vmeitime-http/'
  2. import conf from '@/config.js'
  3. export default{
  4. checkUpgrade(wgtVer){
  5. let that = this;
  6. plus.nativeUI.showWaiting("检测更新...");
  7. api.app.upgrade({version:wgtVer}).then((res)=>{
  8. plus.nativeUI.closeWaiting();
  9. let resData = res.data;
  10. if( parseInt(resData.code) ==0 ){
  11. //可以升级
  12. plus.nativeUI.confirm("检查到当前版本有最新更新,下载升级?",
  13. function(event){
  14. if(event.index ==0){
  15. console.log('下载地址:'+ conf.server + resData.data.url)
  16. that.downWgt(conf.server + resData.data.url); //下载更新版的地址
  17. }
  18. } ,'系统消息',['马上升级','下次再说']);
  19. } else{
  20. plus.nativeUI.toast("无新版本可更新!");
  21. }
  22. }).catch((e)=>{
  23. plus.nativeUI.closeWaiting();
  24. plus.nativeUI.toast('检测更新失败!') ;
  25. })
  26. },
  27. // 下载wgt文件
  28. downWgt(wgtUrl){
  29. let that = this;
  30. plus.nativeUI.showWaiting("下载更新文件...");
  31. plus.downloader.createDownload( wgtUrl, {filename:"_downloads/update/"}, function(d,status){
  32. if ( status == 200 ) {
  33. //console.log("下载wgt成功:"+d.filename);
  34. that.installWgt(d.filename); // 安装wgt包
  35. } else {
  36. //console.log("下载wgt失败!");
  37. plus.nativeUI.alert("下载更新失败!");
  38. }
  39. plus.nativeUI.closeWaiting();
  40. }).start();
  41. },
  42. // 更新应用资源
  43. installWgt(path){
  44. plus.nativeUI.showWaiting("正在安装更新文件...");
  45. plus.runtime.install(path,{},function(){
  46. plus.nativeUI.closeWaiting();
  47. plus.nativeUI.alert("应用资源更新完成!",function(){
  48. plus.runtime.restart();
  49. });
  50. },function(e){
  51. plus.nativeUI.closeWaiting();
  52. plus.nativeUI.alert("安装更新文件失败["+e.code+"]:"+e.message);
  53. });
  54. }
  55. }