fix: 处理 快照因为网络波动导致的下载文件不全的问题
This commit is contained in:
@@ -18,10 +18,19 @@ export default {
|
|||||||
panelId: this.showPanel.id,
|
panelId: this.showPanel.id,
|
||||||
start: this.$stringTimeParseToUnix(bus.formateTimeToTime(this.searchTime[0])),
|
start: this.$stringTimeParseToUnix(bus.formateTimeToTime(this.searchTime[0])),
|
||||||
end: this.$stringTimeParseToUnix(bus.formateTimeToTime(this.searchTime[1])),
|
end: this.$stringTimeParseToUnix(bus.formateTimeToTime(this.searchTime[1])),
|
||||||
|
t: new Date().getTime(),
|
||||||
vars: vars
|
vars: vars
|
||||||
}
|
}
|
||||||
this.$store.dispatch('dispatchHomeLoading', true)
|
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)
|
this.$store.dispatch('dispatchHomeLoading', false)
|
||||||
const self = this
|
const self = this
|
||||||
let fileName = name
|
let fileName = name
|
||||||
@@ -29,6 +38,10 @@ export default {
|
|||||||
if (resFileName) {
|
if (resFileName) {
|
||||||
fileName = resFileName
|
fileName = resFileName
|
||||||
}
|
}
|
||||||
|
if (loaded < total) {
|
||||||
|
this.$message.error(res.msg || res.error || res || this.$t('NetWork Error'))
|
||||||
|
return
|
||||||
|
}
|
||||||
if (res.type == 'application/json') {
|
if (res.type == 'application/json') {
|
||||||
const reader = new FileReader() // 创建一个FileReader实例
|
const reader = new FileReader() // 创建一个FileReader实例
|
||||||
reader.readAsText(res, 'utf-8') // 读取文件,结果用字符串形式表示
|
reader.readAsText(res, 'utf-8') // 读取文件,结果用字符串形式表示
|
||||||
@@ -54,8 +67,6 @@ export default {
|
|||||||
window.URL.revokeObjectURL(href) // 释放blob对象
|
window.URL.revokeObjectURL(href) // 释放blob对象
|
||||||
}
|
}
|
||||||
this.$refs.topTool.closeDialog()
|
this.$refs.topTool.closeDialog()
|
||||||
}, () => {
|
|
||||||
this.$message.error('123')
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4256,7 +4256,15 @@ export default {
|
|||||||
params.direction = this.$refs.logDetail ? this.$refs.logDetail.getDescending() : 'backward'
|
params.direction = this.$refs.logDetail ? this.$refs.logDetail.getDescending() : 'backward'
|
||||||
}
|
}
|
||||||
this.$store.dispatch('dispatchHomeLoading', true)
|
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)
|
this.$store.dispatch('dispatchHomeLoading', false)
|
||||||
const self = this
|
const self = this
|
||||||
let fileName = this.showMetrics ? 'Metrics explore' : 'Logs explore'
|
let fileName = this.showMetrics ? 'Metrics explore' : 'Logs explore'
|
||||||
@@ -4264,6 +4272,10 @@ export default {
|
|||||||
if (resFileName) {
|
if (resFileName) {
|
||||||
fileName = resFileName
|
fileName = resFileName
|
||||||
}
|
}
|
||||||
|
if (loaded < total) {
|
||||||
|
this.$message.error(res.msg || res.error || res || this.$t('NetWork Error'))
|
||||||
|
return
|
||||||
|
}
|
||||||
if (res.type == 'application/json') {
|
if (res.type == 'application/json') {
|
||||||
const reader = new FileReader() // 创建一个FileReader实例
|
const reader = new FileReader() // 创建一个FileReader实例
|
||||||
reader.readAsText(res, 'utf-8') // 读取文件,结果用字符串形式表示
|
reader.readAsText(res, 'utf-8') // 读取文件,结果用字符串形式表示
|
||||||
|
|||||||
@@ -103,12 +103,18 @@ axios.interceptors.response.use(
|
|||||||
return Promise.reject(error)
|
return Promise.reject(error)
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
export function get (url, params, responseType) {
|
export function get (url, params, configs) {
|
||||||
const config = {
|
let config = {}
|
||||||
params: params
|
if (configs) {
|
||||||
}
|
config = {
|
||||||
if (responseType) {
|
...configs,
|
||||||
config.responseType = responseType
|
...config,
|
||||||
|
params: params
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
config = {
|
||||||
|
params: params
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return new Promise((resolve) => {
|
return new Promise((resolve) => {
|
||||||
axios.get(url, config).then(response => {
|
axios.get(url, config).then(response => {
|
||||||
|
|||||||
Reference in New Issue
Block a user