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/table/settings/endpointTable.vue

429 lines
17 KiB
Vue
Raw Normal View History

2021-04-14 18:55:01 +08:00
<template>
<div style="height: 100%">
<el-table
id="endpointTable"
ref="dataTable"
:data="tableData"
:height="height"
border
:default-sort="orderBy"
@header-dragend="dragend"
@sort-change="tableDataSort"
@selection-change="selectionChange"
@row-dblclick="(row)=>{$emit('showBottomBox', 'panelTab', row)}"
2021-04-14 18:55:01 +08:00
>
<el-table-column
:resizable="false"
align="center"
type="selection"
width="55">
</el-table-column>
<el-table-column
v-for="(item, index) in customTableTitle"
v-if="item.show"
:key="`col-${index}`"
:fixed="item.fixed"
:label="item.label"
:min-width="`${item.minWidth}`"
:prop="item.prop"
:resizable="true"
:sort-orders="['ascending', 'descending']"
:sortable="item.sortable"
:width="`${item.width}`"
class="data-column"
>
<template slot="header">
<span class="data-column__span">{{item.label}}</span>
<div class="col-resize-area"></div>
2021-04-14 18:55:01 +08:00
</template>
<template slot-scope="scope" :column="item">
<template v-if="item.prop === 'name'">
2022-07-05 14:06:31 +08:00
<div class="document-copy-block">
<span class="document-copy-text">{{scope.row[item.prop]}}</span>
2022-07-22 10:46:49 +08:00
<i v-if="scope.row[item.prop]" class="nz-icon nz-icon-override" style="visibility: hidden" @click="onCopy(scope.row.name)" :title="$t('overall.copyText')"></i>
</div>
</template>
<template v-else-if="item.prop === 'type'">
{{scope.row.module.type}}
</template>
<template v-else-if="item.prop === 'project'">
2022-07-05 14:06:31 +08:00
<div class="document-copy-block">
<span class="pointer document-copy-text"
@mouseenter="labelHover(scope.row, item.prop, true,true, $event)"
@mouseleave="labelHover(scope.row, item.prop, false,true)">
{{scope.row[item.prop].name}}
</span>
2022-07-22 10:46:49 +08:00
<i v-if="scope.row[item.prop].name" class="nz-icon nz-icon-override" style="visibility: hidden" @click="onCopy(scope.row[item.prop].name)" :title="$t('overall.copyText')"></i>
</div>
</template>
<template v-else-if="item.prop === 'module'">
2022-07-05 14:06:31 +08:00
<div class="document-copy-block">
<span class="pointer document-copy-text"
@mouseenter="labelHover(scope.row, item.prop, true,true, $event)"
@mouseleave="labelHover(scope.row, item.prop, false,true)">
<i style="cursor: pointer" class="nz-icon nz-icon-overview-module monitorColor"/>
{{scope.row[item.prop].name}}
</span>
2022-07-22 10:46:49 +08:00
<i v-if="scope.row[item.prop].name" class="nz-icon nz-icon-override" style="visibility: hidden" @click="onCopy(scope.row[item.prop].name)" :title="$t('overall.copyText')"></i>
</div>
</template>
<template v-else-if="item.prop === 'asset'">
2022-07-05 14:06:31 +08:00
<div class="document-copy-block">
<span
class="pointer document-copy-text"
@mouseenter="labelHover(scope.row, item.prop, true,true, $event)"
@mouseleave="labelHover(scope.row, item.prop, false,true)">
<i class="nz-icon nz-icon-overview-project monitorColor color23BF9A"></i>
{{scope.row.asset&&scope.row.asset.name}}
</span>
<i v-if="scope.row.asset&&scope.row.asset.name" class="nz-icon nz-icon-override" style="visibility: hidden" @click="onCopy(scope.row.asset.name)" :title="$t('overall.copyText')"></i>
</div>
</template>
<template v-else-if="item.prop === 'alerts'">
2022-02-25 14:31:36 +08:00
<span style="cursor: pointer" @click="showBottomBox('endpointAlertMessage', scope.row)">
<i :class="scope.row.alertNum ? 'red' : 'green'" class="nz-icon nz-icon-overview-alert vertical-align-top;" @mouseenter="tooltipHover(scope.row,true, $event)" @mouseleave="tooltipHover(scope.row,false, $event)"></i>
<div v-if="scope.row.alertNumtooltipShow" class="alert-days-info-tooltip" :style="{left: scope.row.left + 'px',top:scope.row.top + 'px'}">
2022-06-21 18:14:21 +08:00
<div class="tooltip-title">{{$t('project.topology.alert')}}({{$t('overall.active')}})</div>
2022-02-25 14:31:36 +08:00
<div class="severity-info" style='justify-content: space-between'>
<div class="severity-name">{{$t('overall.result.total')}}</div>
<div class="severity-value">{{scope.row.alertNum}}</div>
</div>
</div>
<alertDaysInfo
v-show="!scope.row.trendLoading"
:alertDaysData="scope.row.alertDaysData"
/>
</span>
</template>
<template v-else-if="item.prop === 'configs'">
<span class="configs-endpoint metrics"
@mouseenter="labelHover1(scope.row, item.prop, true, $event)"
@mouseleave="labelHover1(scope.row, item.prop, false, $event, true)">
[{{scope.row.configs[0].enable ? 'Metrics':''}}{{scope.row.configs[0].enable&&scope.row.configs[1].enable?',':''}}{{scope.row.configs[1].enable ? 'logs' : ''}}]
</span>
<nz-tooltip :that="scope.row[item.prop]" class="data-column__" v-if="scope.row[item.prop] && scope.row[item.prop].loading" :type="item.prop">
<div name="default">
<span class="copy-value-content" :title="$t('overall.duplicate')"> <i class="nz-icon nz-icon-override" @click="copyValue(clConfigs(scope.row))"></i></span>
<pre class="copy-value-content__pre">{{JSON.stringify(clConfigs(scope.row),null,2)}}</pre>
</div>
</nz-tooltip>
</template>
<template v-else-if="item.prop === 'state'">
<!-- metrics-->
<span style="width: auto;display: inline-block;cursor: pointer"
@mouseenter="labelHoverConfigs(scope.row, 0, true, $event)"
@mouseleave="labelHoverConfigs(scope.row, 0, false, $event)"
>
2022-06-21 18:14:21 +08:00
<span class="endpoint-cell-left"><i class="nz-icon nz-icon-Metrics colorFA901C" /> {{$t('overall.metric')}} </span>
<span v-if="scope.row.configs[0].state===0 || !scope.row.configs[0].state">
<span class="active-icon red-bg inline-block"></span>
</span>
<span v-else-if="scope.row.configs[0].state===1">
<span class="active-icon green-bg inline-block"></span>
</span>
<span v-else-if="scope.row.configs[0].state">
<span class="active-icon gray-bg inline-block"></span>
</span>
</span>
<nz-tooltip :that="scope.row.configs[0]" v-if="scope.row.configs[0] && scope.row.configs[0].loading && scope.row.configs[0].state > 1" :type="'configs[0]'">
<div name="default">
<div v-html="suspendedStr(scope.row.configs[0].state)"></div>
</div>
</nz-tooltip>
<!-- logs-->
<span style="width: auto;display: inline-block;cursor: pointer"
@mouseenter="labelHoverConfigs(scope.row, 1, true, $event)"
@mouseleave="labelHoverConfigs(scope.row, 1, false, $event)">
2022-07-13 11:20:17 +08:00
<span class="endpoint-cell-left" style="margin-left: 10px"><i class="nz-icon nz-icon-logs colorFA901C" /> {{$t('dashboard.panel.chartForm.typeVal.log.label')}} </span>
<span v-if="scope.row.configs[1].state===0 || !scope.row.configs[1].state">
<span class="active-icon red-bg inline-block"></span>
</span>
<span v-else-if="scope.row.configs[1].state===1">
<span class="active-icon green-bg inline-block"></span>
</span>
<span v-else-if="scope.row.configs[1].state">
<span class="active-icon gray-bg inline-block"></span>
</span>
</span>
<nz-tooltip :that="scope.row.configs[1]" v-if="scope.row.configs[1] && scope.row.configs[1].loading && scope.row.configs[1].state > 1" :type="'configs[1]'" :isTopoInfo="isTopoInfo">
<div name="default">
<div v-html="suspendedStr(scope.row.configs[1].state)"></div>
</div>
</nz-tooltip>
</template>
<template v-else-if="item.prop === 'enabled'">
2022-06-23 16:58:18 +08:00
<span v-if="scope.row[item.prop] === 1">{{$t('overall.enabled')}}</span>
2022-06-21 14:17:46 +08:00
<span v-else>{{$t('profile.close')}}</span>
</template>
<span v-else-if="item.prop === 'id'" :id="'globalSearch' + scope.row.id">{{scope.row[item.prop]}}</span>
<span v-else>{{scope.row[item.prop] ? scope.row[item.prop] : ''}}</span>
</template>
</el-table-column>
<el-table-column
:resizable="false"
:width="operationWidth"
v-if="showOption"
fixed="right">
<div slot="header" class="table-operation-title">{{$t('overall.option')}}</div>
<div slot-scope="scope" class="table-operation-items">
<button v-if="endpointTab" class="table-operation-item" v-has="'monitor_endpoint_edit'" @click="$emit('edit', scope.row)" :title="$t('overall.edit')"><i class="nz-icon nz-icon-edit"></i></button>
<button v-else class="table-operation-item" @click="$emit('showBottomBox', 'panelTab', scope.row)" :title="$t('overall.view')"><i class="nz-icon nz-icon-view1"></i></button>
<el-dropdown size="medium" v-has="['monitor_endpoint_edit','monitor_endpoint_delete','alertSilence_add']" trigger="click" @command="tableOperation">
<div class="table-operation-item table-operation-item--more" :title="$t('overall.moreOperations')">
<i class="nz-icon nz-icon-more3"></i>
</div>
<el-dropdown-menu slot="dropdown" class="right-box-select-top right-public-box-dropdown-top">
<!-- <el-dropdown-item v-if="!endpointTab" :command="['endpointQuery', scope.row]"><i class="nz-icon nz-icon-search"></i><span class="operation-dropdown-text">{{$t('overall.query')}}</span></el-dropdown-item>-->
<el-dropdown-item v-if="!endpointTab" v-has="'monitor_endpoint_edit'" :command="['edit', scope.row]"><i class="nz-icon nz-icon-edit"></i><span class="operation-dropdown-text">{{$t('overall.edit')}}</span></el-dropdown-item>
<el-dropdown-item v-has="'monitor_endpoint_delete'" :command="['delete', scope.row, `sys/endpoint?ids=${scope.row.id}`]"><i class="nz-icon nz-icon-delete"></i><span class="operation-dropdown-text">{{$t('overall.delete')}}</span></el-dropdown-item>
<el-dropdown-item v-has="'monitor_endpoint_edit'" :command="['copy', scope.row, 'project']"><i class="nz-icon nz-icon-override"></i><span class="operation-dropdown-text">{{$t('overall.duplicate')}}</span></el-dropdown-item>
<el-dropdown-item v-has="'alertSilence_add'" :command="['fastSilence', scope.row, 'endpoint']"><i class="nz-icon nz-icon-fast-silence"></i><span class="operation-dropdown-text">{{$t('overall.silenceAlert')}}</span></el-dropdown-item>
2022-03-18 18:21:43 +08:00
<el-dropdown-item v-has="'asset_add'" :command="['topology', scope.row, 'endpoint']"><i class="nz-icon nz-icon-Topology"></i><span class="operation-dropdown-text">{{$t('overall.topology')}}</span></el-dropdown-item>
</el-dropdown-menu>
</el-dropdown>
</div>
</el-table-column>
<template slot="empty">
<div v-if="!loading" class="table-no-data">
<svg class="icon" aria-hidden="true">
<use xlink:href="#nz-icon-no-data-list"></use>
</svg>
<div class="table-no-data__title">No results found</div>
</div>
<div v-else>&nbsp;</div>
2021-04-14 18:55:01 +08:00
</template>
</el-table>
<alertLabel
v-if="alertLabelShow"
:id="alertLabelId"
:that="alertLabelObj"
:type="alertLabelType"
></alertLabel>
</div>
2021-04-14 18:55:01 +08:00
</template>
<script>
import table from '@/components/common/mixin/table'
2021-08-10 09:30:12 +08:00
import alertLabel from '../../alert/alertLabel'
import nzTooltip from '../../alert/nzTooltip'
import alertLabelMixin from '@/components/common/mixin/alertLabelMixin'
2021-04-14 18:55:01 +08:00
export default {
name: 'endpointTable',
2021-08-10 09:30:12 +08:00
components: {
alertLabel,
nzTooltip
2021-08-10 09:30:12 +08:00
},
mixins: [table, alertLabelMixin],
props: {
showOption: {
type: Boolean,
default: true
},
isTopoInfo: {
type: Boolean,
default: false
},
2021-10-22 17:47:42 +08:00
endpointTab: Boolean,
loading: Boolean
},
2021-04-14 18:55:01 +08:00
data () {
return {
2022-02-25 14:31:36 +08:00
needAlertDaysData: true,
trendKey: 'endpointId',
2021-04-14 18:55:01 +08:00
tableTitle: [ // 原始table列
{
label: 'ID',
prop: 'id',
show: true,
2021-05-08 09:40:53 +08:00
width: 80,
2021-05-13 11:40:22 +08:00
sortable: 'custom'
2021-04-14 18:55:01 +08:00
}, {
label: this.$t('overall.name'),
2021-04-14 18:55:01 +08:00
prop: 'name',
2021-05-08 09:40:53 +08:00
show: true,
2021-07-22 10:00:29 +08:00
minWidth: 200,
2021-05-13 11:40:22 +08:00
sortable: 'custom'
2021-04-14 18:55:01 +08:00
}, {
label: this.$t('project.project.projectName'),
2021-04-14 18:55:01 +08:00
prop: 'project',
2021-05-08 09:40:53 +08:00
show: true,
minWidth: 100,
sortable: 'custom'
2021-04-14 18:55:01 +08:00
},
{
2022-06-21 11:29:55 +08:00
label: this.$t('asset.asset'),
prop: 'asset',
2021-05-08 09:40:53 +08:00
show: true,
minWidth: 90,
2021-05-13 11:40:22 +08:00
sortable: 'custom'
},
2021-04-14 18:55:01 +08:00
{
2022-07-12 14:06:14 +08:00
label: this.$t('overall.module'),
2021-04-16 17:36:00 +08:00
prop: 'module',
show: true
2021-04-14 18:55:01 +08:00
},
{
2022-07-12 14:06:14 +08:00
label: this.$t('overall.config'),
2021-04-16 17:36:00 +08:00
prop: 'configs',
minWidth: 150,
show: false
},
{
label: this.$t('overall.alert'),
prop: 'alerts',
2021-05-08 09:40:53 +08:00
show: true,
Width: 120,
2021-05-13 11:40:22 +08:00
sortable: 'custom'
2021-04-16 17:36:00 +08:00
},
{
label: this.$t('overall.state'),
2021-04-16 17:36:00 +08:00
prop: 'state',
2021-05-08 09:40:53 +08:00
show: true,
2021-11-25 20:17:04 +08:00
minWidth: 200
2021-04-14 18:55:01 +08:00
}
// {
// label: this.$t('project.endpoint.status'),
// prop: 'enabled',
// show: false
// }
2021-04-14 18:55:01 +08:00
]
}
},
methods: {
2021-08-10 09:30:12 +08:00
copyValue (item) {
const str = item
const domUrl = document.createElement('input')
2021-08-05 14:50:29 +08:00
domUrl.value = JSON.stringify(str)
domUrl.id = 'creatDom'
document.body.appendChild(domUrl)
domUrl.select() // 选择对象
document.execCommand('Copy') // 执行浏览器复制命令
const creatDom = document.getElementById('creatDom')
creatDom.parentNode.removeChild(creatDom)
this.$message.success(this.$t('overall.copySuccess'))
},
suspendedStr (status) { // 10进制转为2进制 分别给对应的状态
2021-04-27 19:24:26 +08:00
if (!status || status === 1 || status == 0) { return '' }
const arr = status.toString(2).split('')
while (arr.length < 4) {
arr.unshift('0')
}
arr.pop()
let str = ''
arr.forEach((item, index) => {
if (index === 0) {
str += `<div><div class="active-icon inline-block ${item == '0' ? 'gray-bg' : 'green-bg'}"></div> DC</div>`
}
if (index === 1) {
str += `<div><div class="active-icon inline-block ${item == '0' ? 'gray-bg' : 'green-bg'}"></div> ASSET</div>`
}
if (index === 2) {
str += `<div><div class="active-icon inline-block ${item == '0' ? 'gray-bg' : 'green-bg'}"></div> ENDPOINT</div>`
}
// if (index === 3) {
// str += `<div>PROMETHEUS <div class="active-icon inline-block ${item == '0' ? 'red-bg' : 'green-bg'}"></div></div>`
// }
})
return str
2021-08-10 09:30:12 +08:00
},
// label 鼠标划入
labelHover1 (item, type, loading, e, slow) {
2021-08-10 09:30:12 +08:00
if (e) {
const dom = e.currentTarget
const position = dom.getBoundingClientRect()
this.$set(item[type], 'position', position)
}
if (slow) {
item[type].timeout = setTimeout(() => {
this.$set(item[type], 'loading', loading)
}, 200)
} else {
2021-11-11 16:46:54 +08:00
if (item[type].timeout) {
clearTimeout(item[type].timeout)
item[type].timeout = null
}
this.$set(item[type], 'loading', loading)
}
// this.$set(this.tableData,index,item);// 调用父组件
},
labelHoverConfigs (item, type, loading, e, slow) {
if (e) {
const dom = e.currentTarget
const position = dom.getBoundingClientRect()
this.$set(item.configs[type], 'position', position)
}
if (slow) {
item.configs[type].timeout = setTimeout(() => {
this.$set(item.configs[type], 'loading', loading)
}, 200)
} else {
this.$set(item.configs[type], 'loading', loading)
}
2021-08-10 09:30:12 +08:00
// this.$set(this.tableData,index,item);// 调用父组件
},
clConfigs (item) {
const str = []
if (item.configs[0].enable) {
str.push(item.configs[0])
}
if (item.configs[1].enable) {
str.push(item.configs[1])
}
return str
}
2021-04-14 18:55:01 +08:00
},
computed: {}
2021-04-14 18:55:01 +08:00
}
</script>
2021-04-16 17:36:00 +08:00
<style scoped>
.bagEF7458{
background: #EF7458;
color: #fff;
}
.bag23BF9A{
background: #23BF9A;
color: #fff;
}
.configs-endpoint{
border-radius: 4px;
padding: 2px 7px;
color: #3C92F1;
position: relative;
display: inline-block;
cursor: pointer;
}
2021-08-05 14:50:29 +08:00
.configs-endpoint.metrics{
color: #3C92F1;
}
.configs-endpoint.logs{
color: #25BF9A;
}
.colorEF7458{
color: #EF7458;
}
.color23BF9A{
color: #23BF9A;
}
.inline-block{
display: inline-block;
}
2021-08-10 09:30:12 +08:00
.pointer{
cursor: pointer;
}
.endpoint-cell-left{
margin-right: 5px;
}
.copy-value-content{
position: absolute;
2021-11-11 17:12:15 +08:00
right: 8px;
top: 4px;
}
.copy-value-content__pre {
height: 200px;
margin-top: 20px;
overflow-y: auto;
overflow-x: hidden;
2021-04-16 17:36:00 +08:00
}
</style>