| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051 |
- <template>
- <el-button type="primary" size="small" @click="exportData" plain>导 出</el-button>
- </template>
- <script>
- export default {
- props:['param','type','columns','columnsIndex','fileName','dataid'],
- data(){
- return{
- columnsData:[]
- }
- },
- methods:{
- async exportData(){
- let rs = []
- this.columnsData = JSON.parse(JSON.stringify(this.columns))
- if (this.columnsData) {
- this.columns.filter(p=>{
- rs.push({
- fieldlabel:p.title,
- fieldname:p.columnname
- })
- })
- }
- this.param.content.dataid = this.dataid
- /*this.param.content.exportFields = rs*/
- this.param.content.isExport = 1
- /*导出数据*/
- const res = await this.$api.requested(this.param)
- this.downFile(res.data,this.fileName)
- this.param.content.isExport = 0
- },
- downFile(url, fileName) {
- console.log(url,'url')
- const x = new XMLHttpRequest()
- x.open('GET', url, true)
- x.responseType = 'blob'
- x.onload = function() {
- const url = window.URL.createObjectURL(x.response)
- const a = document.createElement('a')
- a.href = url
- a.download = fileName
- a.click()
- }
- x.send()
- }
- }
- }
- </script>
- <style>
- </style>
|