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/asset/assetTable.vue

257 lines
10 KiB
Vue
Raw Normal View History

<template>
<el-table
id="roleTable"
ref="dataTable"
:data="tableData"
:height="height"
border
@header-dragend="dragend"
@sort-change="tableDataSort"
@selection-change="selectionChange"
2021-05-25 15:37:33 +08:00
@row-dblclick="(row)=>{$emit('showBottomBox', 'panelTab', row)}"
>
<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>
</template>
<template slot-scope="scope" :column="item">
<template v-if="item.prop === 'type'">{{scope.row.type ? scope.row.type.name : '-'}}</template>
<template v-else-if="item.prop === 'state'">{{scope.row.state ? scope.row.state.name : '-'}}</template>
<template v-else-if="item.prop === 'endpointNum'">
<span style="cursor: pointer" @click="$emit('showBottomBox', 'endpointTab', scope.row)"><i class="nz-icon nz-icon-overview-endpoint monitorColor"></i> <span>{{scope.row.endpointNum ? scope.row.endpointNum : 0}}</span></span>
2021-04-26 21:42:15 +08:00
<!-- <div :class="messageStyle(item, scope.row)" @mouseenter="showTableTooltip(`${$t('asset.down')} / ${$t('asset.suspended')} / ${$t('asset.total')}`, true, $event)" @mouseleave="hideTableTooltip">
<span class="link" style="padding: 2px 8px" @click="showEndpoint(scope.row)">{{scope.row.endpointDownNum}}/{{scope.row.endpointSuspendedNum}}/{{scope.row.endpointNum}}</span>
2021-04-26 21:42:15 +08:00
</div>-->
</template>
<template v-else-if="item.prop === 'alertNum'">
<span style="cursor: pointer" @click="$emit('showBottomBox', 'alertMessageTab', scope.row)"><i :class="scope.row.alertNum ? 'red' : 'green'" class="nz-icon nz-icon-overview-alert"></i> <span>{{scope.row.alertNum ? scope.row.alertNum : 0}}</span></span>
</template>
<template v-else-if="item.prop === 'dc'">{{scope.row.dc ? scope.row.dc.name : '-'}}</template>
<template v-else-if="item.prop === 'cabinet'">
<span v-if="scope.row.cabinet && scope.row.cabinet !== '--'">{{scope.row.cabinet.name}}&nbsp;{{returnCabinet( scope.row.cabinetStart, scope.row.cabinetEnd)}}</span>
<span v-else >--</span>
</template>
2021-05-13 11:40:22 +08:00
<template v-else-if="item.prop == 'pingInfo'">
<div @mouseenter="showTableTooltip( formatPingTime(scope.row.pingInfo.lastUpdate), true, $event)" @mouseleave="hideTableTooltip" v-if="scope.row.pingInfo">
2021-05-13 11:40:22 +08:00
<div :class="{'active-icon green-bg':scope.row.pingInfo.status == 1,'active-icon red-bg':scope.row.pingInfo.status == 0}"></div><span>{{scope.row.pingInfo.rtt?scope.row.pingInfo.rtt+'ms':''}}</span>
</div>
</template>
<template v-else-if="item.prop === 'model'">{{scope.row.model ? scope.row.model.name : '-'}}</template>
<template v-else-if="item.prop === 'parent'">{{scope.row.parent ? scope.row.parent.name : '-'}}</template>
<template v-else-if="item.prop === 'brand'">{{scope.row.brand ? scope.row.brand.name : '-'}}</template>
<template v-else-if="item.prop === 'purchaseDate'">{{scope.row.purchaseDate ? scope.row.purchaseDate : '--'}}</template>
2021-06-02 16:55:17 +08:00
<template v-else>
<span v-if="scope.row.fields&&scope.row.fields.find(field => field.name === item.prop)">
{{scope.row.fields.find(field => field.name === item.prop).value.join(',')}}
</span>
<span v-else>
{{scope.row[item.prop]}}
</span>
</template>
</template>
</el-table-column>
<el-table-column
:resizable="false"
v-if="showOption"
:width="operationWidth"
fixed="right">
<div slot="header" class="table-operation-title">{{$t('overall.option')}}</div>
<div slot-scope="scope" class="table-operation-items">
2021-04-26 21:42:15 +08:00
<button class="table-operation-item" @click="$emit('showBottomBox', 'panelTab', scope.row)"><i class="nz-icon nz-icon-view1"></i></button>
2021-05-19 14:26:09 +08:00
<el-dropdown size="medium" v-has="['asset_edit','asset_connect','asset_add','asset_delete']" trigger="hover" @command="tableOperation">
<div class="table-operation-item table-operation-item--more">
2021-05-27 13:53:42 +08:00
<i class="nz-icon nz-icon-more3"></i>
</div>
<el-dropdown-menu slot="dropdown">
<el-dropdown-item v-has="'asset_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>
2021-05-24 10:12:01 +08:00
<el-dropdown-item v-has="'asset_connect'" :command="['cli', scope.row]" :disabled="!scope.row.authUsername"><i class="nz-icon nz-icon-cli"></i><span class="operation-dropdown-text">{{$t('dashboard.connect')}}</span></el-dropdown-item>
<el-dropdown-item v-has="'asset_add'" :command="['duplicate', scope.row]"><i class="nz-icon nz-icon-override"></i><span class="operation-dropdown-text">{{$t('dashboard.duplicate')}}</span></el-dropdown-item>
<el-dropdown-item v-has="'asset_delete'" :command="['delete', scope.row]"><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="'alertSilence_add'" :command="['fastSilence', scope.row, 'asset']"><i class="nz-icon nz-icon-fast-silence"></i><span class="operation-dropdown-text">{{$t('overall.silenceAlert')}}</span></el-dropdown-item>
</el-dropdown-menu>
</el-dropdown>
</div>
</el-table-column>
</el-table>
</template>
<script>
import table from '@/components/common/mixin/table'
import { showTableTooltip, hideTableTooltip } from '@/components/common/js/tools'
2021-05-13 11:40:22 +08:00
import bus from '@/libs/bus'
export default {
name: 'assetTable',
mixins: [table],
props: {
showOption: {
type: Boolean,
default: true
}
},
data () {
return {
tableTitle: [
{
2021-04-26 21:42:15 +08:00
label: 'ID',
prop: 'id',
2021-04-26 21:42:15 +08:00
show: true,
width: 110,
sortable: 'custom'
}, {
label: this.$t('overall.name'),
prop: 'name',
show: true,
minWidth: 150,
sortable: 'custom'
2021-04-26 21:42:15 +08:00
}, {
label: this.$t('asset.manageIp'),
prop: 'manageIp',
show: true,
2021-05-13 11:40:22 +08:00
width: 140,
sortable: 'custom'
}, {
label: this.$t('overall.parent'),
prop: 'parent',
2021-04-26 21:42:15 +08:00
show: false,
width: 110
}, {
label: this.$t('overall.type'),
prop: 'type',
show: true,
width: 140,
sortable: 'custom'
}, {
label: this.$t('asset.state'),
prop: 'state',
show: true,
2021-05-13 11:40:22 +08:00
width: 100,
sortable: 'custom'
2021-05-13 11:40:22 +08:00
}, {
label: this.$t('asset.pingInfo'),
prop: 'pingInfo',
show: true,
width: 110
}, {
label: this.$t('overall.dc'),
prop: 'dc',
show: true,
2021-05-13 11:40:22 +08:00
width: 140,
sortable: 'custom'
}, {
label: this.$t('asset.cabinet'),
prop: 'cabinet',
show: true,
width: 110,
sortable: 'custom'
}, {
label: this.$t('asset.alertNum'),
2021-04-26 21:42:15 +08:00
prop: 'alertNum',
show: true,
width: 140,
sortable: 'custom'
}, {
label: this.$t('asset.endpointNum2'),
prop: 'endpointNum',
show: true,
width: 160,
sortable: 'custom'
2021-04-26 21:42:15 +08:00
}, {
label: this.$t('asset.brand'),
prop: 'brand',
show: true,
width: 120,
sortable: 'custom'
2021-04-26 21:42:15 +08:00
}, {
label: this.$t('asset.model'),
prop: 'model',
show: true,
width: 110,
sortable: 'custom'
2021-04-26 21:42:15 +08:00
}, {
label: 'SN',
prop: 'sn',
show: true,
width: 110
}, {
label: this.$t('asset.purchaseDate'),
prop: 'purchaseDate',
show: false,
width: 110
}
]
}
},
methods: {
showTableTooltip,
hideTableTooltip,
messageStyle (title, row) {
if (title.prop === 'alertNum') {
if (row.alertNum > 0) {
return 'danger'
} else {
return 'success'
}
}
if (title.label === 'endpointNum') {
if (row.state === 3) {
return 'suspended'
} else {
if (row.endpointDownNum > 0) {
return 'danger'
} else {
return 'success'
}
}
}
return ''
},
showEndpoint (asset) {
this.bottomBox.asset = Object.assign({}, asset)
this.bottomBox.targetTab = 'endpoint'
this.bottomBox.showSubList = true
},
returnCabinet (start, end) { // 返回机柜u位信息
if (!start || !end) {
return ''
}
return `[${start}-${end}]`
2021-05-13 11:40:22 +08:00
},
formatPingTime (str) {
if (!str || str == '') {
return this.$t('asset.assetStatPre') + this.$t('asset.assetStatDown')
}
const ds = '-'
const ts = ':'
const time = new Date(bus.UTCTimeToConfigTimezone(str))
const year = time.getFullYear()
const month = time.getMonth() + 1 > 9 ? time.getMonth() + 1 : ('0' + (time.getMonth() + 1))
const day = time.getDate() > 9 ? time.getDate() : ('0' + time.getDate())
const hours = time.getHours() > 9 ? time.getHours() : ('0' + time.getHours())
const minutes = time.getMinutes() > 9 ? time.getMinutes() : ('0' + time.getMinutes())
const seconds = time.getSeconds() > 9 ? time.getSeconds() : ('0' + time.getSeconds())
return this.$t('asset.assetStatPre') + year + ds + month + ds + day + ' ' + hours + ts + minutes + ts + seconds
}
}
}
</script>