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/bottomBox/tabs/terminalLogCMDTab.vue

255 lines
6.4 KiB
Vue
Raw Normal View History

2021-02-20 18:51:51 +08:00
<template>
<nz-bottom-data-list
:layout="[]"
:tabs="tabs"
@changeTab="changeTab"
:title="'Session ID'"
>
<template v-slot:title><span :title="obj.uuid.substring(0, 8).toUpperCase()">{{obj.uuid.substring(0, 8).toUpperCase()}}</span></template>
<template v-slot>
<div class="record-container">
<div class="record-container--record-tip">
<span class="record--title">{{$t('config.terminallog.cmd.legendTip')}}:</span>
<span class="detail--cmd"><span class="detail--cmd__red"><i class="nz-icon nz-icon-jinggao" style="color: #f35844; margin-right: 8px"></i>{{$t("config.terminallog.cmd.dangerTip")}}</span></span>
2021-02-20 18:51:51 +08:00
</div>
<div class="record-container--record">
<div class="record--title">{{$t('config.terminallog.cmd.history')}}</div>
<div class="record--list">
<template v-for="record in records">
<template v-for="(item, index) in record.list">
<div :key="index" class="detail--time"><span>{{calcTime(item.time)}}</span></div>
<div :key="index" class="detail--cmd"><span :class="matchBgColor(item.cmd)">{{item.cmd}}</span></div>
</template>
</template>
</div>
<div :style="{visibility: hasNext ? 'visible' : 'hidden'}" class="record--more">
<span class="more-btn" @click="loadMore"><i class="nz-icon nz-icon-drop-down"></i></span>
</div>
2021-02-20 18:51:51 +08:00
</div>
</div>
</template>
</nz-bottom-data-list>
2021-02-20 18:51:51 +08:00
</template>
<script>
import dataListMixin from '@/components/common/mixin/dataList'
import subDataListMixin from '@/components/common/mixin/subDataList'
import nzBottomDataList from '@/components/common/bottomBox/nzBottomDataList'
2021-03-19 18:52:19 +08:00
export default {
name: 'terminalLogRecordTab',
mixins: [dataListMixin, subDataListMixin],
2021-03-19 18:52:19 +08:00
components: {
nzBottomDataList
2021-03-19 18:52:19 +08:00
},
computed: {
calcTime () {
return function (time) {
if (this.obj.startTime) {
const startTime = new Date(this.obj.startTime).getTime()
if (startTime) {
const thisTime = startTime + time
return this.dateFormat(thisTime)
2021-02-20 18:51:51 +08:00
}
}
2021-03-19 18:52:19 +08:00
return '-'
}
},
matchBgColor () {
return function (cmd) {
let className = ''
const dangerCmd = this.$CONSTANTS.terminalLog.dangerCmd
const infoCmd = this.$CONSTANTS.terminalLog.infoCmd
const cmdSplit = cmd.split(' ')
if (this.intersection(infoCmd, cmdSplit).length > 0) {
className = 'detail--cmd__green'
2021-02-20 18:51:51 +08:00
}
2021-03-19 18:52:19 +08:00
if (this.intersection(dangerCmd, cmdSplit).length > 0) {
className = 'detail--cmd__red'
2021-02-20 18:51:51 +08:00
}
2021-03-19 18:52:19 +08:00
return className
2021-02-20 18:51:51 +08:00
}
},
2021-03-19 18:52:19 +08:00
hasNext () {
if (this.records.length > 0) {
return this.records[this.records.length - 1].hasNext
2021-02-20 18:51:51 +08:00
}
2021-03-19 18:52:19 +08:00
return false
}
},
data () {
return {
filter: {
uuid: '',
cmd: '',
time: '',
size: 200
2021-02-20 18:51:51 +08:00
},
2021-03-19 18:52:19 +08:00
records: [ // 加载更多时有多个record否则只有一个
2021-02-20 18:51:51 +08:00
2021-03-19 18:52:19 +08:00
]
}
},
methods: {
initData (filter) {
this.$get('/terminal/cmd', filter).then(res => {
if (res.code === 200) {
this.records.push(res.data)
} else {
this.$message.error(res.msg)
2021-02-20 18:51:51 +08:00
}
2021-03-19 18:52:19 +08:00
})
},
loadMore () {
const filter = Object.assign({}, this.filter)
filter.time = this.records[this.records.length - 1].time
this.initData(filter)
},
// 切换tab
changeTab (tab) {
this.$emit('changeTab', tab)
2021-02-20 18:51:51 +08:00
},
2021-03-19 18:52:19 +08:00
intersection (a, b) {
const s = new Set(b)
return a.filter(x => s.has(x))
},
dateFormat (time) {
if (!time) {
return '-'
}
const date = new Date(time)
const year = date.getFullYear()
const month = date.getMonth() + 1 < 10 ? '0' + (date.getMonth() + 1) : date.getMonth() + 1
const day = date.getDate() < 10 ? '0' + date.getDate() : date.getDate()
const hours = date.getHours() < 10 ? '0' + date.getHours() : date.getHours()
const minutes = date.getMinutes() < 10 ? '0' + date.getMinutes() : date.getMinutes()
const seconds = date.getSeconds() < 10 ? '0' + date.getSeconds() : date.getSeconds()
return year + '-' + month + '-' + day + ' ' + hours + ':' + minutes + ':' + seconds
},
formatUpdateTime (date) {
const time = new Date(date)
const hours = time.getHours() > 9 ? time.getHours() : '0' + time.getHours()
const minutes = time.getMinutes() > 9 ? time.getMinutes() : '0' + time.getMinutes()
return hours + ':' + minutes
}
},
watch: {
obj: {
immediate: true,
deep: true,
handler (n) {
this.records = []
this.filter.uuid = n.uuid
this.initData(this.filter)
}
}
2021-02-20 18:51:51 +08:00
}
2021-03-19 18:52:19 +08:00
}
2021-02-20 18:51:51 +08:00
</script>
<style lang="scss">
.record-container {
height: calc(100% - 50px);
overflow: auto;
position: relative;
}
.record-container--record {
background-color: white;
width: calc(100% - 6px);
padding: 16px 15px 6px 15px;
border: 1px solid #d8dce1;
box-sizing: border-box;
min-height: 100px;
.record--title {
color: #333;
font-size: 14px;
font-weight: bold;
margin-bottom: 12px;
}
.record--list {
display: grid;
gap: 6px 12px;
grid-template-columns: 150px auto;
font-size: 14px;
color: #333;
.detail--time {
line-height: 22px;
grid-column: 1/span 1;
display: flex;
font-size: 12px;
align-items: flex-start;
span {
background-color: #ECECEC;
padding: 2px 10px;
}
}
.detail--cmd {
line-height: 22px;
grid-column: 2/span 1;
display: flex;
span {
padding: 2px 10px;
}
}
.detail--cmd__green {
background-color: #B4FDB1;
}
.detail--cmd__red {
background-color: #FFD2C2;
}
}
.record--more {
text-align: center;
margin-top: 15px;
.more-btn {
color: #999;
cursor: pointer;
.nz-icon {
font-size: 14px;
}
}
}
}
.record-container--record-tip {
position: absolute;
right: 20px;
top: 17px;
.record--title {
color: #333;
font-size: 14px;
font-weight: bold;
margin-bottom: 12px;
}
.detail--cmd {
line-height: 22px;
font-size: 14px;
padding-left: 20px;
span {
padding: 3px 10px;
}
}
.detail--cmd__green {
background-color: #A7F29E;
}
.detail--cmd__red {
background-color: #FBe2DE;
}
}
</style>