2022-01-14 09:17:53 +08:00
|
|
|
|
<template>
|
2022-01-14 19:54:37 +08:00
|
|
|
|
<div class="scrape-endpoint">
|
2022-01-14 09:17:53 +08:00
|
|
|
|
<nz-bottom-data-list
|
|
|
|
|
|
:showTitle='showTitle'
|
|
|
|
|
|
:obj='obj'
|
|
|
|
|
|
:targetTab.sync="targetTab"
|
|
|
|
|
|
:api="url"
|
|
|
|
|
|
style="height: 100%"
|
|
|
|
|
|
:custom-table-title.sync="tools.customTableTitle"
|
|
|
|
|
|
:layout="['elementSet']"
|
|
|
|
|
|
:tabs="tabs"
|
|
|
|
|
|
@changeTab="changeTab"
|
|
|
|
|
|
>
|
2022-02-17 15:07:24 +08:00
|
|
|
|
<template v-slot:title><span :title="obj.name || obj.dc.name">{{obj.name || obj.dc.name}}</span></template>
|
2022-01-14 09:17:53 +08:00
|
|
|
|
<template v-slot:top-tool-right>
|
|
|
|
|
|
<div class="top-tool-right">
|
|
|
|
|
|
<div style="margin-right: 15px;">
|
2022-01-14 19:54:37 +08:00
|
|
|
|
<el-input size="small" ref="inputDate" v-model="inputDateSearch" @clear="clearInput" id="inputDate" class="input-with" @focus="focus" @blur="blur">
|
|
|
|
|
|
<el-button slot="append" icon="el-icon-search" @click="focus"></el-button>
|
2022-01-14 09:17:53 +08:00
|
|
|
|
</el-input>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
</template>
|
|
|
|
|
|
<template v-slot>
|
|
|
|
|
|
<scrape-endpoint-table
|
|
|
|
|
|
ref="dataTable"
|
2022-03-09 14:26:11 +08:00
|
|
|
|
:orderByFa="'id'"
|
2022-01-14 09:17:53 +08:00
|
|
|
|
v-loading="tools.loading"
|
|
|
|
|
|
:loading="tools.loading"
|
|
|
|
|
|
:api="url"
|
|
|
|
|
|
:custom-table-title="tools.customTableTitle"
|
|
|
|
|
|
:height="mainTableHeight"
|
|
|
|
|
|
:table-data="tableData"
|
|
|
|
|
|
:currentTableData="currentTableData"
|
2022-01-14 19:54:37 +08:00
|
|
|
|
:inputDateSearch="inputDateSearch"
|
2022-01-14 09:17:53 +08:00
|
|
|
|
@orderBy="tableDataSort"
|
|
|
|
|
|
@reload="getTableData"
|
|
|
|
|
|
@selectionChange="selectionChange"
|
|
|
|
|
|
></scrape-endpoint-table>
|
|
|
|
|
|
</template>
|
|
|
|
|
|
<template v-slot:pagination>
|
|
|
|
|
|
<Pagination ref="Pagination" :pageObj="pageObj" :tableId="tableId" @pageNo='pageNo' @pageSize='pageSize'></Pagination>
|
|
|
|
|
|
</template>
|
|
|
|
|
|
</nz-bottom-data-list>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
</template>
|
|
|
|
|
|
<script>
|
|
|
|
|
|
import nzBottomDataList from '@/components/common/bottomBox/nzBottomDataList'
|
|
|
|
|
|
import dataListMixin from '@/components/common/mixin/dataList'
|
|
|
|
|
|
import scrapeEndpointTable from '@/components/common/table/settings/scrapeEndpointTable'
|
|
|
|
|
|
import subDataList from '@/components/common/mixin/subDataList'
|
|
|
|
|
|
import detailViewRightMixin from '@/components/common/mixin/detailViewRightMixin'
|
2022-01-14 19:54:37 +08:00
|
|
|
|
import bus from '@/libs/bus'
|
|
|
|
|
|
import { sameLabels } from '@/components/common/js/constants'
|
2022-01-14 09:17:53 +08:00
|
|
|
|
export default {
|
|
|
|
|
|
name: 'scrapeEndpoint',
|
|
|
|
|
|
components: {
|
|
|
|
|
|
nzBottomDataList,
|
|
|
|
|
|
scrapeEndpointTable
|
|
|
|
|
|
},
|
2022-01-14 09:25:54 +08:00
|
|
|
|
mixins: [dataListMixin, subDataList, detailViewRightMixin],
|
2022-01-14 09:17:53 +08:00
|
|
|
|
data () {
|
|
|
|
|
|
return {
|
|
|
|
|
|
url: '/prom/api/v1/targets',
|
|
|
|
|
|
tableId: 'promTargetsTable', // 需要分页的table的id,用于记录每页数量
|
|
|
|
|
|
currentTableData: [],
|
|
|
|
|
|
hideSameLabels: true,
|
2022-01-14 19:54:37 +08:00
|
|
|
|
inputDateSearch: '',
|
2022-01-14 09:17:53 +08:00
|
|
|
|
tableDataCopy: '',
|
|
|
|
|
|
pageObj: {
|
|
|
|
|
|
pageSize: 20,
|
|
|
|
|
|
pageNo: 1,
|
|
|
|
|
|
total: 0
|
2022-01-14 19:54:37 +08:00
|
|
|
|
},
|
|
|
|
|
|
timer: null,
|
|
|
|
|
|
sameLabels: ['endpointLabels', 'labelsType', 'lastScrape', 'lastScrapeDuration', 'health', 'lastError']
|
2022-01-14 09:17:53 +08:00
|
|
|
|
}
|
|
|
|
|
|
},
|
|
|
|
|
|
watch: {
|
2022-01-14 19:54:37 +08:00
|
|
|
|
inputDateSearch (n, o) {
|
2022-01-14 09:17:53 +08:00
|
|
|
|
const temp = this
|
|
|
|
|
|
setTimeout(function () {
|
|
|
|
|
|
temp.tableFilter()
|
|
|
|
|
|
}, 500)
|
2022-01-14 19:54:37 +08:00
|
|
|
|
},
|
|
|
|
|
|
obj: {
|
|
|
|
|
|
immediate: true,
|
|
|
|
|
|
deep: true,
|
|
|
|
|
|
handler (n, o) {
|
|
|
|
|
|
if (n) {
|
|
|
|
|
|
this.inputDateSearch = ''
|
|
|
|
|
|
this.getTableData()
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2022-01-14 09:17:53 +08:00
|
|
|
|
}
|
|
|
|
|
|
},
|
|
|
|
|
|
methods: {
|
2022-01-14 19:54:37 +08:00
|
|
|
|
// input 获取焦点时触发
|
2022-01-14 09:17:53 +08:00
|
|
|
|
focus () {
|
|
|
|
|
|
let classVal = document.getElementById('inputDate').parentElement.getAttribute('class')
|
|
|
|
|
|
classVal = classVal.replace('input-with', 'input-with')
|
|
|
|
|
|
document.getElementById('inputDate').parentElement.setAttribute('class', classVal)
|
|
|
|
|
|
this.$refs.inputDate.focus()
|
|
|
|
|
|
},
|
2022-01-14 19:54:37 +08:00
|
|
|
|
// input 失去焦点时触发
|
2022-01-14 09:17:53 +08:00
|
|
|
|
blur () {
|
2022-01-14 19:54:37 +08:00
|
|
|
|
if (!this.inputDateSearch || this.inputDateSearch == '') {
|
2022-01-14 09:17:53 +08:00
|
|
|
|
setTimeout(function () {
|
|
|
|
|
|
let classVal = document.getElementById('inputDate').parentElement.getAttribute('class')
|
|
|
|
|
|
classVal = classVal.replace('input-with', 'input-with')
|
|
|
|
|
|
document.getElementById('inputDate').parentElement.setAttribute('class', classVal)
|
|
|
|
|
|
}, 100)
|
|
|
|
|
|
}
|
|
|
|
|
|
},
|
2022-01-14 19:54:37 +08:00
|
|
|
|
clearInput () {
|
|
|
|
|
|
this.$refs.inputDate.focus()
|
|
|
|
|
|
},
|
|
|
|
|
|
// 数据请求
|
2022-01-14 09:17:53 +08:00
|
|
|
|
getTableData () {
|
2022-01-14 19:54:37 +08:00
|
|
|
|
this.timer = setTimeout(() => {
|
|
|
|
|
|
this.$set(this.searchLabel, 'dcId', this.obj.dcId)
|
|
|
|
|
|
this.$set(this.searchLabel, 'agentId', this.obj.id)
|
|
|
|
|
|
this.$set(this.searchLabel, 'type', this.obj.type)
|
|
|
|
|
|
this.$get(this.url, { ...this.searchLabel }).then(response => {
|
|
|
|
|
|
this.tools.loading = false
|
|
|
|
|
|
this.tableData = response.data.activeTargets.map(item => {
|
|
|
|
|
|
const buildIn = ['asset', 'endpoint', 'module', 'cpu', 'dc', 'project', 'parent_asset', 'user']
|
|
|
|
|
|
buildIn.forEach(label => {
|
|
|
|
|
|
if (label === 'dc') {
|
|
|
|
|
|
item[label] = {
|
|
|
|
|
|
id: item.labels['datacenter' + '_id'],
|
|
|
|
|
|
position: {},
|
|
|
|
|
|
loading: false
|
|
|
|
|
|
}
|
|
|
|
|
|
} else {
|
|
|
|
|
|
item[label] = {
|
|
|
|
|
|
id: item.labels[label + '_id'],
|
|
|
|
|
|
position: {},
|
|
|
|
|
|
loading: false
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
})
|
|
|
|
|
|
return item
|
2022-01-14 10:04:01 +08:00
|
|
|
|
})
|
2022-01-18 10:06:33 +08:00
|
|
|
|
const globalSearchId = this.$store.getters.getGlobalSearchId
|
|
|
|
|
|
let detailViewRightObj = ''
|
|
|
|
|
|
if (globalSearchId) {
|
|
|
|
|
|
detailViewRightObj = this.tableData.find(item => item.id === globalSearchId)
|
|
|
|
|
|
} else {
|
|
|
|
|
|
detailViewRightObj = this.tableData[0]
|
|
|
|
|
|
}
|
|
|
|
|
|
this.detailViewRightObj = detailViewRightObj
|
2022-01-14 19:54:37 +08:00
|
|
|
|
this.inputDateQuery = this.handlerTableData(this.tableData)
|
|
|
|
|
|
this.pageObj.total = this.tableData.length
|
|
|
|
|
|
if (!this.scrollbarWrap) {
|
|
|
|
|
|
this.$nextTick(() => {
|
|
|
|
|
|
this.handleCurrentChange()
|
|
|
|
|
|
})
|
|
|
|
|
|
}
|
2022-01-14 10:04:01 +08:00
|
|
|
|
})
|
2022-01-14 19:54:37 +08:00
|
|
|
|
}, 500)
|
2022-01-14 09:17:53 +08:00
|
|
|
|
},
|
2022-01-14 19:54:37 +08:00
|
|
|
|
// 搜索字段的处理
|
|
|
|
|
|
handlerTableData (dates) {
|
2022-01-14 09:17:53 +08:00
|
|
|
|
const tableDates = []
|
2022-01-14 19:54:37 +08:00
|
|
|
|
for (const date of dates) {
|
|
|
|
|
|
const endpointLabels = date.discoveredLabels.endpoint || ''
|
|
|
|
|
|
const labelsType = date.labels.type || ''
|
|
|
|
|
|
const lastScrape = bus.timeFormate(date.lastScrape, this.timeFormatMain) || ''
|
|
|
|
|
|
const lastScrapeDuration = date.lastScrapeDuration || ''
|
|
|
|
|
|
const health = date.health || ''
|
|
|
|
|
|
const lastError = date.lastError || ''
|
|
|
|
|
|
const asset = date.asset
|
|
|
|
|
|
const cpu = date.cpu
|
|
|
|
|
|
const dc = date.dc
|
|
|
|
|
|
const endpoint = date.endpoint
|
|
|
|
|
|
const module = date.module
|
|
|
|
|
|
const parent_asset = date.parent_asset
|
|
|
|
|
|
const project = date.project
|
|
|
|
|
|
const user = date.user
|
|
|
|
|
|
const labels = date.labels
|
|
|
|
|
|
const discoveredLabels = date.discoveredLabels
|
|
|
|
|
|
const tableData = {
|
|
|
|
|
|
endpointLabels,
|
|
|
|
|
|
endpoint,
|
|
|
|
|
|
labelsType,
|
|
|
|
|
|
lastScrape,
|
|
|
|
|
|
lastScrapeDuration,
|
|
|
|
|
|
health,
|
|
|
|
|
|
lastError,
|
|
|
|
|
|
asset,
|
|
|
|
|
|
dc,
|
|
|
|
|
|
cpu,
|
|
|
|
|
|
module,
|
|
|
|
|
|
project,
|
|
|
|
|
|
parent_asset,
|
|
|
|
|
|
user,
|
|
|
|
|
|
labels,
|
|
|
|
|
|
discoveredLabels
|
|
|
|
|
|
}
|
|
|
|
|
|
let simpleTemp = ''
|
|
|
|
|
|
const keys = Object.keys(tableData)
|
|
|
|
|
|
for (const index in keys) {
|
|
|
|
|
|
const key = keys[index]
|
|
|
|
|
|
if (this.sameLabels.some((i) => { return i === key })) {
|
|
|
|
|
|
if (tableData[key]) {
|
|
|
|
|
|
simpleTemp += key + tableData[key]
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
if (simpleTemp.indexOf(',') !== -1) {
|
|
|
|
|
|
simpleTemp = simpleTemp.substr(0, simpleTemp.length - 1)
|
|
|
|
|
|
}
|
|
|
|
|
|
tableData.tableDateAll = simpleTemp
|
2022-01-14 09:17:53 +08:00
|
|
|
|
tableDates.push(tableData)
|
2022-01-14 19:54:37 +08:00
|
|
|
|
}
|
2022-01-14 09:17:53 +08:00
|
|
|
|
return tableDates
|
|
|
|
|
|
},
|
2022-01-14 19:54:37 +08:00
|
|
|
|
// 对字段进行匹配
|
2022-01-14 09:17:53 +08:00
|
|
|
|
tableFilter () {
|
|
|
|
|
|
const temp = this
|
|
|
|
|
|
const tableDatas = this.inputDateQuery
|
|
|
|
|
|
this.tableData = tableDatas.filter((item) => {
|
2022-01-14 19:54:37 +08:00
|
|
|
|
if (item.endpoint) {
|
|
|
|
|
|
const element = temp.hideSameLabels ? item.tableDateAll : item.endpoint
|
|
|
|
|
|
return element.indexOf(this.inputDateSearch) !== -1
|
|
|
|
|
|
}
|
2022-01-14 09:17:53 +08:00
|
|
|
|
})
|
|
|
|
|
|
this.pageObj.pageNo = 1
|
|
|
|
|
|
this.handleCurrentChange()
|
|
|
|
|
|
},
|
|
|
|
|
|
pageNo (val) {
|
|
|
|
|
|
this.pageObj.pageNo = val
|
|
|
|
|
|
this.handleCurrentChange()
|
|
|
|
|
|
},
|
|
|
|
|
|
pageSize (val) {
|
|
|
|
|
|
this.pageObj.pageSize = val
|
|
|
|
|
|
localStorage.setItem('nz-pageSize-' + localStorage.getItem('nz-username') + '-' + this.tableId, val)
|
|
|
|
|
|
this.handleCurrentChange()
|
|
|
|
|
|
},
|
2022-01-14 19:54:37 +08:00
|
|
|
|
// 计算当前分页需要返回数据的条数
|
2022-01-14 09:17:53 +08:00
|
|
|
|
handleCurrentChange () {
|
|
|
|
|
|
this.pageObj.total = this.tableData.length
|
|
|
|
|
|
this.currentTableData = this.tableData.slice(
|
|
|
|
|
|
(this.pageObj.pageNo - 1) * this.pageObj.pageSize,
|
|
|
|
|
|
this.pageObj.pageNo * this.pageObj.pageSize
|
|
|
|
|
|
)
|
|
|
|
|
|
}
|
|
|
|
|
|
},
|
|
|
|
|
|
mounted () {
|
2022-01-14 19:54:37 +08:00
|
|
|
|
},
|
|
|
|
|
|
beforeDestroy () {
|
|
|
|
|
|
// 移除定时器
|
|
|
|
|
|
clearInterval(this.timer)
|
|
|
|
|
|
},
|
|
|
|
|
|
created () {
|
|
|
|
|
|
const pageSize = localStorage.getItem('nz-pageSize-' + localStorage.getItem('nz-username') + '-' + this.tableId)
|
|
|
|
|
|
this.pageObj.pageSize = pageSize || 20
|
2022-01-14 09:17:53 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
</script>
|