NEZ-3174 feat:notebook导出pdf

This commit is contained in:
zyh
2023-09-21 11:26:28 +08:00
parent dc6bda79a2
commit c2a76789f0
3 changed files with 26 additions and 18 deletions

View File

@@ -538,13 +538,13 @@ export default {
if (window.navigator.msSaveOrOpenBlob) {
// 兼容ie11
const blobObject = new Blob([res.data])
window.navigator.msSaveOrOpenBlob(blobObject, this.obj.name)
window.navigator.msSaveOrOpenBlob(blobObject, this.obj.name + '.json')
} else {
const url = URL.createObjectURL(new Blob([res.data]))
const a = document.createElement('a')
document.body.appendChild(a) // 此处增加了将创建的添加到body当中
a.href = url
a.download = this.obj.name
a.download = this.obj.name + '.json'
a.target = '_blank'
a.click()
a.remove() // 将a标签移除

View File

@@ -35,6 +35,7 @@
</template>
<script>
import axios from 'axios'
import bus from '@/libs/bus'
function create (f) {
@@ -145,34 +146,26 @@ export default {
downloadSnapshot () {
let total = 10
let loaded = 0
this.$get(`/visual/${this.api}/snapshot/download/` + this.tid, {}, {
axios.get(`/visual/${this.api}/snapshot/download/` + this.tid, {
responseType: 'blob',
onDownloadProgress: function (progressEvent) {
// 处理原生进度事件
total = progressEvent.total
loaded = progressEvent.loaded
}
}).then(res => {
const self = this
const fileName = this.showPanel.name
if (res.type == 'application/json') {
const reader = new FileReader() // 创建一个FileReader实例
reader.readAsText(res, 'utf-8') // 读取文件,结果用字符串形式表示
reader.onload = function () { // 读取完成后,**获取reader.result**
const { msg } = JSON.parse(reader.result)
self.$message.error(msg) // 弹出错误提示
}
return
}
if (loaded < total) {
this.$message.error(res.msg || res.error || res || this.$t('NetWork Error'))
this.$message.error(res.msg || res.error || this.$t('NetWork Error'))
this.prevent_opt.import = false
return
}
if (window.navigator.msSaveOrOpenBlob) {
// 兼容ie11
const blobObject = new Blob([res])
const blobObject = new Blob([res.data])
window.navigator.msSaveOrOpenBlob(blobObject, fileName + '.' + (this.showPanel.format || 'html'))
} else {
const blob = new Blob([res])
const blob = new Blob([res.data])
const link = document.createElement('a')
const href = window.URL.createObjectURL(blob) // 下载链接
link.href = href
@@ -184,8 +177,20 @@ export default {
}
this.prevent_opt.import = false
this.$emit('update:snapshotVisible', false)
}, (res) => {
this.$message.error(res.msg || res.error)
}, 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)
this.prevent_opt.import = false
})
},
// 关闭定时器 取消任务

View File

@@ -201,6 +201,9 @@ export default {
if (!this.isExportHtml) {
this.onScroll()
} else {
setTimeout(() => {
window.dataJson.AllChartDataload = true
}, 1000)
this.onScroll(999999)
}
setTimeout(() => {