index1.vue 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. <template>
  2. <el-button type="primary" size="small" @click="exportData" plain>导 出</el-button>
  3. </template>
  4. <script>
  5. export default {
  6. props:['param','type','columns','columnsIndex','fileName','dataid'],
  7. data(){
  8. return{
  9. columnsData:[]
  10. }
  11. },
  12. methods:{
  13. async exportData(){
  14. let rs = []
  15. this.columnsData = JSON.parse(JSON.stringify(this.columns))
  16. if (this.columnsData) {
  17. this.columns.filter(p=>{
  18. rs.push({
  19. fieldlabel:p.title,
  20. fieldname:p.columnname
  21. })
  22. })
  23. }
  24. this.param.content.dataid = this.dataid
  25. /*this.param.content.exportFields = rs*/
  26. this.param.content.isExport = 1
  27. /*导出数据*/
  28. const res = await this.$api.requested(this.param)
  29. this.downFile(res.data,this.fileName)
  30. this.param.content.isExport = 0
  31. },
  32. downFile(url, fileName) {
  33. console.log(url,'url')
  34. const x = new XMLHttpRequest()
  35. x.open('GET', url, true)
  36. x.responseType = 'blob'
  37. x.onload = function() {
  38. const url = window.URL.createObjectURL(x.response)
  39. const a = document.createElement('a')
  40. a.href = url
  41. a.download = fileName
  42. a.click()
  43. }
  44. x.send()
  45. }
  46. }
  47. }
  48. </script>
  49. <style>
  50. </style>