config.js 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. module.exports = {
  2. updateManager,
  3. }
  4. function updateManager() {
  5. // #ifdef APP-PLUS
  6. const updated = uni.getStorageSync('updated'); // 尝试读取storage
  7. // 如果上次刚更新过----删除 updated成功标志
  8. // console.log(updated)
  9. if (updated.completed === true) {
  10. // 删除安装包及安装记录
  11. console.log('安装记录被删除,更新成功');
  12. uni.removeSavedFile({
  13. filePath: updated.packgePath,
  14. success: res => {
  15. uni.removeStorageSync('updated');
  16. }
  17. });
  18. } else if (updated.completed === false) {
  19. uni.removeStorageSync('updated');
  20. plus.runtime.install(updated.packgePath, {
  21. force: true
  22. });
  23. uni.setStorage({
  24. key: 'updated',
  25. data: {
  26. completed: true,
  27. packgePath: updated.packgePath
  28. },
  29. success: res => {
  30. console.log('成功安装上次的更新,应用需要重启才能继续完成');
  31. }
  32. });
  33. uni.showModal({
  34. title: '提示',
  35. content: '应用将重启以完成更新',
  36. showCancel: false,
  37. complete: () => {
  38. plus.runtime.restart();
  39. }
  40. });
  41. }
  42. // #endif
  43. //checkUpdater();
  44. };
  45. import CONFIG from "./../config/global.config"
  46. export function checkUpdater(currentId, updaterPage) {
  47. let version=null
  48. plus.runtime.getProperty(plus.runtime.appid, (wgtinfo)=>{
  49. version=wgtinfo.versionCode;
  50. console.log("当前版本"+version)
  51. uni.request({
  52. url: CONFIG.baseUrl+ "/app/config/info",
  53. method: 'get',
  54. success:(res)=>{
  55. if (res.data.code != 200 ) {
  56. uni.showModal({
  57. title: '提示',
  58. content: res.data.msg
  59. })
  60. return;
  61. }
  62. let upgradeInfo = res.data.data;
  63. console.log("res"+JSON.stringify(upgradeInfo))
  64. if (Number(version) <Number( upgradeInfo.number)) {
  65. uni.showModal({
  66. title: '发现新版本',
  67. content: '有新版本可用 (版本号:' + upgradeInfo.ver + '),请问您是否更新?',
  68. showCancel:false,
  69. success: (res) => {
  70. if (res.confirm) {
  71. console.log(plus.os.name.toLowerCase())
  72. if (plus.os.name.toLowerCase() === 'ios') {
  73. let appleId=1538532925; //app的appleId id1538532925
  74. plus.runtime.launchApplication({
  75. action: `itms-apps://itunes.apple.com/cn/app/id${appleId}?mt=8`
  76. }, function(e) {
  77. console.log('Open system default browser failed: ' + e.message);
  78. });
  79. } else {
  80. if(upgradeInfo.status){
  81. uni.redirectTo({
  82. url: '/pages/index/update',
  83. success(res) {
  84. console.log(res);
  85. },
  86. fail(err) {
  87. console.log(err);
  88. }
  89. })
  90. }else{
  91. uni.navigateTo({
  92. url: '/pages/index/update',
  93. success(res) {
  94. console.log(res);
  95. },
  96. fail(err) {
  97. console.log(err);
  98. }
  99. })
  100. }
  101. }
  102. // downLoad();
  103. } else if (res.cancel) {
  104. console.log('取消')
  105. }
  106. },
  107. })
  108. }
  109. }
  110. });
  111. })
  112. }