import axios from 'axios'
import modal from 'ant-design-vue/es/modal'
const isNewVersion = () => {
  const url = `//${window.location.host}/version.json?t=${new Date().getTime()}`
  axios.get(url).then(res => {
    if (res.status === 200) {
      const vueVersion = res.data.version
      const message = res.data.message
      const localVueVersion = localStorage.getItem('vueVersion-ocs')
      if (localVueVersion && localVueVersion != vueVersion) {
        modal.info({
          title: '提示',
          content: message,
          onOk () {
            localStorage.clear()
            sessionStorage.clear()
            localStorage.setItem('vueVersion-ocs', vueVersion)
            window.location.reload(true)
          }
        })
      } else {
        localStorage.setItem('vueVersion-ocs', vueVersion)
      }
    }
  })
}

export default {
  isNewVersion
}
