upApp.js 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. import store from '../store/index.js'
  2. import {
  3. upApp
  4. } from '../api/user.js'
  5. let getUpAppUrl = 'http:\/\/gp.liuniu946.com\/uploads\/config\/file\/20220313\/4bc10dc9878fc3be972e626afbde670e.apk'
  6. const iosAppStroeUrl =
  7. 'https://apps.apple.com/cn/app/%E6%BB%A1%E5%9B%AD%E6%98%A5%E7%BA%BF%E4%B8%8A%E5%95%86%E5%9F%8E/id1524593346';
  8. // 获取app是否需要升级
  9. export function getUpApp() {
  10. // 获取当前运行系统
  11. let hj = uni.getSystemInfoSync().platform;
  12. // 获取仓库app数据对象
  13. let app = store.state.isShowIllegality;
  14. // 当前系统为安卓则显示数据
  15. if (hj === 'android') {
  16. // 设置默认显示数据
  17. app = true;
  18. store.commit('changeState', {
  19. name: 'app',
  20. value: app
  21. });
  22. }
  23. upApp({}).then(res => {
  24. let r = res.data;
  25. console.log(res.data,'下载');
  26. plus.runtime.getProperty(plus.runtime.appid, function(wgtinfo) {
  27. try{
  28. // 保存线上版本号
  29. let version = r.app_version;
  30. console.log(version,'吴');
  31. // 获取线上版本
  32. const arr = version.split('.');
  33. console.log(arr,'徐');
  34. // 获取当前系统
  35. const arr1 = wgtinfo.version.split('.');
  36. console.log(arr1,'徐浩岚');
  37. console.log(arr,'222333');
  38. for (let i = 0; i < arr.length; i++) {
  39. // 线上版本号
  40. const x = +arr[i];
  41. // 线下版本号
  42. const y = +arr1[i];
  43. // 判断当前版本是否为小于等于线上版本
  44. console.log(x <= y,'判断',x,y);
  45. if (x > y) {
  46. // 只有ios才需要显示
  47. if (hj === 'ios') {
  48. // 设置显示数据
  49. app = true;
  50. store.commit('changeState', {
  51. name: 'app',
  52. value: app
  53. });
  54. }
  55. // 当版本较低时更新数据
  56. // if (x < y) {
  57. uni.showModal({
  58. title: '提示',
  59. content: '请更新应用',
  60. showCancel: false,
  61. success(e) {
  62. if (hj === 'ios') {
  63. plus.runtime.openURL(
  64. iosAppStroeUrl
  65. );
  66. }
  67. if (hj === 'android') {
  68. plus.runtime.openURL(r.file_url);
  69. // _self.downApp(version);
  70. }
  71. }
  72. });
  73. // }
  74. return;
  75. }
  76. }
  77. }catch(e){
  78. console.log(e,'错误');
  79. }
  80. });
  81. }, )
  82. // uni.request({
  83. // url: getUpAppUrl,
  84. // method: 'GET',
  85. // data: {},
  86. // success:
  87. // });
  88. }
  89. // 下载app
  90. export function downApp(version) {
  91. plus.nativeUI.showWaiting('下载升级包...');
  92. plus.downloader
  93. .createDownload('http://lxscimg.liuniu946.com/lxscV' + version + '.apk', {}, (d, status) => {
  94. if (status == 200) {
  95. installApp(d.filename); // 安装app
  96. } else {
  97. plus.nativeUI.alert('下载升级包失败!');
  98. }
  99. plus.nativeUI.closeWaiting();
  100. })
  101. .start();
  102. }
  103. // 安装app
  104. export function installApp(path) {
  105. plus.nativeUI.showWaiting('安装升级包...');
  106. plus.runtime.install(
  107. path, {},
  108. function() {
  109. plus.nativeUI.closeWaiting();
  110. uni.showToast({
  111. icon: 'none',
  112. title: '升级完成,准备重新载入'
  113. });
  114. setTimeout(_ => {
  115. uni.hideToast();
  116. plus.runtime.restart();
  117. }, 1000);
  118. },
  119. function(e) {
  120. plus.nativeUI.closeWaiting();
  121. plus.nativeUI.alert('安装升级包失败[' + e.code + ']:' + e.message);
  122. }
  123. );
  124. }