Merge branch 'dev-3.8' of git.mesalab.cn:nezha/nezha-fronted into dev-3.8

This commit is contained in:
zyh
2023-09-22 17:55:57 +08:00
4 changed files with 17 additions and 8 deletions

View File

@@ -45,6 +45,7 @@
"caniuse-lite": "^1.0.30001412",
"codemirror-promql": "^0.19.0",
"css-minimizer-webpack-plugin": "^1.0.0",
"csv-string": "^4.1.1",
"cytoscape": "^3.15.2",
"d3": "^6.7.0",
"d3-hexbin": "^0.2.2",

View File

@@ -9,6 +9,7 @@ import {
chartTimeSeriesAreaOption,
chartTimeSeriesScatterOption
} from './chart/options/chartTimeSeries'
import * as CSV from 'csv-string';
export default {
data () {
return {
@@ -532,6 +533,7 @@ export default {
// 兼容ie11
const blobObject = new Blob([csv])
window.navigator.msSaveOrOpenBlob(blobObject, chart.name + '.csv')
this.$message.success(this.$t('tip.downloadSuccess'))
} else {
const blob = new Blob([csv])
const link = document.createElement('a')
@@ -542,11 +544,12 @@ export default {
link.click() // 点击下载
document.body.removeChild(link) // 下载完成移除元素
window.URL.revokeObjectURL(href) // 释放blob对象
this.$message.success(this.$t('tip.downloadSuccess'))
}
},
convertTimeSertesToCSV (chartInfo) {
const data = this.series
let csv = 'time,legend,value\n'
let csv = '"time","legend","value"\n'
data.forEach((item, index) => {
item.data.forEach(value => {
let val = formatScientificNotation(value[1], this.$lodash.get(chartInfo, 'param.decimals', 2))
@@ -557,13 +560,16 @@ export default {
unit = chartDataFormat.getUnit(this.$lodash.get(chartInfo, 'unit', 2))
}
val = unit.compute(val, index, -1, chartInfo.param.decimals || 2)
csv += `${this.momentTz(value[0] * 1000)},${this.legends[index].alias},${val}\n`
csv += `"${this.momentTz(value[0] * 1000)}","${this.yasuo(this.legends[index].alias)}","${val}"\n`
})
})
return csv
},
yasuo (str) {
return str.replace(/\"/g, '\"\"')
},
convertOtherToCSV (chartInfo) {
let csv = 'legend,value\n'
let csv = '"legend","value"\n'
let keyByData = ''
let legend = 'legend'
switch (chartInfo.type) {
@@ -618,18 +624,18 @@ export default {
return
}
this.$lodash.get(this, keyByData, []).forEach(item => {
csv += `${item[legend]},${item.showValue}\n`
csv += `"${this.yasuo(item[legend])}","${item.showValue}"\n`
})
return csv
},
convertTableToCSV (chartInfo) {
let csv = ''
csv = this.columns.map(item => item.title).join(',')
csv = this.columns.map(item => '"' + this.yasuo(item.title) + '"').join(',')
csv += '\n'
this.oldTableData.forEach(item => {
let arr = []
this.columns.forEach(column => {
arr.push(item.display[column.title + 'display'].display)
arr.push(`"${this.yasuo(item.display[column.title + 'display'].display)}"`)
})
arr = arr.join(',')
csv += arr

View File

@@ -72,7 +72,8 @@ export default {
servicesTableData: [],
ringTableData: [],
readyTableData: '',
loading: false
loading: false,
fromBottom: true
}
},
mounted () {

View File

@@ -73,7 +73,8 @@ export default {
servicesTableTitle: [],
ringTableData: [],
readyTableData: '',
loading: false
loading: false,
fromBottom: true
}
},
mounted () {