updatePop.vue 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  1. <template>
  2. <view>
  3. <u-popup :show="show" @close="close" mode="center">
  4. <view class="updatetips-whole">
  5. <view class="updatetips">
  6. <view>
  7. <view class="updatetips-head">
  8. <!-- <image src="../static/images/updatetips.png"></image> -->
  9. <view class="updatetips-version" style="text-align: center;">
  10. 更新提示
  11. </view>
  12. </view>
  13. <view class="updatetips-content">
  14. 应用现在有新的版本可供更新</br>
  15. (文件大小{{changeByte(sizes)}} )
  16. </view>
  17. <!-- 进度条 -->
  18. <u-line-progress
  19. v-if="isProgress"
  20. :percentage="progress"
  21. activeColor="#55D88A"
  22. :showText="false"
  23. height="4"
  24. ></u-line-progress>
  25. </view>
  26. <view class="updatetips-btn-disable" v-if="isProgress">升级</view>
  27. <view class="updatetips-btn" v-else @click="downloadBtn()">升级</view>
  28. </view>
  29. </view>
  30. </u-popup>
  31. </view>
  32. </template>
  33. <script>
  34. export default {
  35. props:['versionNum','versionContent','downloadUrl','sizes'],
  36. data() {
  37. return {
  38. show:false,
  39. progress:0,
  40. isProgress:false,
  41. progress:''
  42. };
  43. },
  44. methods: {
  45. open() {
  46. this.show = true
  47. },
  48. close(){
  49. this.show = false
  50. },
  51. downloadBtn(){
  52. this.isProgress=true
  53. const downloadTask = uni.downloadFile({
  54. url:this.downloadUrl,
  55. success: (res) => {
  56. //安装
  57. plus.runtime.install(
  58. res.tempFilePath, {
  59. force: true
  60. },
  61. function(_res) {
  62. plus.runtime.restart();
  63. }
  64. )
  65. },
  66. fail: (err)=> {
  67. uni.$u.toast('下载失败')
  68. }
  69. })
  70. // 查看下载进度
  71. downloadTask.onProgressUpdate((res) => {
  72. this.progress=res.progress
  73. })
  74. },
  75. // 单位转换
  76. changeByte (byte) {
  77. let size = "";
  78. if (byte < 0.1 * 1024) {
  79. // 小于0.1KB,则转化成B
  80. size = `${byte.toFixed(2)}B`;
  81. } else if (byte < 0.1 * 1024 * 1024) {
  82. // 小于0.1MB,则转化成KB
  83. size = `${(byte / 1024).toFixed(2)}KB`;
  84. } else if (byte < 0.1 * 1024 * 1024 * 1024) {
  85. // 小于0.1GB,则转化成MB
  86. size = `${(byte / (1024 * 1024)).toFixed(2)}MB`;
  87. } else {
  88. // 其他转化成GB
  89. size = `${(byte / (1024 * 1024 * 1024)).toFixed(2)}GB`;
  90. }
  91. const sizeStr = `${size}`; // 转成字符串
  92. const index = sizeStr.indexOf("."); // 获取小数点处的索引
  93. const dou = sizeStr.substr(index + 1, 2); // 获取小数点后两位的值
  94. // eslint-disable-next-line eqeqeq
  95. if (dou == "00") {
  96. // 判断后两位是否为00,如果是则删除00
  97. return sizeStr.substring(0, index) + sizeStr.substr(index + 3, 2);
  98. }
  99. return size;
  100. }
  101. }
  102. };
  103. </script>
  104. <style scoped>
  105. .updatetips-whole{
  106. display: flex;
  107. justify-content: center;
  108. align-items: center;
  109. width: 650rpx;
  110. height: 100%;
  111. }
  112. .updatetips{
  113. position: relative;
  114. width: 80%;
  115. min-height: 100rpx;
  116. background-color: #fff;
  117. border-radius: 20rpx;
  118. }
  119. .updatetips-head{
  120. position: relative;
  121. width: 100%;
  122. padding: 20rpx 0;
  123. }
  124. .updatetips-head>image{
  125. position: absolute;
  126. top: -72rpx;
  127. width: 100%;
  128. height: 280rpx;
  129. }
  130. .updatetips-version{
  131. color: #555;
  132. font-size: 40rpx;
  133. }
  134. .updatetips-content{
  135. width: 80%;
  136. min-height: 100rpx;
  137. margin: 40rpx auto;
  138. text-align: center;
  139. }
  140. .updatetips-btn-disable{
  141. height: 120rpx;
  142. line-height: 120rpx;
  143. text-align: center;
  144. color: #02A7F0;
  145. }
  146. .updatetips-btn{
  147. height: 120rpx;
  148. line-height: 120rpx;
  149. text-align: center;
  150. color: #02A7F0;
  151. }
  152. .updatetips-btn::before{
  153. content: "";
  154. width: 85%;
  155. height: 1px;
  156. background-color: #E6E6E6;
  157. position: absolute;
  158. left: 50%;
  159. transform: translate(-50%,-50%);
  160. }
  161. </style>