app版本更新---全量更新,热更新等等

风意不止 / 2024-10-15 / 原文

全量更新代码

isFirst:true
  onLoad() {
    this.versionCheck(true)
    compareVersion(version1, version2) {
      const arr1 = version1.split('.').map((e) => e * 1)
      const arr2 = version2.split('.').map((e) => e * 1)
      const length = Math.max(arr1.length, arr2.length)
      for (let i = 0; i < length; i++) {
        if ((arr1[i] || 0) > (arr2[i] || 0)) return 1 // version1 大
        if ((arr1[i] || 0) < (arr2[i] || 0)) return -1 // version2 大
      }
      return 0 // 一样大
    },
  versionCheck(isFirst) {
      uni.getSystemInfo({
        success: (result) => {
			// console.log('res',result,isFirst)
			// return
          const { appVersion, osName } = result
          this.appVersion = appVersion
          if (isFirst) return
          const isIOS = osName === 'ios';
          (isIOS ? httpappVerIos : httpappVerAndroid)().then((res) => {
            let cloudVersion = res.appVersion
            // cloudVersion = '14.1.1'
            const isOld = this.compareVersion(this.appVersion, cloudVersion)
            if (isOld === -1) {
              // this.$modal.msg('存在新版本')
              this.$modal.confirm('发现最新版本,是否更新?').then((_) => {
                if (isIOS) {
                  plus.runtime.launchApplication(
                    {
                      //在App Store Connect中的App Store下的app信息,可找到appleId
                      // let appleId = 111111111
                      // action: `itms-apps://itunes.apple.com/cn/app/id${appleId}?mt=8`
                      action: res.appUrl
                    },
                    function (e) {
                      console.log('Open system default browser failed: ' + e.message)
                    }
                  )
                } else {
                  this.androidDownload(res.packPath).start()
                }
              })
            } else {
              this.$modal.msg('当前是最新版本')
            }
          })
        }
      })
    },


全量更新,热更新,插件版本

https://ext.dcloud.net.cn/plugin?id=1643