feat: 添加显示更多的选项

This commit is contained in:
zhangyu
2021-12-23 10:44:30 +08:00
parent e2733f9710
commit 8c46345aa1
7 changed files with 157 additions and 100 deletions

View File

@@ -13,6 +13,19 @@
</span> </span>
</el-popover> </el-popover>
</span> </span>
<span v-if="!isError&&!showAllData&&allDataLength>20" class="chart-header-error moreTitle">
<el-popover
placement="top-start"
:close-delay=10
trigger="hover"
popper-class="chart-warring-popper">
<div class="moreTitle">{{$t('dashboard.panel.moreTitle')}}{{$t('dashboard.panel.showAll')}}{{allDataLength}}</div>
<span slot="reference" class="panel-info-corner panel-info-corner--error" @click="loadMore">
<i class="nz-icon nz-icon-warning fa"></i>
<span class="panel-info-corner-inner"></span>
</span>
</el-popover>
</span>
<div class="chart-header__title">{{chartInfo.name}}</div> <div class="chart-header__title">{{chartInfo.name}}</div>
<div class="chart-header__tools"> <div class="chart-header__tools">
<span v-if="chartInfo.remark" class="chart-header__tool top-tool-btn-group"> <span v-if="chartInfo.remark" class="chart-header__tool top-tool-btn-group">
@@ -33,25 +46,10 @@
<script> <script>
import bus from '@/libs/bus' import bus from '@/libs/bus'
import lodash from 'lodash' import lodash from 'lodash'
import chartHeaderMixin from "@/components/chart/chartHeaderMixin";
export default { export default {
name: 'ChartScreenHeader', name: 'ChartScreenHeader',
props: { mixins: [chartHeaderMixin],
chartInfo: Object,
from: String,
isGroup: {
type: Boolean,
default: false
},
error: {
type: String,
default: ''
},
isError: {
type: Boolean,
default: false
},
chartData: {}
},
computed: { computed: {
timeRange () { timeRange () {
return this.$store.getters.getTimeRange return this.$store.getters.getTimeRange
@@ -134,14 +132,6 @@ export default {
} }
}, },
watch: { watch: {
isError: {
immediate: true,
handler (n) {
if (n) {
this.errorText = this.chartData.filter(item => item.error).map(item => item.error).join('\n')
}
}
},
timeRange: { timeRange: {
immediate: true, immediate: true,
handler (n) { handler (n) {

View File

@@ -12,6 +12,7 @@
:is-fullscreen="isFullscreen" :is-fullscreen="isFullscreen"
:minusTime="minusTime" :minusTime="minusTime"
:multipleTime="multipleTime" :multipleTime="multipleTime"
:showAllData="showAllData"
@chartIsNoData="chartIsNoData" @chartIsNoData="chartIsNoData"
></chart-time-series> ></chart-time-series>
<chart-pie <chart-pie
@@ -226,7 +227,11 @@ export default {
isError: Boolean, isError: Boolean,
filter: {}, filter: {},
multipleTime: {}, multipleTime: {},
minusTime: {} minusTime: {},
showAllData: {
type: Boolean,
default: false
}
}, },
data () { data () {
return { return {

View File

@@ -69,6 +69,7 @@ export default {
}, },
methods: { methods: {
initChart (chartOption = this.chartOption) { initChart (chartOption = this.chartOption) {
console.log(123)
this.legends = [] this.legends = []
chartOption.series = this.handleTimeSeries(this.chartInfo, chartOption.series[0], this.chartData) // 生成series和legends chartOption.series = this.handleTimeSeries(this.chartInfo, chartOption.series[0], this.chartData) // 生成series和legends
if (this.isNoData) { if (this.isNoData) {
@@ -151,7 +152,6 @@ export default {
let sum = 0 let sum = 0
let flag = true let flag = true
params.forEach((item, i) => { params.forEach((item, i) => {
console.log(item)
const seriesName = item.seriesName.split('-')[0] const seriesName = item.seriesName.split('-')[0]
if (i === 0) { if (i === 0) {
const value = bus.computeTimezone(item.data[0] * 1000) const value = bus.computeTimezone(item.data[0] * 1000)

View File

@@ -13,6 +13,19 @@
</span> </span>
</el-popover> </el-popover>
</span> </span>
<span v-if="!isError&&!showAllData&&allDataLength>10" class="chart-header-error moreTitle">
<el-popover
placement="top-start"
:close-delay=10
trigger="hover"
popper-class="chart-warring-popper">
<div class="moreTitle">{{$t('dashboard.panel.moreTitle')}}{{$t('dashboard.panel.showAll')}}{{allDataLength}}</div>
<span slot="reference" class="panel-info-corner panel-info-corner--error" @click="loadMore">
<i class="nz-icon nz-icon-warning fa"></i>
<span class="panel-info-corner-inner"></span>
</span>
</el-popover>
</span>
<div class="chart-header__title" v-if="!isGroup">{{chartInfo.name}}</div> <div class="chart-header__title" v-if="!isGroup">{{chartInfo.name}}</div>
<div class="chart-header__title" v-else > <div class="chart-header__title" v-else >
<span @click="groupShow"> <i class="nz-icon" :class="chartInfo.param.collapse ? 'nz-icon-arrow-down': 'nz-icon-arrow-right'"></i></span> <span @click="groupShow"> <i class="nz-icon" :class="chartInfo.param.collapse ? 'nz-icon-arrow-down': 'nz-icon-arrow-right'"></i></span>
@@ -63,73 +76,9 @@
</template> </template>
<script> <script>
import chartHeaderMixin from '@/components/chart/chartHeaderMixin'
export default { export default {
name: 'chartHeader', name: 'chartHeader',
props: { mixins: [chartHeaderMixin],
chartInfo: Object,
from: String,
isGroup: {
type: Boolean,
default: false
},
error: {
type: String,
default: ''
},
isError: {
type: Boolean,
default: false
},
chartData: {}
},
data () {
return {
dropdownMenuShow: false,
errorText: ''
}
},
methods: {
showFullscreen () {
this.$emit('showFullscreen', true)
},
refreshChart () {
this.$emit('refresh')
},
editChart () {
// this.$emit('edit-chart', this.chartInfo)
this.$store.dispatch('dispatchEditChart', {
chart: this.chartInfo,
type: 'edit'
})
},
removeChart () {
this.$store.dispatch('dispatchDelChart', {
chart: this.chartInfo,
type: 'delete'
})
},
duplicate () {
this.$store.dispatch('dispatchEditChart', {
chart: this.chartInfo,
type: 'duplicate'
})
},
clickos () {
this.dropdownMenuShow = false
},
groupShow () {
this.$emit('groupShow', !this.chartInfo.param.collapse)
}
},
watch: {
isError: {
immediate: true,
handler (n) {
if (n) {
this.errorText = this.chartData.filter(item => item.error).map(item => item.error).join('\n')
}
}
}
}
} }
</script> </script>

View File

@@ -0,0 +1,79 @@
export default {
props: {
chartInfo: Object,
from: String,
isGroup: {
type: Boolean,
default: false
},
error: {
type: String,
default: ''
},
isError: {
type: Boolean,
default: false
},
chartData: {},
showAllData: {
type: Boolean,
default: false
},
allDataLength: {
type: Number,
default: 0
}
},
data () {
return {
dropdownMenuShow: false,
errorText: ''
}
},
methods: {
showFullscreen () {
this.$emit('showFullscreen', true)
},
refreshChart () {
this.$emit('refresh')
},
editChart () {
// this.$emit('edit-chart', this.chartInfo)
this.$store.dispatch('dispatchEditChart', {
chart: this.chartInfo,
type: 'edit'
})
},
removeChart () {
this.$store.dispatch('dispatchDelChart', {
chart: this.chartInfo,
type: 'delete'
})
},
duplicate () {
this.$store.dispatch('dispatchEditChart', {
chart: this.chartInfo,
type: 'duplicate'
})
},
clickos () {
this.dropdownMenuShow = false
},
groupShow () {
this.$emit('groupShow', !this.chartInfo.param.collapse)
},
loadMore () {
this.$emit('loadMore')
}
},
watch: {
isError: {
immediate: true,
handler (n) {
if (n) {
this.errorText = this.chartData.filter(item => item.error).map(item => item.error).join('\n')
}
}
}
}
}

View File

@@ -15,14 +15,17 @@ export default {
}, },
chartId: '', chartId: '',
isNoData: true, isNoData: true,
showAllData: false
} }
}, },
props: { props: {
chartInfo: Object, chartInfo: Object,
chartData: Array, chartData: Array,
chartOption: Object, chartOption: Object,
isFullscreen: Boolean isFullscreen: Boolean,
showAllData: {
type: Boolean,
default: false
}
}, },
computed: { computed: {
filterTime () { filterTime () {
@@ -41,10 +44,11 @@ export default {
let colorIndex = 0 let colorIndex = 0
originalDatas.forEach((originalData, expressionIndex) => { originalDatas.forEach((originalData, expressionIndex) => {
originalData.forEach((data, dataIndex) => { originalData.forEach((data, dataIndex) => {
// if (colorIndex >= 20 && !this.showAllData) { console.log(this.showAllData)
// colorIndex++ if (colorIndex >= 20 && !this.showAllData) {
// return colorIndex++
// } return
}
this.isNoData = false this.isNoData = false
const s = lodash.cloneDeep(seriesTemplate) const s = lodash.cloneDeep(seriesTemplate)
if (s) { if (s) {

View File

@@ -8,6 +8,9 @@
:isError="isError" :isError="isError"
:chartData="chartData" :chartData="chartData"
:chart-info="chartInfo" :chart-info="chartInfo"
:showAllData.sync="showAllData"
:allDataLength="allDataLength"
@loadMore="loadMore"
@edit-chart="$emit('edit-chart', chartInfo)" @edit-chart="$emit('edit-chart', chartInfo)"
@refresh="refresh" @refresh="refresh"
@groupShow="groupShow" @groupShow="groupShow"
@@ -20,6 +23,9 @@
:isError="isError" :isError="isError"
:chartData="chartData" :chartData="chartData"
:chart-info="chartInfo" :chart-info="chartInfo"
:showAllData.sync="showAllData"
:allDataLength="allDataLength"
@loadMore="loadMore"
@refresh="refresh" @refresh="refresh"
@dateChange="dateChange" @dateChange="dateChange"
@close="showFullscreen" @close="showFullscreen"
@@ -38,6 +44,7 @@
:minusTime="minusTime" :minusTime="minusTime"
:multipleTime="multipleTime" :multipleTime="multipleTime"
:is-fullscreen="isFullscreen" :is-fullscreen="isFullscreen"
:showAllData="showAllData"
v-if="!isGroup(chartInfo.type) || !chartInfo.param.collapse" v-if="!isGroup(chartInfo.type) || !chartInfo.param.collapse"
></chart> ></chart>
</div> </div>
@@ -77,7 +84,9 @@ export default {
loading: true, loading: true,
isError: false, isError: false,
multipleTime: false, multipleTime: false,
minusTime: '' minusTime: '',
showAllData: false,
allDataLength: 0
} }
}, },
computed: { computed: {
@@ -139,6 +148,7 @@ export default {
}, },
query (elements, startTime, endTime, step) { query (elements, startTime, endTime, step) {
this.isError = false this.isError = false
this.allDataLength = 0
try { try {
switch (this.chartInfo.datasource) { switch (this.chartInfo.datasource) {
case 'metrics': case 'metrics':
@@ -187,6 +197,9 @@ export default {
res.forEach((r, rIndex) => { res.forEach((r, rIndex) => {
if (rIndex < elements.length) { if (rIndex < elements.length) {
if (r.status === 'success') { if (r.status === 'success') {
r.data.result.forEach(item => {
this.allDataLength++
})
chartData.push(r.data.result) chartData.push(r.data.result)
} else { } else {
chartData.push({ error: r.msg || r.error || r }) chartData.push({ error: r.msg || r.error || r })
@@ -196,6 +209,7 @@ export default {
if (r.status === 'success') { if (r.status === 'success') {
console.log(r.data.result) console.log(r.data.result)
r.data.result.forEach(item => { r.data.result.forEach(item => {
this.allDataLength++
item.values.forEach(values => { item.values.forEach(values => {
values[0] = values[0] + this.minusTime / 1000 values[0] = values[0] + this.minusTime / 1000
}) })
@@ -360,6 +374,21 @@ export default {
this.groupInit() this.groupInit()
bus.$emit('groupMove', '', '', true) bus.$emit('groupMove', '', '', true)
this.$emit('groupShow', this.chartInfo) this.$emit('groupShow', this.chartInfo)
},
showMultiple (type) {
switch (type) {
case 'line' :
case 'area' :
case 'point' :
return true
default: return false
}
},
loadMore () {
this.showAllData = true
this.$nextTick(() => {
this.$refs.chart && this.$refs.chart.$refs['chart' + this.chartInfo.id].initChart()
})
} }
}, },
watch: { watch: {
@@ -378,6 +407,7 @@ export default {
}, },
mounted () { mounted () {
this.chartInfo.loaded && this.getChartData() this.chartInfo.loaded && this.getChartData()
this.showAllData = !this.showMultiple(this.chartInfo.type)
} }
} }
</script> </script>