This repository has been archived on 2025-09-14. You can view files and clone it, but cannot push or open issues or pull requests.
Files
cyber-narrator-cn-ui/src/views/charts2/charts/npm/NpmEventsHeader.vue

100 lines
2.4 KiB
Vue
Raw Normal View History

<template>
<div class="npm-header">
<div class="npm-header-body" v-for="(item, index) in chartData" :key=index>
<div class="npm-header-body-severity">
<div class="npm-header-body-severity-icon" :class="item.eventSeverity"></div>
<div class="npm-header-body-severity-value">{{item.eventSeverity}}</div>
</div>
2022-11-21 17:31:30 +08:00
<chart-error v-if="showError" tooltip :content="errorMsg" />
<div v-else class="npm-header-body-total">{{item.count}}</div>
</div>
</div>
</template>
<script>
import { getSecond } from '@/utils/date-util'
import { get } from '@/utils/http'
import { api } from '@/utils/api'
import chartMixin from '@/views/charts2/chart-mixin'
2022-11-21 17:31:30 +08:00
import ChartError from '@/components/common/Error'
export default {
name: 'NpmEventsHeader',
2022-11-21 17:31:30 +08:00
components: { ChartError },
mixins: [chartMixin],
data () {
return {
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-08-23 21:42:42 +08:00
watch: {
timeFilter: {
handler () {
2022-08-23 21:42:42 +08:00
this.recentEventsListData()
}
}
},
methods: {
recentEventsListData () {
const params = {
startTime: getSecond(this.timeFilter.startTime),
endTime: getSecond(this.timeFilter.endTime),
type: this.type
}
this.toggleLoading(true)
get(api.npm.events.list, params).then(res => {
if (res.code === 200) {
2022-11-21 17:31:30 +08:00
this.showError = false
res.data.result.forEach(t => {
this.chartData.forEach(d => {
if (d.eventSeverity === t.eventSeverity) {
d.count = t.count.toLocaleString()
}
})
})
2022-11-21 17:31:30 +08:00
} else {
this.showError = true
this.errorMsg = res.message
}
2022-11-21 17:31:30 +08:00
}).catch(error => {
this.showError = true
this.errorMsg = error.message
}).finally(() => {
this.toggleLoading(false)
})
}
},
mounted () {
this.recentEventsListData()
}
}
</script>