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
nezha-nezha-fronted/nezha-fronted/src/components/common/mixin/table.js

196 lines
5.8 KiB
JavaScript
Raw Normal View History

export default {
props: {
tableData: {
type: Array
},
customTableTitle: {
type: Array
},
height: {
type: String,
default: '100%'
},
api: {
type: String
},
tableId: {
type: String
},
orderByFa: {}
},
data () {
return {
operationWidth: '165', // 操作列宽
orderBy: {},
severityDataWeight: this.$store.getters.severityDataWeight
}
},
methods: {
tableOperation ([command, row, param]) {
switch (command) {
case 'delete': {
this.$emit('del', row)
break
}
case 'recordTab': {
this.$emit('showBottomBox', 'recordTab', row)
2021-04-13 20:33:12 +08:00
break
}
2021-05-19 23:17:24 +08:00
case 'endpointQuery': {
this.$emit('showBottomBox', 'endpointQuery', row)
break
}
case 'sync': {
// this.$emit('copy', row)
this.$emit('sync', row)
break
}
case 'fastSilence': {
// this.$emit('copy', row)
this.$emit('addSilence', row, param)
break
}
default:
2021-05-19 23:17:24 +08:00
this.$emit(command, row)
break
}
},
2021-04-13 10:00:48 +08:00
selectionChange (objs) {
this.$emit('selectionChange', objs)
},
isBuiltIn (row) {
return (row.buildIn && row.buildIn == 1) || (row.builtIn && row.builtIn == 1)
},
dragend () {
this.$nextTick(() => {
this.$refs.dataTable.doLayout()
})
},
showBottomBox (targetTab, row) {
this.$emit('showBottomBox', targetTab, JSON.parse(JSON.stringify(row)))
},
tableDataSort (item) {
let orderBy = ''
let str = item.prop
if (str === 'dc') {
str = 'datacenter'
}
if (item.order === 'ascending') {
orderBy = str
}
if (item.order === 'descending') {
orderBy = '-' + str
}
this.$emit('orderBy', orderBy)
},
getWeeksTime () {
const localOffset = new Date().getTimezoneOffset() // 默认 显示时区偏移的结果 单位分钟
const now = new Date(new Date().toLocaleDateString()).getTime() - localOffset * 60 * 1000
const arr = []
for (let i = 0; i < 7; i++) {
const obj = {
time: now - i * 24 * 60 * 60 * 1000,
tooltipShow: false,
position: {
left: 0,
top: 0
}
}
this.severityDataWeight.forEach(item => {
obj[item.name] = 0
obj[item.name + 'Color'] = item.color
})
arr.unshift(obj)
}
return arr
}
},
watch: {
orderByFa: {
immediate: true,
handler (n) {
if (n) {
const index = n.indexOf('-')
if (index !== -1) {
this.orderBy[n.slice(index + 1)] = 'descending'
} else {
this.orderBy[n] = 'descending'
}
}
}
2022-01-17 16:32:00 +08:00
},
tableData: {
immediate: true,
handler (n) {
if (n && n.length) {
const id = this.$store.getters.getGlobalSearchId
if (id) {
setTimeout(() => {
if (document.getElementById('globalSearch' + id)) {
document.getElementById('globalSearch' + id).scrollIntoView(true)
this.$store.commit('setGlobalSearchId', '')
}
}, 500)
}
if (this.needAlertDaysData) {
const weekDays = this.getWeeksTime()
n.forEach(item => {
const params = {
type: 'total',
dimension: 'priority',
step: 'd'
}
params[this.trendKey] = item.id
setTimeout(() => {
this.$get('/stat/alertMessage/trend', params).then((res) => {
// res = {
// msg: 'success',
// code: 200,
// data: {
// result: [
// {
// values: [
// {
// metric: { priority: 'P1' },
// values: []
// }, {
// metric: { priority: 'P2' },
// values: [
// [1645142400000, 0], [1645228800000, 3], [1645315200000, 20], [1645401600000, 0], [1645488000000, 0], [1645574400000, 3], [1645660800000, 20]
// ]
// }, {
// metric: { priority: 'P3' },
// values: [
// [1645142400000, 1], [1645228800000, 3], [1645315200000, 20], [1645401600000, 0], [1645488000000, 0], [1645574400000, 3], [1645660800000, 20]
// ]
// }]
// }],
// resultType: 'matrix'
// },
// time: '2022-02-24 08:41:35'
// }
const alertDaysData = res.data.result ? res.data.result[0].values : []
const newWeekDays = JSON.parse(JSON.stringify(weekDays))
alertDaysData.forEach(item => {
item.values.forEach(time => {
const findItem = newWeekDays.find(days => days.time == time[0])
if (findItem) {
findItem[item.metric.priority] = time[1]
}
})
})
setTimeout(() => {
item.alertDaysData = newWeekDays
item.trendLoading = false
})
})
})
})
}
2022-01-17 16:32:00 +08:00
}
}
}
2022-01-17 16:32:00 +08:00
// document.querySelector("#header").scrollIntoView(true);
}
}