upApp.js 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. import store from '../store/index.js'
  2. import {
  3. getAppBBH
  4. } from "@/api/index.js";
  5. const iosAppStroeUrl =
  6. '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';
  7. // 获取app是否需要升级
  8. export function getUpApp() {
  9. // 获取当前运行系统
  10. let hj = uni.getSystemInfoSync().platform;
  11. // 获取仓库app数据对象
  12. let app = store.state.isShowIllegality;
  13. getAppBBH().then((res) => {
  14. let r = res.data;
  15. console.log(r, 'rdesedaf');
  16. plus.runtime.getProperty(plus.runtime.appid, function(wgtinfo) {
  17. console.log(r,'下载',wgtinfo.versionCode,r.app_version);
  18. if (+r.app_version > +wgtinfo.versionCode) {
  19. uni.showModal({
  20. title: '提示',
  21. content: '请更新应用',
  22. showCancel: false,
  23. success(e) {
  24. if (hj === 'ios') {
  25. plus.runtime.openURL(
  26. iosAppStroeUrl
  27. );
  28. }
  29. if (hj === 'android') {
  30. // plus.runtime.openURL('http://lxscimg.liuniu946.com/lxscV' + version + '.apk');
  31. downApp(r.file_url.app_file);
  32. }
  33. }
  34. });
  35. }
  36. });
  37. }).catch((e) => {
  38. console.log(e);
  39. })
  40. }
  41. // 下载app
  42. export function downApp(version) {
  43. console.log(version,'下载地址');
  44. plus.nativeUI.showWaiting('下载升级包...');
  45. plus.downloader
  46. .createDownload(version, {}, (d, status) => {
  47. console.log(d);
  48. if (status == 200) {
  49. console.log('开始安装');
  50. installApp(d.filename); // 安装app
  51. } else {
  52. plus.nativeUI.alert('下载升级包失败!');
  53. }
  54. plus.nativeUI.closeWaiting();
  55. })
  56. .start();
  57. }
  58. // 安装app
  59. export function installApp(path) {
  60. console.log(path,'安装');
  61. plus.nativeUI.showWaiting('安装升级包...');
  62. plus.runtime.install(
  63. path, {},
  64. function() {
  65. plus.nativeUI.closeWaiting();
  66. uni.showToast({
  67. icon: 'none',
  68. title: '升级完成,准备重新载入'
  69. });
  70. setTimeout(_ => {
  71. uni.hideToast();
  72. plus.runtime.restart();
  73. }, 1000);
  74. },
  75. function(e) {
  76. console.log(e,'安装失败');
  77. plus.nativeUI.closeWaiting();
  78. plus.nativeUI.alert('安装升级包失败[' + e.code + ']:' + e.message);
  79. }
  80. );
  81. }