fix: 内置报告 全选bug修复
This commit is contained in:
@@ -8,7 +8,6 @@
|
||||
@header-dragend="dragend"
|
||||
@sort-change="tableDataSort"
|
||||
@selection-change="selectionChange"
|
||||
@select-all="selectionChangeAll"
|
||||
@select="select"
|
||||
>
|
||||
<el-table-column
|
||||
@@ -39,6 +38,9 @@
|
||||
{{scope.row.startTime}}-{{scope.row.endTime}}
|
||||
</template>
|
||||
</span>
|
||||
<span v-if="item.prop === 'type'">
|
||||
{{scope.row.reportTemp.name}}
|
||||
</span>
|
||||
<span v-else>{{scope.row[item.prop]}}</span>
|
||||
</template>
|
||||
|
||||
@@ -59,18 +61,16 @@
|
||||
</el-table-column>
|
||||
</el-table>
|
||||
<div class="table-operation-all">
|
||||
<el-checkbox v-model="checkboxAll" @change="builtinReportCheckbox"></el-checkbox>
|
||||
<el-checkbox v-model="checkboxAll" @change="builtinReportCheckbox(tableData)"></el-checkbox>
|
||||
<div class="table-operation-all-span">
|
||||
<span>{{ $t('overall.all') }}</span>
|
||||
<span :class="{'table-operation-all-checkbox': checkboxAll}" @click="batchDownload">{{$t('report.batchDow')}}</span>
|
||||
<span :class="{'table-operation-all-checkbox': batchDow}" :disabled="checkboxAll" @click="tableOperation(['download', this.checkboxIds, 'builtin'])">{{$t('report.batchDow')}}</span>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
import table from '@/mixins/table'
|
||||
import { get } from '@/utils/http'
|
||||
import axios from 'axios'
|
||||
export default {
|
||||
name: 'builtinReportTable',
|
||||
mixins: [table],
|
||||
@@ -102,74 +102,26 @@ export default {
|
||||
],
|
||||
checkboxAll: false,
|
||||
checkboxIds: '',
|
||||
builtinId: ''
|
||||
batchDow: false,
|
||||
builtinId: '',
|
||||
indeterminate: false
|
||||
}
|
||||
},
|
||||
methods: {
|
||||
select (objs) {
|
||||
selectionChange (objs) {
|
||||
this.$emit('selectionChange', objs)
|
||||
this.checkboxIds = objs.map(item => { return item.id }).join(',')
|
||||
if (objs.length > 0) {
|
||||
this.checkboxAll = true
|
||||
} else {
|
||||
this.checkboxAll = false
|
||||
}
|
||||
this.checkboxAll = objs.length > 0 || objs.length === this.tableData.length
|
||||
this.batchDow = objs.length > 0
|
||||
},
|
||||
builtinReportCheckbox (objs) {
|
||||
if (objs) {
|
||||
this.selectionChangeAll(this.tableData)
|
||||
objs.forEach(item => {
|
||||
this.$refs.dataTable.toggleAllSelection(item)
|
||||
})
|
||||
} else {
|
||||
this.$refs.dataTable.clearSelection()
|
||||
}
|
||||
},
|
||||
selectionChangeAll (objs) {
|
||||
console.log(objs)
|
||||
},
|
||||
batchDownload: function () {
|
||||
const fileName = 'builtinReport' + '-' + this.getTimeString() + '.zip'
|
||||
const params = {
|
||||
ids: this.checkboxIds
|
||||
}
|
||||
axios.get('/report/job/batchDownloadPdf', { responseType: 'blob', params: params }).then(res => {
|
||||
if (window.navigator.msSaveOrOpenBlob) {
|
||||
// 兼容ie11
|
||||
const blobObject = new Blob([res.data])
|
||||
window.navigator.msSaveOrOpenBlob(blobObject, fileName)
|
||||
} else {
|
||||
const url = URL.createObjectURL(new Blob([res.data]))
|
||||
const a = document.createElement('a')
|
||||
document.body.appendChild(a) // 此处增加了将创建的添加到body当中
|
||||
a.href = url
|
||||
a.download = fileName
|
||||
a.target = '_blank'
|
||||
a.click()
|
||||
a.remove() // 将a标签移除
|
||||
}
|
||||
}, error => {
|
||||
const $self = this
|
||||
const reader = new FileReader()
|
||||
reader.onload = function (event) {
|
||||
const responseText = reader.result
|
||||
const exception = JSON.parse(responseText)
|
||||
if (exception.message) {
|
||||
$self.$message.error(exception.message)
|
||||
} else {
|
||||
console.error(error)
|
||||
}
|
||||
}
|
||||
reader.readAsText(error.response.data)
|
||||
})
|
||||
},
|
||||
getTimeString () {
|
||||
const split = '-'
|
||||
const date = new Date()
|
||||
const year = date.getFullYear()
|
||||
const month = this.formatNum(date.getMonth() + 1)
|
||||
const day = this.formatNum(date.getDate())
|
||||
const hours = this.formatNum(date.getHours())
|
||||
const minutes = this.formatNum(date.getMinutes())
|
||||
const seconds = this.formatNum(date.getSeconds())
|
||||
return year + split + month + split + day + ' ' + hours + split + minutes + split + seconds
|
||||
},
|
||||
formatNum (num) {
|
||||
return num > 9 ? num : '0' + num
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -42,7 +42,7 @@ export default {
|
||||
asce: tableSort.asce,
|
||||
desc: tableSort.desc,
|
||||
strToDate: tableSort.strToDate,
|
||||
tableOperation ([command, row]) {
|
||||
tableOperation ([command, row, param]) {
|
||||
switch (command) {
|
||||
case 'edit': {
|
||||
this.edit(row)
|
||||
@@ -57,7 +57,7 @@ export default {
|
||||
break
|
||||
}
|
||||
case 'download': {
|
||||
this.download(row)
|
||||
this.download(row, param)
|
||||
break
|
||||
}
|
||||
case 'preview': {
|
||||
@@ -146,12 +146,24 @@ export default {
|
||||
this.object = { ...u, name: 'Copy from ' + u.name, id: '' }
|
||||
this.rightBox.show = true
|
||||
},
|
||||
download (u) {
|
||||
const fileName = 'builtinReport' + '-' + this.getTimeString() + '.pdf'
|
||||
const params = {
|
||||
id: u.id
|
||||
download (u, n) {
|
||||
let fileName = ''
|
||||
let url = ''
|
||||
let params = {}
|
||||
if (n === 'builtin') {
|
||||
fileName = 'builtinReport' + '-' + this.getTimeString() + '.zip' // 文件名称
|
||||
url = '/report/job/batchDownloadPdf' // 批量 zip 下载
|
||||
params = {
|
||||
ids: u
|
||||
}
|
||||
} else {
|
||||
fileName = 'builtinReport' + '-' + this.getTimeString() + '.pdf' // 文件名称
|
||||
url = '/report/job/downloadPdf' // 单个 pdf 下载
|
||||
params = {
|
||||
id: u.id
|
||||
}
|
||||
}
|
||||
axios.get('/report/job/downloadPdf', { responseType: 'blob', params: params }).then(res => {
|
||||
axios.get(url, { responseType: 'blob', params: params }).then(res => {
|
||||
if (window.navigator.msSaveOrOpenBlob) {
|
||||
// 兼容ie11
|
||||
const blobObject = new Blob([res.data])
|
||||
|
||||
@@ -41,7 +41,7 @@ export default {
|
||||
tableOperation ([command, row, param]) {
|
||||
switch (command) {
|
||||
default:
|
||||
this.$emit(command, row)
|
||||
this.$emit(command, row, param)
|
||||
break
|
||||
}
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user