
import { ref } from 'vue'

export default function () {
  const exportLoading = ref(false),
    exportData = async (func) => {
      exportLoading.value = true
      const res = await func()
      const url = URL.createObjectURL(res)
      const link = document.createElement('a')
      link.style.display = 'none'
      link.href = url
      document.body.appendChild(link)
      link.click()
      document.body.removeChild(link)
      window.URL.revokeObjectURL(url)
      exportLoading.value = false
    }

  return {
    exportLoading,
    exportData
  }
}
