Merge branch 'dev-3.9' of git.mesalab.cn:nezha/nezha-fronted into dev-3.9

This commit is contained in:
zyh
2023-10-17 14:06:00 +08:00
12 changed files with 75 additions and 60 deletions

View File

@@ -183,10 +183,13 @@ export default {
if (userInfo) {
this.waterMarkText = `${userInfo.username}(${userInfo.name})`
}
if (!baseUrl.endsWith('/')) {
baseUrl += '/'
}
if (this.terminal.type === 'asset') {
url = baseUrl + '/terminal.ws?width=' + this.terminal.width + '&height=' + this.terminal.height + '&cols=' + this.term.cols + '&rows=' + this.term.rows + '&token=' + token + '&assetId=' + this.terminal.assetId + '&accountId=' + this.terminal.accountId + '&uuid=' + this.terminal.uuid
url = baseUrl + 'terminal.ws?width=' + this.terminal.width + '&height=' + this.terminal.height + '&cols=' + this.term.cols + '&rows=' + this.term.rows + '&token=' + token + '&assetId=' + this.terminal.assetId + '&accountId=' + this.terminal.accountId + '&uuid=' + this.terminal.uuid
} else if (this.terminal.type === 'custom') {
url = baseUrl + '/terminal.ws?width=' + this.terminal.width + '&height=' + this.terminal.height + '&cols=' + this.term.cols + '&rows=' + this.term.rows + '&token=' + token + '&accountId=' + this.terminal.accountId + '&uuid=' + this.terminal.uuid
url = baseUrl + 'terminal.ws?width=' + this.terminal.width + '&height=' + this.terminal.height + '&cols=' + this.term.cols + '&rows=' + this.term.rows + '&token=' + token + '&accountId=' + this.terminal.accountId + '&uuid=' + this.terminal.uuid
Object.keys(this.terminal.custom).forEach(key => {
if (this.terminal.custom[key]) {
url += '&' + key + '=' + this.terminal.custom[key]
@@ -250,8 +253,6 @@ export default {
// 关闭
this.terminalSocket.onclose = () => {
this.terminal.isLogin = false
// 报错sorry的还没来得及看信息就关闭
// this.$emit("closeConsole",this.terminal.name);//
this.term && (this.term.options.disableStdin = true)
}

View File

@@ -82,6 +82,10 @@
<discovery-tab v-if="from === fromRoute.assetDiscovery && targetTab === 'assetDiscoveryTab'" :from="from" :obj="obj" :tabs="tabs.discovery" @changeTab="changeTab" :targetTab.sync="targetTab"></discovery-tab>
<!-- notebook Tab -->
<notebook-tab @getTableData="getTableData" v-if="from === fromRoute.notebook && targetTab === 'notebookTab'" :from="from" :obj="obj" :tabs="tabs.notebook" @changeTab="changeTab" :targetTab.sync="targetTab"></notebook-tab>
<!--softwareAsset列表的tab-->
<endpointTabNew v-if="from === fromRoute.softwareAsset && targetTab === 'endpoint'" v-show="subResizeShow" :from="from" :obj="obj" :tabs="tabs.module.softwareAssetTabTitle" :targetTab="targetTab" @changeTab="changeTab"></endpointTabNew>
<!--model 下滑-->
<asset-tab v-if="(from === fromRoute.softwareType) && targetTab === 'asset'" :tabs="tabs.softwareType" ref="assetTab" :from="from" :obj="obj" @changeTab="changeTab" @exit="closeSubList" :targetTab.sync="targetTab"></asset-tab>
</div>
</div>
</div>
@@ -241,6 +245,11 @@ export default {
{ prop: 'moduleAlertMessage', name: this.$t('overall.alert') }
]
},
softwareAsset: {
softwareAssetTabTitle: [
{ prop: 'endpoint', name: this.$t('asset.endpoint') },
]
},
endpoint: {
endpointTabTitle: [
{ prop: 'dashboardTab', name: this.$t('overall.dashboard') },
@@ -268,6 +277,9 @@ export default {
model: [
{ prop: 'asset', name: this.$t('asset.asset'), active: true }
],
softwareType: [
{ prop: 'asset', name: this.$t('asset.asset'), active: true }
],
dc: {
cabinet: [
{ prop: 'cabinet', name: this.$t('asset.cabinet'), active: true },

View File

@@ -233,6 +233,7 @@ export default {
// this.$store.commit('addConsole', consoleParam)
},
getTableData (params) {
let url = this.url
if (params && Object.keys(params).length > 0) {
for (const key in params) {
this.$set(this.searchLabel, key, params[key])
@@ -249,9 +250,12 @@ export default {
this.$set(this.searchLabel, 'modelIds', this.obj.id)
} else if (this.from === fromRoute.dc) {
this.$set(this.searchLabel, 'dcIds', this.obj.id)
} else if (this.from === fromRoute.softwareType) {
url = '/asset/software'
this.$set(this.searchLabel, 'typeIds', this.obj.id)
}
this.tools.loading = true
this.$get(this.url, { ...this.searchLabel, ...this.searchCheckBox }).then(response => {
this.$get(url, { ...this.searchLabel, ...this.searchCheckBox }).then(response => {
this.tools.loading = false
if (response.code === 200) {
for (let i = 0; i < response.data.list.length; i++) {

View File

@@ -138,6 +138,8 @@ export default {
params.moduleIds = this.obj.id
} else if (this.from === fromRoute.asset) {
params.assetIds = this.obj.id
} else if (this.from === fromRoute.softwareAsset) {
params.softwareAssetIds = this.obj.id
}
this.$get(this.url, params).then(response => {
this.tools.loading = false

View File

@@ -424,6 +424,8 @@ export const fromRoute = {
assetType: 'assetType',
assetState: 'assetState',
assetLabel: 'assetLabel',
softwareAsset: 'softwareAsset',
softwareType: 'softwareType',
assetDiscovery: 'assetDiscovery',
user: 'user',
agent: 'agent',

View File

@@ -92,7 +92,7 @@
<div slot="header" class="table-operation-title">{{$t('overall.option')}}</div>
<div slot-scope="scope" class="table-operation-items">
<!-- <button class="table-operation-item" v-has="'softwareAsset_edit'" @click="$emit('edit', scope.row)" :title="$t('overall.edit')"><i class="nz-icon nz-icon-edit"></i></button> -->
<button class="table-operation-item" @click="showBottomBox('asset', scope.row)" :title="$t('overall.view')"><i class="nz-icon nz-icon-view1"></i></button>
<button class="table-operation-item" @click="showBottomBox('endpoint', scope.row)" :title="$t('overall.view')"><i class="nz-icon nz-icon-view1"></i></button>
<el-dropdown size="medium" v-has="['softwareAsset_delete','main_edit','softwareAsset_edit']" 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>

View File

@@ -4,7 +4,7 @@
ref="dataList"
:api="url"
:custom-table-title.sync="tools.customTableTitle"
:from="fromRoute.model"
:from="fromRoute.softwareAsset"
:layout="['searchInput', 'elementSet', 'pagination']"
:search-msg="searchMsg"
@search="search"

View File

@@ -4,7 +4,7 @@
ref="dataList"
:api="url"
:custom-table-title.sync="tools.customTableTitle"
:from="fromRoute.model"
:from="fromRoute.softwareType"
:layout="['searchInput', 'elementSet', 'pagination']"
:search-msg="searchMsg"
@search="search"

View File

@@ -1,7 +1,7 @@
<template>
<div class="explores">
<explore-item
v-for="item in exploreItems"
v-for="(item, index) in exploreItems"
ref="exploreItem"
:key="item"
:closable="closable"

View File

@@ -224,12 +224,12 @@
<el-collapse v-show="!showIntroduce" v-model="collapseValue" class="explore-collapse" @change="logsCollapseChange">
<!--metric-->
<template v-if="showMetrics">
<el-collapse-item v-if="!allMatrix" name="1" :title="$t('explore.graph')" class="el-collapse-item__height">
<el-collapse-item v-if="!allMatrix && showChart" name="1" :title="$t('explore.graph')" class="el-collapse-item__height">
<div class="chart-room">
<chart ref="exploreChart" :unit="chartUnit" :timeRange="filterTime"></chart>
</div>
</el-collapse-item>
<el-collapse-item class="el-collapse-item__height" name="2" title="Table">
<el-collapse-item class="el-collapse-item__height" name="2" title="Table" v-if="showTable">
<div slot="title" class="explore-table-title">
<span>{{tableMode==='table'?$t('dashboard.dashboard.chartForm.typeVal.table.label'):$t('explore.row')}}</span>
<!-- 判断是否折叠 -->
@@ -3731,7 +3731,9 @@ export default {
rowData: [],
metricsHistory: [],
logsHistory: [],
lastHistory: []
lastHistory: [],
showChart: false,
showTable: false,
}
},
async created () {
@@ -4041,7 +4043,7 @@ export default {
// 过滤掉state为0的元素
let step = bus.getStep(bus.formateTimeToTime(this.filterTime[0]), bus.formateTimeToTime(this.filterTime[1]))
this.expressions.forEach((item, index) => {
if (item != '' && this.promqlKeys[index].state && !this.promqlKeys[index].matrix) {
if (item != '' && this.promqlKeys[index].state && !this.promqlKeys[index].matrix && this.promqlKeys[index].queryType == 1) {
let queryStep = step
if (this.promqlKeys[index].step) {
queryStep = this.promqlKeys[index].step + 's'
@@ -4051,6 +4053,7 @@ export default {
if (this.promqlKeys[index].queryType === 2) {
requestArr.push(this.$get('/prom/api/v1/query_instant?query=' + encodeURIComponent(item) + '&time=' + this.$stringTimeParseToUnix(bus.formateTimeToTime(this.filterTime[1]))))
} else {
this.showChart = true
requestArr.push(this.$get('/prom/api/v1/query_range?query=' + encodeURIComponent(item) + '&start=' + this.$stringTimeParseToUnix(bus.formateTimeToTime(this.filterTime[0])) + '&end=' + this.$stringTimeParseToUnix(bus.formateTimeToTime(this.filterTime[1])) + '&step=' + queryStep + '&nullType=null'))
}
}
@@ -4132,13 +4135,13 @@ export default {
}
}
})
this.$refs.exploreChart.setLegend(legend)
this.$refs.exploreChart.setRandomColors(series.length)
this.series = series
this.$refs.exploreChart?.setLegend(legend)
this.$refs.exploreChart?.setRandomColors(series.length)
if (!series.length) {
series = ''
}
this.$refs.exploreChart.setSeries(series)
this.$refs.exploreChart?.setSeries(series)
this.defaultChartVisible = true
}
this.$refs.exploreChart && this.$refs.exploreChart.endLoading()
@@ -4146,13 +4149,17 @@ export default {
}
},
async queryTableData () {
console.log(this.expressions)
this.tools.loading = true
if (this.expressions.length > 0) {
const requestArr = []
this.expressions.forEach((item, index) => {
// 过滤掉state为0的元素
if (item !== '' && this.promqlKeys[index].state) {
requestArr.push(this.$get('/prom/api/v1/query?query=' + encodeURIComponent(item)))
console.log(this.promqlKeys[index].queryType)
if (item !== '' && this.promqlKeys[index].state && this.promqlKeys[index].queryType == 2) {
// requestArr.push(this.$get('/prom/api/v1/query?query=' + encodeURIComponent(item)))
this.showTable = true
requestArr.push(this.$get('/prom/api/v1/query_instant?query=' + encodeURIComponent(item) + '&time=' + this.$stringTimeParseToUnix(bus.formateTimeToTime(this.filterTime[1]))))
}
})
if (requestArr.length > 0) {
@@ -4168,7 +4175,7 @@ export default {
this.tableTitle = []
this.tools.customTableTitle = []
this.allMatrix = res.every(d => d.data.resultType === 'matrix')
// this.allMatrix = res.every(d => d.data.resultType === 'matrix')
res.forEach((response, index) => {
if (response.data && response.status === 'success') {
@@ -4176,21 +4183,10 @@ export default {
this.promqlKeys[index].matrix = response.data.resultType === 'matrix'
let data = response.data.result
if (data) {
if (data.length && !Array.isArray(data[0].value) && response.data.resultType !== 'matrix') {
data = [{
metric: {},
value: data
}]
}
data.forEach((result, i) => {
const metrics = Object.assign({}, result.metric)
if (response.data.resultType === 'matrix') {
this.$set(metrics, 'value#' + index, chartDataFormat.getUnit(this.chartUnit || 2).compute(result.values[0][1], null, 2))
this.$set(metrics, 'time', bus.timeFormate(bus.computeTimezone(result.values[0][0] * 1000)))
} else {
this.$set(metrics, 'value#' + index, chartDataFormat.getUnit(this.chartUnit || 2).compute(result.value[1], null, 2))
this.$set(metrics, 'time', bus.timeFormate(bus.computeTimezone(result.value[0] * 1000)))
}
this.$set(metrics, 'value#' + index, chartDataFormat.getUnit(this.chartUnit || 2).compute(result.values[0][1], null, 2))
this.$set(metrics, 'time', bus.timeFormate(bus.computeTimezone(result.values[0][0] * 1000)))
for (const key in metrics) {
const label = {
label: key,
@@ -4204,37 +4200,28 @@ export default {
tLabels.push(label)
}
}
if (response.data.resultType === 'matrix') {
result.values.forEach(item => {
tData.push({
...metrics,
['value#' + index]: chartDataFormat.getUnit(this.chartUnit || 2).compute(item[1], null, 2),
time: bus.timeFormate(bus.computeTimezone(result.values[0][0] * 1000))
})
result.values.forEach(item => {
tData.push({
...metrics,
['value#' + index]: chartDataFormat.getUnit(this.chartUnit || 2).compute(item[1], null, 2),
time: bus.timeFormate(bus.computeTimezone(result.values[0][0] * 1000))
})
} else {
tData.push(metrics)
}
})
// 处理row模式数据
const rowData = this.handlerRowData(result.metric)
rowData.value = metrics['value#' + index]
// matrix 类型数据
if (response.data.resultType === 'matrix') {
rowData.valueList = result.values.map((item, index) => {
const obj = {}
obj.value = chartDataFormat.getUnit(this.chartUnit || 2).compute(item[1], null, 2)
obj.timestamp = '@' + item[0]
obj.time = bus.timeFormate(bus.computeTimezone(item[0] * 1000))
if (index) { // 与前一个数据间隔
obj.interval = '+' + parseInt(item[0] - result.values[index - 1][0]).toString()
}
return obj
})
} else {
rowData.timestamp = '@' + result.value[0]
rowData.time = bus.timeFormate(bus.computeTimezone(result.value[0] * 1000))
}
rowData.valueList = result.values.map((item, index) => {
const obj = {}
obj.value = chartDataFormat.getUnit(this.chartUnit || 2).compute(item[1], null, 2)
obj.timestamp = '@' + item[0]
obj.time = bus.timeFormate(bus.computeTimezone(item[0] * 1000))
if (index) { // 与前一个数据间隔
obj.interval = '+' + parseInt(item[0] - result.values[index - 1][0]).toString()
}
return obj
})
this.rowData.push(rowData)
})
}
@@ -4375,6 +4362,8 @@ export default {
if (error) { return }
if (this.showMetrics) {
this.$refs.exploreChart && this.$refs.exploreChart.startLoading()
this.showChart = false
this.showTable = false
await this.queryTableData()
this.queryChartData()
this.storeHistory()

View File

@@ -328,7 +328,8 @@ export default {
this.expressions.forEach((expr, i) => {
if (this.expressionsShow[i]) {
this.promqlKeys.push({
id: this.expressionsShow[i].elementId,
elementId: this.expressionsShow[i].elementId,
id: this.expressionsShow[i].id,
expression: expr,
type: 'expert',
legend: this.expressionsShow[i].legend,

View File

@@ -249,8 +249,12 @@ export default {
mounted () {
},
methods: {
closeRightBox () {
closeRightBox (refresh) {
this.rightBox.show = false
if (refresh) {
const findItem = this.tableData.find(item=> item.ip === this.object.manageIp)
findItem.imported = 1
}
},
async uploadAsset (row) {
this.object = this.newObject()