index.js 777 Bytes
import Request from '../../request/index'
import webwx, { setProduct } from './helper'
class Version {
  constructor(options = {}) {
    options.alert = options.alert || function () {}
    options.request.returnAll = false
    this.options = options
    this.request = new Request(options)
  }
  async get(data = {}) {
    setProduct.call(this, data)
    const versionInfo = await this.request.get(data)
    if (!versionInfo || !versionInfo.version) {
      throw new Error('未获取到版本信息,请检查配置')
    }
    this.version = versionInfo
    return this.compare()
  }
  set(version = this.version.version) {
    webwx.setVersion.call(this, version)
    return this.compare()
  }
  compare() {
    return webwx.getResult.call(this)
  }
}
export default Version