downLoad.vue 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  1. <template>
  2. <view class="content">
  3. <view class="main">
  4. <view class="main-bg"><image src="../../static/images/download.png" mode=""></image></view>
  5. <view class="title">软件更新</view>
  6. <!-- <view class="jdt">
  7. <u-line-progress :show-percent="false" :percent="percent" :striped-active="true" :striped="true" inactive-color="#f5957d" active-color="#fd6f3f"></u-line-progress>
  8. </view> -->
  9. <view class="num">{{ percent }}%</view>
  10. <view class="tipSpan">软件更新中,请勿断开相框电源</view>
  11. <!-- <view class="btn" @click="cancelDown()">取消更新</view> -->
  12. </view>
  13. </view>
  14. </template>
  15. <script>
  16. export default {
  17. data() {
  18. return {
  19. dtask: '',
  20. percent: 0
  21. };
  22. },
  23. onLoad(opt) {
  24. this.downApp(opt.apk);
  25. },
  26. onShow() {},
  27. onReachBottom() {},
  28. onReady() {},
  29. onBackPress() {
  30. return true
  31. },
  32. methods: {
  33. downApp(version) {
  34. if(version.indexOf('http') == -1) {
  35. this.dtask = plus.downloader.createDownload('https://ygs.hqgjsmc.com' + version);
  36. }else {
  37. this.dtask = plus.downloader.createDownload(version);
  38. }
  39. this.dtask.addEventListener('statechanged', this.onStateChanged, false);
  40. this.dtask.start();
  41. },
  42. cancelDown() {
  43. this.dtask.abort();
  44. uni.navigateTo({
  45. url: '/pages/index/index'
  46. });
  47. },
  48. onStateChanged(download, status) {
  49. let prg = 0;
  50. console.log(this.percent);
  51. switch (download.state) {
  52. case 1:
  53. // showLoading.setTitle("正在下载");
  54. break;
  55. case 2:
  56. // showLoading.setTitle("已连接到服务器");
  57. break;
  58. case 3:
  59. prg = parseInt(
  60. //下载的进度
  61. (parseFloat(download.downloadedSize) / parseFloat(download.totalSize)) * 100
  62. );
  63. // showLoading.setTitle("版本更新,正在下载" + prg + "% ");
  64. this.percent = prg;
  65. break;
  66. case 4:
  67. this.installApp(download.filename);
  68. // plus.nativeUI.closeWaiting(); //关闭系统提示框
  69. this.showProcess = false;
  70. //下载完成
  71. break;
  72. }
  73. },
  74. installApp(path) {
  75. plus.nativeUI.showWaiting('安装升级包...');
  76. plus.runtime.install(
  77. path,
  78. {},
  79. function() {
  80. plus.nativeUI.closeWaiting();
  81. uni.showToast({
  82. icon: 'none',
  83. title: '升级完成,准备重新载入'
  84. });
  85. setTimeout(_ => {
  86. uni.hideToast();
  87. plus.runtime.restart();
  88. }, 1000);
  89. },
  90. function(e) {
  91. plus.nativeUI.closeWaiting();
  92. plus.nativeUI.alert('安装升级包失败[' + e.code + ']:' + e.message);
  93. }
  94. );
  95. }
  96. }
  97. };
  98. </script>
  99. <style lang="scss">
  100. page,
  101. .content {
  102. min-height: 100%;
  103. height: auto;
  104. }
  105. .main {
  106. margin-top: 100rpx;
  107. .main-bg {
  108. margin: 0 auto;
  109. width: 550rpx;
  110. height: 340rpx;
  111. image {
  112. width: 100%;
  113. height: 100%;
  114. }
  115. }
  116. .title {
  117. text-align: center;
  118. color: #000000;
  119. font-size: 40rpx;
  120. margin-top: 20rpx;
  121. font-family: PingFang SC;
  122. font-weight: bolder;
  123. }
  124. .jdt {
  125. width: 550rpx;
  126. margin: 20rpx auto;
  127. }
  128. .num {
  129. text-align: center;
  130. color: #ff7575;
  131. font-size: 30rpx;
  132. font-family: PingFang SC;
  133. font-weight: 500;
  134. }
  135. .tipSpan {
  136. margin-top: 20rpx;
  137. text-align: center;
  138. color: #ababab;
  139. font-size: 30rpx;
  140. font-family: PingFang SC;
  141. font-weight: 500;
  142. }
  143. .btn {
  144. display: flex;
  145. justify-content: center;
  146. align-items: center;
  147. color: #ffffff;
  148. width: 400rpx;
  149. height: 80rpx;
  150. background: #ff4c4c;
  151. margin: 20rpx auto;
  152. border-radius: 20rpx;
  153. }
  154. }
  155. </style>