#
whycq
2023-02-07 e2b07afb71e112babef573c8dad089d0a2aef5da
App.vue
@@ -181,6 +181,61 @@
            });
            complete: () => {}
         },
         downWgt() {
            let that = this;
            const downloadUrl = that.baseUrll + "/static/appupload/" + that.upVersion + ".apk"
            uni.showLoading({
               title: '更新中……'
            })
            // return
            const downloadTask = uni.downloadFile({ //执行下载
               url: downloadUrl, //下载地址
               timeout: 1000 * 30, //30秒超时时间
               success: downloadResult => { //下载成功
                  console.log(downloadResult);
                  that.showdownLine = false
                  uni.hideLoading();
                  console.log('downloadResult.statusCode' + downloadResult.statusCode)
                  if (downloadResult.statusCode == 200) {
                     console.log('更新中')
                     uni.showModal({
                        title: '',
                        content: '更新成功,确定现在重启吗?',
                        confirmText: '重启',
                        confirmColor: '#EE8F57',
                        success: function(res) {
                           if (res.confirm == true) {
                              plus.runtime.install( //安装
                                 downloadResult.tempFilePath, {
                                    force: true
                                 },
                                 function(res) {
                                    utils.showToast('更新成功,重启中');
                                    plus.runtime.restart();
                                 }
                              );
                           }
                        }
                     });
                  }
               },
               fail: err => {
                  uni.hideLoading();
                  that.showdownLine = false
                  that.$u.toast(err.errMsg)
                  console.log(err)
               },
               complete: com => {
                  console.log(com)
               }
            });
            // 下载进度
            downloadTask.onProgressUpdate(res => {
               that.downloadNum = res.progress
               console.log('下载进度' + that.downloadNum);
            });
         },
      }
   }
</script>