index.vue 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  1. <template>
  2. <view class="">
  3. <!-- 升级弹框 -->
  4. <u-popup :show="show" mode="center" width="500rpx" style="background-color: transparent;">
  5. <view class="" style="text-align: center;width: 500rpx;">
  6. <view class="" style='position: relative;'>
  7. <image style="width: 500rpx;height:700rpx;"
  8. src="http://icc-oss.oss-cn-hangzhou.aliyuncs.com/app/czzn-app/update1.png"
  9. mode="">
  10. </image>
  11. <view class="flex-col"
  12. style="position: absolute;bottom: 60rpx;width: 100%;justify-content: flex-end;align-items: center;height: 250rpx;">
  13. <view class="white lg"
  14. style="width: 80%;height: 80rpx;line-height: 80rpx;text-align: center;background:linear-gradient(to bottom,#FF7B7B,#FF4E4E);border-radius: 50rpx; color:#fff"
  15. @click="downloadPackage"> 立即升级
  16. </view>
  17. </view>
  18. </view>
  19. <!-- <image style="width: 80rpx;height:80rpx;margin-top: 40rpx;"
  20. src="https://wuzhongjie.oss-cn-beijing.aliyuncs.com/uniapp_web/wuzhongjie/videoPart/update2.png"
  21. mode="" @click="cancle"></image> -->
  22. </view>
  23. </u-popup>
  24. <!-- 下载弹框 -->
  25. <u-popup :show="show_update" mode="center" width="500rpx">
  26. <view
  27. style="background-color: #fff;height: 200rpx;border-radius: 30rpx;padding:20rpx 20rpx;text-align: center;">
  28. <view class="" style="margin: 30rpx;">
  29. 下载中...
  30. </view>
  31. <u-line-progress :percentage="progress" :showText="false"/>
  32. </view>
  33. </u-popup>
  34. </view>
  35. </template>
  36. <script>
  37. export default {
  38. data() {
  39. return {
  40. show: false,
  41. show_update: false,
  42. show: false,
  43. content: '11',
  44. show1: false,
  45. content1: '11',
  46. version: '',
  47. hot_version: '',
  48. progress: 0,
  49. new_ver: '',
  50. new_down_url: '',
  51. ios_down_url:"",
  52. update_content:'',
  53. }
  54. },
  55. mounted() {
  56. console.log('wgt包啵啵啵啵啵啵啵啵啵')
  57. // this.show = true
  58. this.isUpdate()
  59. },
  60. methods: {
  61. cancle() {
  62. this.show = false
  63. },
  64. getLocalVersion() { //获取当前版本号
  65. return new Promise((resolve, reject) => {
  66. plus.runtime.getProperty(plus.runtime.appid, function(widgetInfo) {
  67. console.log(widgetInfo, 'wgt包啵啵啵啵啵啵啵啵啵')
  68. this.version = widgetInfo.version
  69. this.hot_version = widgetInfo.versionCode
  70. resolve(this.version)
  71. })
  72. })
  73. },
  74. async isUpdate() { //后端获取最新版本号,版本号对比
  75. var ver = await this.getLocalVersion();
  76. console.log('当前版本号',ver);
  77. uni.request({
  78. url: 'http://zhijian.chinayimatong.com/admin/sys/app/download/getDownloadList/1808782670845468674',
  79. method: 'get',
  80. }).then(res => { //判断手机类型
  81. console.log('接口版本号', res[1].data)
  82. let data = res[1].data.data
  83. if (ver !== data.version) { //大版本更新
  84. if (uni.getSystemInfoSync().platform == 'android') {
  85. this.show = true
  86. this.new_down_url = data.androidDownload
  87. } else {
  88. this.show = true
  89. this.ios_down_url = data.iosDownload
  90. }
  91. }else{
  92. this.$emit('noNeedUpdate','')
  93. }
  94. }).catch(()=>{
  95. this.$emit('noNeedUpdate','')
  96. })
  97. },
  98. downloadPackage() { //确认升级版本-新建下载任务
  99. this.show = false
  100. if(this.new_down_url==''){ //苹果大版本更新去应用商店
  101. uni.navigateTo({
  102. url:this.ios_down_url
  103. })
  104. }else{
  105. var dtask = plus.downloader.createDownload(this.new_down_url, {}, function(d, status) {
  106. if (status == 200) { // 下载完成-进行安装
  107. console.log('下载status', d, status)
  108. // console.log("Download success: " + d.filename);
  109. this.show_update = false
  110. plus.runtime.install(d.filename, {
  111. force: true
  112. }, function() {
  113. plus.runtime.restart();
  114. }, function(e) {
  115. console.log(e)
  116. plus.nativeUI.toast("安装失败");
  117. });
  118. } else {
  119. console.log("Download failed: " + status);
  120. }
  121. });
  122. this.onProgress(dtask)
  123. dtask.start();}
  124. },
  125. onProgress(task) { // 获取下载进度
  126. console.log('下载中onProgress');
  127. this.show_update = true
  128. task.addEventListener('statechanged', e => {
  129. console.log('下载中', e)
  130. if (e && e.downloadedSize > 0) {
  131. let progress = ((e.downloadedSize / e.totalSize) * 100).toFixed(0)
  132. console.log('下载中111', progress)
  133. this.progress = progress
  134. }
  135. }, false)
  136. }
  137. },
  138. }
  139. </script>
  140. <style lang="less" scoped>
  141. .flex-col{
  142. display: flex;
  143. flex-direction: column;
  144. }
  145. </style>