upApp.vue 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. <template>
  2. <view class="content">
  3. <view class="up-wrap">
  4. <image src="../../static/img/upapp.png" mode="" class="upapp-bg"></image>
  5. <view class="tit">
  6. 新版本升级
  7. </view>
  8. <view class="val">
  9. 客户端体验优化
  10. </view>
  11. <view class="btn" @click="upApp">
  12. {{is_up?(schedule + '%'): '马上更新'}}
  13. </view>
  14. </view>
  15. </view>
  16. </template>
  17. <script>
  18. export default {
  19. data() {
  20. return {
  21. schedule: 0,
  22. is_up: false,
  23. }
  24. },
  25. onLoad() {
  26. },
  27. onShow() {
  28. },
  29. onBackPress() {
  30. return true
  31. },
  32. methods: {
  33. upApp() {
  34. let _this = this
  35. plus.runtime.getProperty(plus.runtime.appid, function(info) {
  36. console.log(info,'info');
  37. _this.$httpSend({
  38. path: '/im/app/update',
  39. data: {
  40. appid: info.appid,
  41. version: info.version,
  42. },
  43. success(res) {
  44. if (res.status) {
  45. // _action.checkFail();
  46. _this.is_up = true
  47. // let wgtWaiting = plus.nativeUI.showWaiting("更新开始下载"),
  48. let update_url = (plus.os.name == 'Android' ? res.update_url.android : res
  49. .update_url.ios),
  50. downloadTask = uni.downloadFile({
  51. url: update_url,
  52. success: (res) => {
  53. // wgtWaiting.close();
  54. if (res.statusCode === 200) {
  55. plus.runtime.install(res.tempFilePath, {}, () => {
  56. plus.runtime.restart();
  57. }, (e) => {
  58. uni.showModal({
  59. content: "update error [" + e
  60. .code + "]:" + e.message,
  61. showCancel: false,
  62. });
  63. });
  64. } else {
  65. uni.showModal({
  66. content: "api error update fail!",
  67. showCancel: false,
  68. });
  69. }
  70. }
  71. });
  72. downloadTask.onProgressUpdate((res) => {
  73. console.log(res,'res+++++++++');
  74. _this.schedule = res.progress
  75. // wgtWaiting.setTitle('下载中...' + res.progress + '%');
  76. });
  77. }
  78. },
  79. });
  80. })
  81. }
  82. }
  83. }
  84. </script>
  85. <style lang="scss">
  86. .content {
  87. position: absolute;
  88. height: 100%;
  89. width: 100%;
  90. background-color: #7f7f7f;
  91. display: flex;
  92. justify-content: center;
  93. align-items: center;
  94. }
  95. .up-wrap {
  96. width: 522rpx;
  97. height: 499rpx;
  98. background: #FFFFFF;
  99. border-radius: 28rpx;
  100. position: relative;
  101. .upapp-bg {
  102. width: 345rpx;
  103. height: 307rpx;
  104. position: absolute;
  105. left: 0;
  106. right: 0;
  107. top: -150rpx;
  108. margin: auto;
  109. }
  110. .tit {
  111. margin-top: 190rpx;
  112. font-size: 39rpx;
  113. font-weight: 500;
  114. color: #FF443F;
  115. text-align: center;
  116. }
  117. .val {
  118. font-size: 31rpx;
  119. font-weight: 500;
  120. color: #A5A5A5;
  121. text-align: center;
  122. margin-top: 10rpx;
  123. }
  124. .btn {
  125. width: 357rpx;
  126. height: 83rpx;
  127. background: #FF443F;
  128. border-radius: 41rpx;
  129. text-align: center;
  130. line-height: 83rpx;
  131. font-size: 34rpx;
  132. font-weight: 500;
  133. color: #FFFFFF;
  134. margin: 10rpx auto 0;
  135. }
  136. }
  137. </style>