2022-07-29 09:55:58 +08:00
|
|
|
<template>
|
|
|
|
|
<div class="npm-header">
|
2022-09-08 17:09:38 +08:00
|
|
|
<div class="npm-header-body" v-for="(item, index) in chartData" :key=index>
|
2022-07-29 09:55:58 +08:00
|
|
|
<div class="npm-header-body-severity">
|
2023-01-30 14:02:28 +08:00
|
|
|
<div class="npm-header-body-severity-icon" :class="item.eventSeverity" :test-id="`icon${index}`"></div>
|
|
|
|
|
<div class="npm-header-body-severity-value" :test-id="`severity${index}`">{{item.eventSeverity}}</div>
|
2022-07-29 09:55:58 +08:00
|
|
|
</div>
|
2022-11-21 17:31:30 +08:00
|
|
|
<chart-error v-if="showError" tooltip :content="errorMsg" />
|
2023-01-30 14:02:28 +08:00
|
|
|
<div v-else class="npm-header-body-total" :test-id="`total${index}`">{{item.count}}</div>
|
2022-07-29 09:55:58 +08:00
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
</template>
|
|
|
|
|
|
|
|
|
|
<script>
|
2022-08-11 16:45:48 +08:00
|
|
|
import { getSecond } from '@/utils/date-util'
|
|
|
|
|
import { api } from '@/utils/api'
|
2022-08-21 22:11:53 +08:00
|
|
|
import chartMixin from '@/views/charts2/chart-mixin'
|
2022-11-21 17:31:30 +08:00
|
|
|
import ChartError from '@/components/common/Error'
|
2023-01-30 14:02:28 +08:00
|
|
|
import axios from 'axios'
|
2023-02-27 16:01:25 +08:00
|
|
|
|
2022-07-29 09:55:58 +08:00
|
|
|
export default {
|
|
|
|
|
name: 'NpmEventsHeader',
|
2022-11-21 17:31:30 +08:00
|
|
|
components: { ChartError },
|
2022-08-21 22:11:53 +08:00
|
|
|
mixins: [chartMixin],
|
2022-07-29 09:55:58 +08:00
|
|
|
data () {
|
|
|
|
|
return {
|
2022-09-08 17:09:38 +08:00
|
|
|
chartData: [
|
|
|
|
|
{
|
|
|
|
|
eventSeverity: 'critical',
|
|
|
|
|
count: '-',
|
|
|
|
|
index: 0
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
eventSeverity: 'high',
|
|
|
|
|
count: '-',
|
|
|
|
|
index: 1
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
eventSeverity: 'medium',
|
|
|
|
|
count: '-',
|
|
|
|
|
index: 2
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
eventSeverity: 'low',
|
|
|
|
|
count: '-',
|
|
|
|
|
index: 3
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
eventSeverity: 'info',
|
|
|
|
|
count: '-',
|
|
|
|
|
index: 4
|
|
|
|
|
}
|
|
|
|
|
],
|
2022-11-21 17:31:30 +08:00
|
|
|
type: 'severity',
|
|
|
|
|
showError: false,
|
|
|
|
|
errorMsg: ''
|
2022-07-29 09:55:58 +08:00
|
|
|
}
|
|
|
|
|
},
|
2022-08-23 21:42:42 +08:00
|
|
|
watch: {
|
|
|
|
|
timeFilter: {
|
2022-11-23 17:20:37 +08:00
|
|
|
handler () {
|
2022-08-23 21:42:42 +08:00
|
|
|
this.recentEventsListData()
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
},
|
2022-08-11 16:45:48 +08:00
|
|
|
methods: {
|
|
|
|
|
recentEventsListData () {
|
|
|
|
|
const params = {
|
2023-01-30 14:02:28 +08:00
|
|
|
startTime: this.timeFilter && this.timeFilter.startTime ? getSecond(this.timeFilter.startTime) : '',
|
|
|
|
|
endTime: this.timeFilter && this.timeFilter.endTime ? getSecond(this.timeFilter.endTime) : '',
|
2022-08-12 15:25:54 +08:00
|
|
|
type: this.type
|
2022-07-29 09:55:58 +08:00
|
|
|
}
|
2022-08-21 22:11:53 +08:00
|
|
|
this.toggleLoading(true)
|
2023-01-30 14:02:28 +08:00
|
|
|
axios.get(api.npm.events.list, { params: params }).then(res => {
|
|
|
|
|
res = res.data
|
2022-08-11 16:45:48 +08:00
|
|
|
if (res.code === 200) {
|
2022-11-21 17:31:30 +08:00
|
|
|
this.showError = false
|
2022-12-09 10:24:40 +08:00
|
|
|
if (res.data.result.length === 0) {
|
|
|
|
|
this.chartData.forEach(d => { d.count = '-' })
|
|
|
|
|
}
|
2022-08-12 15:25:54 +08:00
|
|
|
res.data.result.forEach(t => {
|
2022-09-08 17:09:38 +08:00
|
|
|
this.chartData.forEach(d => {
|
|
|
|
|
if (d.eventSeverity === t.eventSeverity) {
|
2022-10-14 18:24:39 +08:00
|
|
|
d.count = t.count.toLocaleString()
|
2022-09-08 17:09:38 +08:00
|
|
|
}
|
|
|
|
|
})
|
2022-08-12 15:25:54 +08:00
|
|
|
})
|
2022-11-21 17:31:30 +08:00
|
|
|
} else {
|
|
|
|
|
this.showError = true
|
|
|
|
|
this.errorMsg = res.message
|
2022-08-11 16:45:48 +08:00
|
|
|
}
|
2023-03-16 19:07:37 +08:00
|
|
|
}).catch(e => {
|
2022-11-21 17:31:30 +08:00
|
|
|
this.showError = true
|
2023-03-16 19:07:37 +08:00
|
|
|
this.errorMsg = this.errorMsgHandler(e)
|
2022-08-21 22:11:53 +08:00
|
|
|
}).finally(() => {
|
|
|
|
|
this.toggleLoading(false)
|
2022-08-11 16:45:48 +08:00
|
|
|
})
|
2022-07-29 09:55:58 +08:00
|
|
|
}
|
2022-08-11 16:45:48 +08:00
|
|
|
},
|
|
|
|
|
mounted () {
|
2023-01-30 14:02:28 +08:00
|
|
|
this.$nextTick(() => {
|
|
|
|
|
this.recentEventsListData()
|
|
|
|
|
})
|
2022-07-29 09:55:58 +08:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
</script>
|