summaryrefslogtreecommitdiff
path: root/nezha-fronted/src/components/page/config/promServer.vue
diff options
context:
space:
mode:
Diffstat (limited to 'nezha-fronted/src/components/page/config/promServer.vue')
-rw-r--r--nezha-fronted/src/components/page/config/promServer.vue356
1 files changed, 78 insertions, 278 deletions
diff --git a/nezha-fronted/src/components/page/config/promServer.vue b/nezha-fronted/src/components/page/config/promServer.vue
index 71943db10..65a797ea8 100644
--- a/nezha-fronted/src/components/page/config/promServer.vue
+++ b/nezha-fronted/src/components/page/config/promServer.vue
@@ -1,42 +1,29 @@
-<style lang="scss">
-@import '@/assets/css/common/tableCommon.scss';
-</style>
<template>
- <div class="prom list-page">
- <div class="main-list" :class="{'main-list-with-sub': bottomBox.showSubList}">
- <div class="main-modal"></div>
- <div class="top-tools" v-show="bottomBox.mainResizeShow">
- <div class="top-tool-main-right" :class="{'top-tool-main-right-to-left': bottomBox.showSubList}">
- <div class="top-tool-search">
- <search-input ref="searchInput" :searchMsg="searchMsg" @search="search" :inTransform="bottomBox.inTransform"></search-input>
- </div>
- <button :title="$t('overall.createPrometheusServer')" @click="add" type="button" v-has="'prom_toAdd'"
- id="prom-add" class="top-tool-btn margin-l-20">
- <i class="nz-icon-create-square nz-icon"></i>
- </button>
- <delete-button :delete-objs="batchDeleteObjs" @after="getTableData" @before="delFlag=true" api="promServer" v-has="'prom_delete'" id="promserver-list-batch-delete"></delete-button>
- <button id="prom-column-setting" class="top-tool-btn margin-l-10"
- type="button" @click="!tools.showCustomTableTitle && (tools.showCustomTableTitle = true)">
- <i class="nz-icon-gear nz-icon"></i>
- </button>
- </div>
- <div class="pagination-top pagination-top-hide display-none"></div>
- </div>
- <!-- 自定义table列 -->
- <transition name="el-zoom-in-top">
- <element-set
- id="promserver-list"
- v-if="tools.showCustomTableTitle"
- @close="tools.showCustomTableTitle = false"
- :custom-table-title.sync="tools.customTableTitle"
- :original-table-title="tableTitle"
- ref="customTableTitle"
- ></element-set>
- </transition>
- <div class="nz-table2">
- <el-table v-show="bottomBox.mainResizeShow" ref="promTable" v-loading="tools.loading" :data="tableData"
- :height="mainTableHeight" border @sort-change="tableDataSort"
- @selection-change="(selection)=>{this.batchDeleteObjs=selection}"
+ <div style="height: 100%">
+ <nz-data-list
+ ref="dataList"
+ :components="['searchInput', 'elementSet']"
+ :custom-table-title.sync="tools.customTableTitle"
+ :from="fromRoute.promServer"
+ :search-msg="searchMsg"
+ :table-id="tableId"
+ :table-title="tableTitle">
+ <template v-slot:top-tool-right>
+ <button id="prom-add" v-has="'prom_toAdd'" :title="$t('overall.createPrometheusServer')" class="top-tool-btn margin-l-20"
+ type="button" @click="add">
+ <i class="nz-icon-create-square nz-icon"></i>
+ </button>
+ <delete-button id="promserver-list-batch-delete" v-has="'prom_delete'" :delete-objs="batchDeleteObjs" api="agent" @after="getTableData" @before="delFlag=true"></delete-button>
+ </template>
+ <template v-slot:default="slotProps">
+ <el-table ref="dataTable"
+ v-loading="tools.loading"
+ :data="tableData"
+ :height="mainTableHeight"
+ border
+ @header-dragend="dragend"
+ @sort-change="tableDataSort"
+ @selection-change="(selection)=>{batchDeleteObjs=selection}"
>
<el-table-column
:resizable="false"
@@ -47,20 +34,24 @@
<el-table-column v-for="(item, index) in tools.customTableTitle" v-if="item.show"
:key="`col-${index}`"
:label="item.label"
- :prop="$tableSet.propTitle(item.prop,'promServer')"
+ :prop="propTitle(item.prop, fromRoute.promServer)"
:resizable="true"
:sort-orders="['ascending', 'descending']"
- :sortable="$tableSet.sortableShow(item.prop,'promServer')">
+ :sortable="sortableShow(item.prop, fromRoute.promServer)">
+ <template slot="header">
+ <span>
+ <span>{{item.label}}</span>
+ <div class="col-resize-area"></div>
+ </span>
+ </template>
<template slot-scope="scope" :column="item">
- <span v-if="item.prop == 'idc'" >{{scope.row[item.prop]?scope.row[item.prop].name:'-'}}</span>
+ <span v-if="item.prop === 'idc'" >{{scope.row[item.prop]?scope.row[item.prop].name:'-'}}</span>
- <span v-else-if="item.prop == 'type'">
- <!--{{scope.row[item.prop] == '1' ? 'Global' : ''}}
- {{scope.row[item.prop] == '2' ? 'Per-Datacenter' : ''}}-->
+ <span v-else-if="item.prop === 'type'">
{{findServerType(scope.row[item.prop]).text}}
</span>
- <span v-else-if="item.prop == 'checkTime'">{{utcTimeToTimezoneStr(scope.row[item.prop])}}</span>
- <span v-else-if="item.prop == 'status'">
+ <span v-else-if="item.prop === 'checkTime'">{{utcTimeToTimezoneStr(scope.row[item.prop])}}</span>
+ <span v-else-if="item.prop === 'status'">
<el-popover :content="$t('asset.assetStatPre')+(scope.row.checkTime?utcTimeToTimezoneStr(scope.row.checkTime):$t('asset.assetStatDown'))" placement="right" trigger="hover" width="200">
<div slot="reference" style="width: 20px">
<div :class="{'active-icon green':scope.row[item.prop] == '1','active-icon red':scope.row[item.prop] == '0' || scope.row[item.prop] == '-1' || scope.row[item.prop] == '-2'}"></div>
@@ -71,74 +62,62 @@
<template v-else>-</template>
</template>
</el-table-column>
+ <el-table-column
+ :resizable="false"
+ :width="operationWidth"
+ fixed="right">
+ <div slot="header" class="table-operation-title">{{$t('overall.option')}}</div>
+ <div slot-scope="scope" class="table-operation-items">
+ <button class="table-operation-item" @click="$refs.dataList.showBottomBox('operationLog', scope.row)"><i class="nz-icon nz-icon-view1"></i></button>
+ <el-dropdown size="medium" trigger="hover" @command="tableOperation">
+ <div class="table-operation-item table-operation-item--more">
+ <span>…</span><i class="nz-icon nz-icon-arrow-down"></i>
+ </div>
+ <el-dropdown-menu slot="dropdown">
+ <el-dropdown-item :command="['edit', scope.row]" :disabled="isBuildIn(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 :command="['delete', scope.row, `agent?ids=${scope.row.id}`]" :disabled="isBuildIn(scope.row)"><i class="nz-icon nz-icon-delete"></i><span class="operation-dropdown-text">{{$t('overall.delete')}}</span></el-dropdown-item>
+ </el-dropdown-menu>
+ </el-dropdown>
+ </div>
+ </el-table-column>
</el-table>
- </div>
- <button :class="{'to-top-is-hover': tools.tableHover}" :style="{top: tools.toTopBtnTop}" @click="toTop(scrollbarWrap)" class="to-top" v-show="tools.showTopBtn && bottomBox.mainResizeShow" id="promserver-list-totop"><i class="nz-icon nz-icon-top"></i></button>
- <div class="pagination-bottom" v-show="!bottomBox.showSubList">
- <Pagination :tableId="tableId" :pageObj="pageObj" @pageNo='pageNo' @pageSize='pageSize' ref="Pagination"></Pagination>
- </div>
- </div>
- <transition name="el-zoom-in-bottom">
- <bottom-box v-if="bottomBox.showSubList" :sub-resize-show="bottomBox.subResizeShow" :obj="bottomBox.promServer" :is-full-screen="bottomBox.isFullScreen" :from="'promServer'" :target-tab.sync="bottomBox.targetTab" :detail="bottomBox.promDetail"
- @closeSubList="bottomBox.showSubList = false" @fullScreen="fullScreen" @exitFullScreen="exitFullScreen" @listResize="listResize" ></bottom-box>
- </transition>
+ <!-- 回到table顶部的按钮 -->
+ <button v-show="tools.showTopBtn && slotProps.mainResizeShow" id="account-list-totop" :class="{'to-top-is-hover': tools.tableHover}" :style="{top: tools.toTopBtnTop}" class="to-top" @click="toTop(scrollbarWrap)"><i class="nz-icon nz-icon-top"></i></button>
+ </template>
+ <!-- 分页组件 -->
+ <template v-slot:pagination>
+ <Pagination ref="Pagination" :pageObj="pageObj" :tableId="tableId" @pageNo='pageNo' @pageSize='pageSize'></Pagination>
+ </template>
+ </nz-data-list>
<transition name="right-box">
- <prom-server-box v-if="rightBox.show" :prom-server="promServer" @close="closeRightBox"></prom-server-box>
+ <prom-server-box v-if="rightBox.show" :prom-server="object" @close="closeRightBox"></prom-server-box>
</transition>
</div>
</template>
<script>
-import bus from '../../../libs/bus'
-import promServerBox from '../../common/rightBox/promServerBox'
-import deleteButton from '../../common/deleteButton'
+import deleteButton from '@/components/common/deleteButton'
+import promServerBox from '@/components/common/rightBox/promServerBox'
+import { promServer } from '@/components/common/js/constants'
+import nzDataList from '@/components/common/table/nzDataList'
+import tableMixin from '@/components/common/mixin/table'
export default {
name: 'promServer',
components: {
- 'prom-server-box': promServerBox,
- 'delete-button': deleteButton
+ nzDataList,
+ promServerBox,
+ deleteButton
},
+ mixins: [tableMixin],
data () {
return {
- // 侧滑
- rightBox: {
- show: false
- },
- /* 二级页面相关 */
- bottomBox: {
- promDetail: {},
- promServer: {},
- mainResizeShow: true, // dom高度改变时是否展示|隐藏
- subResizeShow: true,
- isFullScreen: false, // 全屏状态
- showSubList: false, // 是否显示二级列表
- targetTab: '', // 显示二级列表中的哪个页签
- inTransform: false // 搜索框相关,搜索条件下拉框是否在transform里
- },
- mainTableHeight: this.$tableHeight.normal, // 主列表table高度
- /* 工具参数 */
- tools: {
- loading: false, // 是否显示table加载动画
- toTopBtnTop: this.$tableHeight.toTopBtnTop, // to-top按钮的top属性
- tableHover: false, // 控制滚动条和top按钮同时出现
- showTopBtn: false, // 显示To top按钮
- showCustomTableTitle: false, // 自定义列弹框是否显示
- customTableTitle: [] // 自定义列工具的数据
- },
- batchDeleteObjs: [],
tableId: 'promTable', // 需要分页的table的id,用于记录每页数量
- promServer: {},
- blankPromServer: {
+ blankObject: {
id: '',
host: '',
port: 9090,
idc: { id: '', name: '', location: '' }
},
- pageObj: {
- pageNo: 1,
- pageSize: this.$CONSTANTS.defaultPageSize,
- total: 0
- },
tableTitle: [
{
label: 'ID',
@@ -207,97 +186,10 @@ export default {
disabled: false
}]
},
- searchLabel: {}, // 搜索参数
- promServerType: null,
- scrollbarWrap: null,
- delFlag: false
+ promServerType: null
}
},
methods: {
- // 全屏
- fullScreen () {
- const vm = this
- this.$bottomBoxWindow.fullScreen(vm)
- },
- // 退出全屏
- exitFullScreen () {
- const vm = this
- this.$bottomBoxWindow.exitFullScreen(vm)
- },
- // 鼠标拖动二级列表
- listResize (e) {
- const vm = this
- this.$bottomBoxWindow.listResize(vm, e)
- },
- convertToDetail (obj) {
- const detail = []
- detail.push({ label: this.$t('config.dc.dc'), value: obj.idc.name })
- detail.push({ label: 'Host', value: obj.host })
- detail.push({ label: 'Port', value: obj.port })
- let type = ''
- for (let i = 0; i < this.$CONSTANTS.promServer.typeData.length; i++) {
- if (obj.value == this.$CONSTANTS.promServer.typeData[i].type) {
- type = this.$CONSTANTS.promServer.typeData[i].label
- break
- }
- }
- detail.push({ label: this.$t('config.promServer.type'), value: type })
- detail.push({
- label: this.$t('asset.state'),
- value: obj.status,
- type: 'status',
- msg: this.$t('asset.assetStatPre') + (obj.checkTime ? obj.checkTime : this.$t('asset.assetStatDown'))
- })
- return detail
- },
- edit (u) {
- this.promServer = JSON.parse(JSON.stringify(u))
- this.rightBox.show = true
- },
- /* 删除 */
- del (u) {
- this.$confirm(this.$t('tip.confirmDelete'), {
- confirmButtonText: this.$t('tip.yes'),
- cancelButtonText: this.$t('tip.no'),
- type: 'warning'
- }).then(() => {
- this.$delete('promServer?ids=' + u.id).then(response => {
- if (response.code === 200) {
- this.delFlag = true
- this.$message({ duration: 1000, type: 'success', message: this.$t('tip.deleteSuccess') })
- this.getTableData()
- } else {
- this.$message.error(response.msg)
- }
- })
- })
- },
- detail (u) {
- this.bottomBox.promServer = JSON.parse(JSON.stringify(u))
- this.bottomBox.targetTab = 'detail'
- this.bottomBox.showSubList = true
- },
- add () {
- this.promServer = this.newPromServer()
- this.rightBox.show = true
- },
- closeRightBox (refresh) {
- this.rightBox.show = false
- if (refresh) {
- this.delFlag = true
- this.getTableData()
- }
- },
-
- jumpTo (data, id) {
- bus.$emit('menu-change', data)
- this.$router.push({
- path: '/' + data,
- query: {
- t: +new Date()
- }
- })
- },
getTableData () {
if (!this.hasButton('prom_view')) {
this.$message.error(this.$t('tip.noAccess'))
@@ -306,7 +198,7 @@ export default {
this.$set(this.searchLabel, 'pageNo', this.pageObj.pageNo)
this.$set(this.searchLabel, 'pageSize', this.pageObj.pageSize)
this.loading = true
- this.$get('promServer', this.searchLabel).then(response => {
+ this.$get('agent', this.searchLabel).then(response => {
this.loading = false
if (response.code === 200) {
for (let i = 0; i < response.data.list.length; i++) {
@@ -321,45 +213,13 @@ export default {
this.pageObj.total = response.data.total
if (!this.scrollbarWrap) {
this.$nextTick(() => {
- this.scrollbarWrap = this.$refs.promTable.bodyWrapper
+ this.scrollbarWrap = this.$refs.dataTable.bodyWrapper
this.toTopBtnHandler(this.scrollbarWrap)
})
}
}
})
},
- newPromServer () {
- return JSON.parse(JSON.stringify(this.blankPromServer))
- },
- pageNo (val) {
- this.pageObj.pageNo = val
- this.getTableData()
- },
- pageSize (val) {
- this.pageObj.pageSize = val
- localStorage.setItem('nz-pageSize-' + localStorage.getItem('nz-username') + '-' + this.tableId, val)
- this.getTableData()
- },
- search (searchObj) {
- let orderBy = ''
- if (this.searchLabel.orderBy) {
- orderBy = this.searchLabel.orderBy
- }
- this.pageObj.pageNo = 1
- this.searchLabel = {}
- for (const item in searchObj) {
- if (searchObj[item]) {
- this.$set(this.searchLabel, item, searchObj[item])
- }
- }
- if (orderBy) {
- this.$set(this.searchLabel, 'orderBy', orderBy)
- }
- if (this.$refs.promTable && this.$refs.promTable.bodyWrapper) {
- this.$refs.promTable.bodyWrapper.scrollTop = 0
- }
- this.getTableData()
- },
// 获取dc数据
getDcData () {
return new Promise(resolve => {
@@ -371,22 +231,10 @@ export default {
})
})
},
- // 数据排序
- tableDataSort (item) {
- let orderBy = ''
- if (item.order === 'ascending') {
- orderBy = item.prop
- }
- if (item.order === 'descending') {
- orderBy = '-' + item.prop
- }
- this.$set(this.searchLabel, 'orderBy', orderBy)
- this.getTableData()
- },
findServerType (type) {
if (!this.promServerType) {
this.promServerType = []
- this.$CONSTANTS.promServer.theData.forEach(item => {
+ promServer.theData.forEach(item => {
this.promServerType = this.promServerType.concat(item.children)
})
}
@@ -395,59 +243,11 @@ export default {
})
}
},
- created () {
- // 是否存在分页缓存
- const pageSize = localStorage.getItem('nz-pageSize-' + localStorage.getItem('nz-username') + '-' + this.tableId)
- if (pageSize != 'undefined' && pageSize != null) {
- this.pageObj.pageSize = pageSize
- }
- },
mounted () {
// 初始化数据
Promise.all([this.getDcData()]).then(response => {
this.getTableData()
})
- // 初始化表头
- this.tools.customTableTitle = localStorage.getItem('nz-tableTitle-' + localStorage.getItem('nz-username') + '-' + this.$route.path)
- ? JSON.parse(localStorage.getItem('nz-tableTitle-' + localStorage.getItem('nz-username') + '-' + this.$route.path))
- : this.tableTitle
- this.tableTitleReset(this.tableTitle, this.tools.customTableTitle)
- // 是否存在分页缓存
- const pageSize = localStorage.getItem('nz-pageSize-' + localStorage.getItem('nz-username') + '-' + this.tableId)
- if (pageSize != 'undefined' && pageSize != null) {
- this.pageObj.pageSize = pageSize
- }
- },
- beforeDestroy () {
- if (this.scrollbarWrap) {
- this.scrollbarWrap.removeEventListener('scroll', bus.debounce)
- };
- },
-
- watch: {
- 'bottomBox.promServer': {
- deep: true,
- handler (n) {
- this.bottomBox.promDetail = this.convertToDetail(n)
- }
- },
- 'bottomBox.showSubList': function (n) {
- const vm = this
- this.$bottomBoxWindow.showSubListWatch(vm, n)
- },
- tableData: {
- deep: true,
- handler (n) {
- if (n.length === 0 && this.pageObj.pageNo > 1) {
- this.pageNo(this.pageObj.pageNo - 1)
- }
- if (!this.delFlag) { // 不是删除时回到顶部
- this.$refs.promTable.bodyWrapper.scrollTop = 0
- } else {
- this.delFlag = false
- }
- }
- }
}
}
</script>