From 2cee77db390c3911b8ae63de40ff894973397d25 Mon Sep 17 00:00:00 2001 From: zhangyu Date: Thu, 15 Jun 2023 18:29:33 +0800 Subject: [PATCH] =?UTF-8?q?fix=EF=BC=9A=20=E5=A4=84=E7=90=86=20=E5=BF=AB?= =?UTF-8?q?=E7=85=A7=E5=9B=A0=E4=B8=BA=E7=BD=91=E7=BB=9C=E6=B3=A2=E5=8A=A8?= =?UTF-8?q?=E5=AF=BC=E8=87=B4=E7=9A=84=E4=B8=8B=E8=BD=BD=E6=96=87=E4=BB=B6?= =?UTF-8?q?=E4=B8=8D=E5=85=A8=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/components/common/mixin/exportHtml.js | 17 ++++++++++++++--- .../page/dashboard/explore/exploreItem.vue | 14 +++++++++++++- nezha-fronted/src/http.js | 18 ++++++++++++------ 3 files changed, 39 insertions(+), 10 deletions(-) diff --git a/nezha-fronted/src/components/common/mixin/exportHtml.js b/nezha-fronted/src/components/common/mixin/exportHtml.js index 5d0726d56..80a5769e1 100644 --- a/nezha-fronted/src/components/common/mixin/exportHtml.js +++ b/nezha-fronted/src/components/common/mixin/exportHtml.js @@ -18,10 +18,19 @@ export default { panelId: this.showPanel.id, start: this.$stringTimeParseToUnix(bus.formateTimeToTime(this.searchTime[0])), end: this.$stringTimeParseToUnix(bus.formateTimeToTime(this.searchTime[1])), + t: new Date().getTime(), vars: vars } this.$store.dispatch('dispatchHomeLoading', true) - this.$get('/visual/panel/snapshot', params, 'blob').then(res => { + let total = 10 + let loaded = 0 + this.$get('/visual/panel/snapshot', params, { + onDownloadProgress: function (progressEvent) { + // 处理原生进度事件 + total = progressEvent.total + loaded = progressEvent.loaded + } + }).then(res => { this.$store.dispatch('dispatchHomeLoading', false) const self = this let fileName = name @@ -29,6 +38,10 @@ export default { if (resFileName) { fileName = resFileName } + if (loaded < total) { + this.$message.error(res.msg || res.error || res || this.$t('NetWork Error')) + return + } if (res.type == 'application/json') { const reader = new FileReader() // 创建一个FileReader实例 reader.readAsText(res, 'utf-8') // 读取文件,结果用字符串形式表示 @@ -54,8 +67,6 @@ export default { window.URL.revokeObjectURL(href) // 释放blob对象 } this.$refs.topTool.closeDialog() - }, () => { - this.$message.error('123') }) } } diff --git a/nezha-fronted/src/components/page/dashboard/explore/exploreItem.vue b/nezha-fronted/src/components/page/dashboard/explore/exploreItem.vue index 312c928cf..d14af898d 100644 --- a/nezha-fronted/src/components/page/dashboard/explore/exploreItem.vue +++ b/nezha-fronted/src/components/page/dashboard/explore/exploreItem.vue @@ -4256,7 +4256,15 @@ export default { params.direction = this.$refs.logDetail ? this.$refs.logDetail.getDescending() : 'backward' } this.$store.dispatch('dispatchHomeLoading', true) - this.$get('/visual/explore/snapshot', params, 'blob').then(res => { + let total = 10 + let loaded = 0 + this.$get('/visual/explore/snapshot', params, { + onDownloadProgress: function (progressEvent) { + // 处理原生进度事件 + total = progressEvent.total + loaded = progressEvent.loaded + } + }).then(res => { this.$store.dispatch('dispatchHomeLoading', false) const self = this let fileName = this.showMetrics ? 'Metrics explore' : 'Logs explore' @@ -4264,6 +4272,10 @@ export default { if (resFileName) { fileName = resFileName } + if (loaded < total) { + this.$message.error(res.msg || res.error || res || this.$t('NetWork Error')) + return + } if (res.type == 'application/json') { const reader = new FileReader() // 创建一个FileReader实例 reader.readAsText(res, 'utf-8') // 读取文件,结果用字符串形式表示 diff --git a/nezha-fronted/src/http.js b/nezha-fronted/src/http.js index 4d3dd83e9..ddcd6e0cd 100644 --- a/nezha-fronted/src/http.js +++ b/nezha-fronted/src/http.js @@ -103,12 +103,18 @@ axios.interceptors.response.use( return Promise.reject(error) } ) -export function get (url, params, responseType) { - const config = { - params: params - } - if (responseType) { - config.responseType = responseType +export function get (url, params, configs) { + let config = {} + if (configs) { + config = { + ...configs, + ...config, + params: params + } + } else { + config = { + params: params + } } return new Promise((resolve) => { axios.get(url, config).then(response => {