upApp.js 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  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. plus.runtime.getProperty(plus.runtime.appid, function(wgtinfo) {
  16. if (+r.app_version > +wgtinfo.versionCode) {
  17. uni.showModal({
  18. title: '提示',
  19. content: '请更新应用',
  20. showCancel: false,
  21. success(e) {
  22. if (hj === 'ios') {
  23. plus.runtime.openURL(
  24. iosAppStroeUrl
  25. );
  26. }
  27. if (hj === 'android') {
  28. // plus.runtime.openURL('http://lxscimg.liuniu946.com/lxscV' + version + '.apk');
  29. downApp(r.file_url.app_file);
  30. }
  31. }
  32. });
  33. }
  34. });
  35. }).catch((e) => {
  36. console.log(e);
  37. })
  38. }
  39. // 下载app
  40. export function downApp(version) {
  41. plus.nativeUI.showWaiting('下载升级包...');
  42. plus.downloader
  43. .createDownload(version, {}, (d, status) => {
  44. if (status == 200) {
  45. installApp(d.filename); // 安装app
  46. } else {
  47. plus.nativeUI.alert('下载升级包失败!');
  48. }
  49. plus.nativeUI.closeWaiting();
  50. })
  51. .start();
  52. }
  53. // 安装app
  54. export function installApp(path) {
  55. plus.nativeUI.showWaiting('安装升级包...');
  56. plus.runtime.install(
  57. path, {},
  58. function() {
  59. plus.nativeUI.closeWaiting();
  60. uni.showToast({
  61. icon: 'none',
  62. title: '升级完成,准备重新载入'
  63. });
  64. setTimeout(_ => {
  65. uni.hideToast();
  66. plus.runtime.restart();
  67. }, 1000);
  68. },
  69. function(e) {
  70. plus.nativeUI.closeWaiting();
  71. plus.nativeUI.alert('安装升级包失败[' + e.code + ']:' + e.message);
  72. }
  73. );
  74. }