upApp.vue 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  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="btn444" @click="upApp">
  12. {{is_up?(schedule + '%'): '马上更新'}}
  13. </view>
  14. </view>
  15. </view>
  16. </template>
  17. <script>
  18. import api from "../../library/index.js"
  19. export default {
  20. data() {
  21. return {
  22. schedule: 0,
  23. is_up: false,
  24. }
  25. },
  26. onLoad() {
  27. },
  28. onShow() {
  29. },
  30. onBackPress() {
  31. return true
  32. },
  33. methods: {
  34. upApp() {
  35. let _this = this
  36. plus.runtime.getProperty(plus.runtime.appid, function(info) {
  37. console.log(info, 'info');
  38. api.update({
  39. version: info.version,
  40. osname: plus.os.name
  41. }).then(res => {
  42. console.log(res);
  43. if (res.data.status == 1) {
  44. // plus.runtime.openURL(res.data.downurl);
  45. console.log(res.data.downurl,'res.data.downurl');
  46. _this.is_up = true
  47. let downloadTask = uni.downloadFile({
  48. url: res.data.downurl,
  49. success: (res1) => {
  50. // wgtWaiting.close();
  51. if (res1.statusCode === 200) {
  52. plus.runtime.install(res1.tempFilePath, {}, () => {
  53. plus.runtime.restart();
  54. }, (e) => {
  55. uni.showModal({
  56. content: "update error [" +
  57. e
  58. .code + "]:" + e
  59. .message,
  60. showCancel: false,
  61. });
  62. });
  63. } else {
  64. uni.showModal({
  65. content: "api error update fail!",
  66. showCancel: false,
  67. });
  68. }
  69. }
  70. });
  71. downloadTask.onProgressUpdate((res) => {
  72. console.log(res.progress);
  73. _this.schedule = res.progress
  74. });
  75. }
  76. })
  77. })
  78. }
  79. }
  80. }
  81. </script>
  82. <style lang="scss" scoped>
  83. .content {
  84. position: absolute;
  85. height: 100%;
  86. width: 100%;
  87. background-color: #7f7f7f;
  88. display: flex;
  89. justify-content: center;
  90. align-items: center;
  91. }
  92. .up-wrap {
  93. width: 522rpx;
  94. height: 499rpx;
  95. background: #FFFFFF;
  96. border-radius: 28rpx;
  97. position: relative;
  98. .upapp-bg {
  99. width: 345rpx;
  100. height: 307rpx;
  101. position: absolute;
  102. left: 0;
  103. right: 0;
  104. top: -150rpx;
  105. margin: auto;
  106. }
  107. .tit {
  108. margin-top: 190rpx;
  109. font-size: 39rpx;
  110. font-weight: 500;
  111. color: #FF443F;
  112. text-align: center;
  113. }
  114. .val {
  115. font-size: 31rpx;
  116. font-weight: 500;
  117. color: #A5A5A5;
  118. text-align: center;
  119. margin-top: 10rpx;
  120. }
  121. .btn444 {
  122. width: 357rpx;
  123. height: 83rpx !important;
  124. background: #FF443F;
  125. border-radius: 41rpx;
  126. text-align: center;
  127. line-height: 83rpx;
  128. font-size: 34rpx;
  129. font-weight: 500;
  130. color: #FFFFFF;
  131. margin: 10rpx auto 0;
  132. }
  133. }
  134. </style>