2021-04-12 13:00:59 +08:00
|
|
|
|
import bus from '@/libs/bus'
|
|
|
|
|
|
import { tableSet } from '@/components/common/js/tools'
|
|
|
|
|
|
import { fromRoute } from '@/components/common/js/constants'
|
2021-07-23 15:49:18 +08:00
|
|
|
|
import { object } from 'cytoscape/src/is'
|
2021-04-12 13:00:59 +08:00
|
|
|
|
export default {
|
|
|
|
|
|
data () {
|
|
|
|
|
|
return {
|
|
|
|
|
|
fromRoute: fromRoute,
|
|
|
|
|
|
// 侧滑
|
|
|
|
|
|
rightBox: {
|
|
|
|
|
|
show: false
|
|
|
|
|
|
},
|
|
|
|
|
|
pageObj: { // 分页对象
|
|
|
|
|
|
pageNo: 1,
|
|
|
|
|
|
pageSize: this.$CONSTANTS.defaultPageSize,
|
|
|
|
|
|
total: 0
|
|
|
|
|
|
},
|
|
|
|
|
|
/* 工具参数 */
|
|
|
|
|
|
tools: {
|
2021-05-19 11:32:41 +08:00
|
|
|
|
loading: true, // 是否显示table加载动画
|
2021-04-29 22:24:38 +08:00
|
|
|
|
customTableTitle: [], // 自定义列工具的数据
|
|
|
|
|
|
extraTableTitle: [] // 特殊页面(asset)额外的列
|
2021-04-12 13:00:59 +08:00
|
|
|
|
},
|
|
|
|
|
|
mainTableHeight: this.$tableHeight.normal, // 主列表table高度
|
|
|
|
|
|
batchDeleteObjs: [],
|
|
|
|
|
|
object: {},
|
|
|
|
|
|
|
|
|
|
|
|
tableData: [],
|
|
|
|
|
|
searchLabel: {}, // 搜索参数
|
|
|
|
|
|
scrollbarWrap: null,
|
|
|
|
|
|
delFlag: false,
|
2021-04-20 14:38:24 +08:00
|
|
|
|
fromBottom: false,
|
2021-04-21 12:55:09 +08:00
|
|
|
|
operationWidth: '165', // 操作列宽
|
|
|
|
|
|
searchCheckBox: {}
|
2021-04-12 13:00:59 +08:00
|
|
|
|
}
|
|
|
|
|
|
},
|
|
|
|
|
|
methods: {
|
|
|
|
|
|
sortableShow: tableSet.sortableShow,
|
|
|
|
|
|
propTitle: tableSet.propTitle,
|
|
|
|
|
|
asce: tableSet.asce,
|
|
|
|
|
|
desc: tableSet.desc,
|
|
|
|
|
|
strTodate: tableSet.strTodate,
|
2021-04-13 10:00:48 +08:00
|
|
|
|
tableOperation ([command, row]) {
|
2021-04-12 13:00:59 +08:00
|
|
|
|
switch (command) {
|
|
|
|
|
|
case 'edit': {
|
|
|
|
|
|
this.edit(row)
|
|
|
|
|
|
break
|
|
|
|
|
|
}
|
|
|
|
|
|
case 'delete': {
|
2021-04-13 10:00:48 +08:00
|
|
|
|
this.del(row)
|
2021-04-12 13:00:59 +08:00
|
|
|
|
break
|
|
|
|
|
|
}
|
2021-05-11 20:47:22 +08:00
|
|
|
|
case 'copy': {
|
|
|
|
|
|
this.copy(row)
|
|
|
|
|
|
break
|
|
|
|
|
|
}
|
2021-04-12 13:00:59 +08:00
|
|
|
|
default:
|
|
|
|
|
|
break
|
|
|
|
|
|
}
|
|
|
|
|
|
},
|
|
|
|
|
|
isBuildIn (row) {
|
|
|
|
|
|
return (row.buildIn && row.buildIn == 1) || (row.builtIn && row.builtIn == 1)
|
|
|
|
|
|
},
|
2021-04-13 10:00:48 +08:00
|
|
|
|
selectionChange (objs) {
|
|
|
|
|
|
this.batchDeleteObjs = objs
|
|
|
|
|
|
},
|
2021-04-16 21:10:31 +08:00
|
|
|
|
getTableData (params) {
|
|
|
|
|
|
if (params && Object.keys(params).length > 0) {
|
|
|
|
|
|
for (const key in params) {
|
|
|
|
|
|
this.$set(this.searchLabel, key, params[key])
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2021-04-12 13:00:59 +08:00
|
|
|
|
this.$set(this.searchLabel, 'pageNo', this.pageObj.pageNo)
|
|
|
|
|
|
this.$set(this.searchLabel, 'pageSize', this.pageObj.pageSize)
|
|
|
|
|
|
this.tools.loading = true
|
2021-04-21 12:55:09 +08:00
|
|
|
|
this.$get(this.url, { ...this.searchLabel, ...this.searchCheckBox }).then(response => {
|
2021-04-12 13:00:59 +08:00
|
|
|
|
this.tools.loading = false
|
|
|
|
|
|
if (response.code === 200) {
|
|
|
|
|
|
for (let i = 0; i < response.data.list.length; i++) {
|
|
|
|
|
|
response.data.list[i].status = response.data.list[i].status + ''
|
|
|
|
|
|
}
|
|
|
|
|
|
this.tableData = response.data.list
|
|
|
|
|
|
this.pageObj.total = response.data.total
|
|
|
|
|
|
if (!this.scrollbarWrap) {
|
|
|
|
|
|
this.$nextTick(() => {
|
|
|
|
|
|
this.scrollbarWrap = this.$refs.dataTable.$refs.dataTable.bodyWrapper
|
|
|
|
|
|
this.toTopBtnHandler(this.scrollbarWrap)
|
|
|
|
|
|
})
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
})
|
|
|
|
|
|
},
|
|
|
|
|
|
del (row) {
|
2021-04-20 14:38:24 +08:00
|
|
|
|
const self = this
|
2021-04-12 13:00:59 +08:00
|
|
|
|
this.$confirm(this.$t('tip.confirmDelete'), {
|
|
|
|
|
|
confirmButtonText: this.$t('tip.yes'),
|
|
|
|
|
|
cancelButtonText: this.$t('tip.no'),
|
|
|
|
|
|
type: 'warning'
|
|
|
|
|
|
}).then(() => {
|
2021-04-13 10:00:48 +08:00
|
|
|
|
this.$delete(this.url + '?ids=' + row.id).then(response => {
|
2021-04-12 13:00:59 +08:00
|
|
|
|
if (response.code === 200) {
|
2021-04-20 14:38:24 +08:00
|
|
|
|
self.delFlag = true
|
2021-04-12 13:00:59 +08:00
|
|
|
|
this.$message({ duration: 2000, type: 'success', message: this.$t('tip.deleteSuccess') })
|
2021-04-20 14:38:24 +08:00
|
|
|
|
self.getTableData()
|
2021-04-12 13:00:59 +08:00
|
|
|
|
} else {
|
|
|
|
|
|
this.$message.error(response.msg)
|
|
|
|
|
|
}
|
|
|
|
|
|
})
|
|
|
|
|
|
})
|
|
|
|
|
|
},
|
|
|
|
|
|
newObject () {
|
|
|
|
|
|
return JSON.parse(JSON.stringify(this.blankObject))
|
|
|
|
|
|
},
|
|
|
|
|
|
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()
|
|
|
|
|
|
},
|
|
|
|
|
|
add () {
|
|
|
|
|
|
this.object = this.newObject()
|
|
|
|
|
|
this.rightBox.show = true
|
|
|
|
|
|
},
|
|
|
|
|
|
closeRightBox (refresh) {
|
|
|
|
|
|
this.rightBox.show = false
|
|
|
|
|
|
if (refresh) {
|
|
|
|
|
|
this.delFlag = true
|
|
|
|
|
|
this.getTableData()
|
|
|
|
|
|
}
|
|
|
|
|
|
},
|
2021-06-01 14:26:09 +08:00
|
|
|
|
closeSilenceBox (refresh) {
|
|
|
|
|
|
this.silenceBoxShow = false
|
|
|
|
|
|
if (refresh) {
|
|
|
|
|
|
this.delFlag = true
|
|
|
|
|
|
this.getTableData()
|
|
|
|
|
|
}
|
|
|
|
|
|
},
|
2021-04-12 13:00:59 +08:00
|
|
|
|
edit (u) {
|
2021-04-26 21:42:15 +08:00
|
|
|
|
this.$get(`${this.url}/${u.id}`).then(response => {
|
|
|
|
|
|
if (response.code === 200) {
|
|
|
|
|
|
this.object = response.data
|
|
|
|
|
|
this.rightBox.show = true
|
|
|
|
|
|
}
|
|
|
|
|
|
})
|
2021-04-12 13:00:59 +08:00
|
|
|
|
},
|
2021-05-11 20:47:22 +08:00
|
|
|
|
copy (u) {
|
2021-08-26 14:51:38 +08:00
|
|
|
|
this.object = { ...u, name: u.name + '-copy', id: '' }
|
|
|
|
|
|
if (this.object.name.length > 64) {
|
|
|
|
|
|
const length = this.object.name.length - 64
|
|
|
|
|
|
this.object.name = u.name.substring(0, u.name.length - length) + '-copy'
|
|
|
|
|
|
}
|
2021-05-11 20:47:22 +08:00
|
|
|
|
this.rightBox.show = true
|
|
|
|
|
|
},
|
2021-04-12 13:00:59 +08:00
|
|
|
|
esc () {
|
|
|
|
|
|
this.rightBox.show = false
|
|
|
|
|
|
},
|
|
|
|
|
|
dragend () {
|
|
|
|
|
|
this.$nextTick(() => {
|
|
|
|
|
|
this.$refs.dataTable.$refs.dataTable.doLayout()
|
|
|
|
|
|
})
|
|
|
|
|
|
},
|
|
|
|
|
|
search (searchObj) {
|
|
|
|
|
|
this.searchLabel = {}
|
|
|
|
|
|
this.pageObj.pageNo = 1
|
|
|
|
|
|
for (const item in searchObj) {
|
2021-04-23 20:06:58 +08:00
|
|
|
|
if (typeof searchObj[item] !== 'undefined' && searchObj[item] !== null && searchObj[item] !== '') {
|
2021-04-12 13:00:59 +08:00
|
|
|
|
this.$set(this.searchLabel, item, searchObj[item])
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
if (this.$refs.dataTable) {
|
2021-04-22 15:12:12 +08:00
|
|
|
|
this.$refs.dataTable.$refs.dataTable.bodyWrapper.scrollTop = 0
|
2021-04-12 13:00:59 +08:00
|
|
|
|
}
|
|
|
|
|
|
this.getTableData()
|
|
|
|
|
|
},
|
|
|
|
|
|
tableDataSort (orderBy) {
|
|
|
|
|
|
this.$set(this.searchLabel, 'orderBy', orderBy)
|
|
|
|
|
|
this.getTableData()
|
|
|
|
|
|
},
|
|
|
|
|
|
tableTitleReset (src, dist) {
|
|
|
|
|
|
dist.forEach(item => {
|
|
|
|
|
|
const title = src.find(t => t.prop === item.prop)
|
|
|
|
|
|
if (title && title.label) {
|
|
|
|
|
|
item.label = title.label
|
|
|
|
|
|
}
|
|
|
|
|
|
})
|
|
|
|
|
|
},
|
|
|
|
|
|
toTop (wrap) {
|
|
|
|
|
|
let currentTop = wrap.scrollTop
|
|
|
|
|
|
const interval = currentTop / 10
|
|
|
|
|
|
const intervalFunc = setInterval(function () { // 花200ms分10次回到顶部,模拟动画效果
|
|
|
|
|
|
if (currentTop === 0) {
|
|
|
|
|
|
clearInterval(intervalFunc)
|
|
|
|
|
|
} else {
|
|
|
|
|
|
currentTop = (currentTop - interval) < interval * 0.5 ? 0 : currentTop - interval
|
|
|
|
|
|
wrap.scrollTop = currentTop
|
|
|
|
|
|
}
|
|
|
|
|
|
}, 20)
|
|
|
|
|
|
},
|
2021-04-22 16:35:15 +08:00
|
|
|
|
clickTab (showTabInfo, showTab) {
|
|
|
|
|
|
this.$emit('changeShowTab', showTab)
|
|
|
|
|
|
},
|
2021-04-12 13:00:59 +08:00
|
|
|
|
toTopBtnHandler (wrap) {
|
|
|
|
|
|
const vm = this
|
|
|
|
|
|
wrap.addEventListener('scroll', bus.debounce(function () {
|
|
|
|
|
|
vm.tools.showTopBtn = wrap.scrollTop > 50
|
|
|
|
|
|
vm.tools.tableHover = wrap.scrollTop > 50
|
|
|
|
|
|
}, 100))
|
2021-04-29 22:24:38 +08:00
|
|
|
|
},
|
|
|
|
|
|
showClickSearch () {
|
|
|
|
|
|
const index = this.dataListLayout.indexOf('clickSearch')
|
|
|
|
|
|
if (index > -1) {
|
|
|
|
|
|
this.dataListLayout.splice(index, 1)
|
|
|
|
|
|
} else {
|
|
|
|
|
|
this.dataListLayout.push('clickSearch')
|
|
|
|
|
|
}
|
2021-06-01 14:26:09 +08:00
|
|
|
|
},
|
|
|
|
|
|
addSilence (row, type) {
|
|
|
|
|
|
this.blankSilenceObject.startAt = bus.timeFormate(bus.getOffsetTimezoneData(), 'yyyy-MM-dd hh:mm:ss')
|
|
|
|
|
|
this.blankSilenceObject.endAt = bus.timeFormate(bus.getOffsetTimezoneData(1), 'yyyy-MM-dd hh:mm:ss')
|
|
|
|
|
|
this.objectSilence = JSON.parse(JSON.stringify(this.blankSilenceObject))
|
2021-06-01 15:19:47 +08:00
|
|
|
|
this.objectSilence.name = 'Quick silence'
|
2021-06-01 14:26:09 +08:00
|
|
|
|
if (type !== 'alertMessage' && type !== 'alertRule') {
|
|
|
|
|
|
this.objectSilence.matchers = [
|
|
|
|
|
|
{ name: type, value: row.name, regex: 0 },
|
|
|
|
|
|
{ name: type + '_id', value: row.id, regex: 0 }
|
|
|
|
|
|
]
|
|
|
|
|
|
} else if (type === 'alertMessage') {
|
|
|
|
|
|
if (typeof row.labels === 'string') row.labels = JSON.parse(row.labels)
|
|
|
|
|
|
const labels = JSON.parse(JSON.stringify(row.labels))
|
|
|
|
|
|
this.objectSilence.matchers = []
|
|
|
|
|
|
Object.keys(labels).forEach((key, i) => {
|
|
|
|
|
|
this.objectSilence.matchers.push(
|
|
|
|
|
|
{ name: key, value: labels[key], regex: 0 }
|
|
|
|
|
|
)
|
|
|
|
|
|
})
|
|
|
|
|
|
} else if (type === 'alertRule') {
|
|
|
|
|
|
this.objectSilence.matchers = [
|
2021-07-23 15:49:18 +08:00
|
|
|
|
{ name: 'alertName', value: row.name, regex: 0 }
|
2021-06-01 14:26:09 +08:00
|
|
|
|
]
|
|
|
|
|
|
}
|
|
|
|
|
|
this.silenceBoxShow = true
|
|
|
|
|
|
},
|
|
|
|
|
|
closeDialog () {
|
|
|
|
|
|
this.silenceBoxShow = false
|
2021-09-09 16:00:37 +08:00
|
|
|
|
},
|
|
|
|
|
|
showText (row) {
|
|
|
|
|
|
this.dialogShowText = true
|
|
|
|
|
|
this.dialogText = row.alertRule.trbShot
|
2021-04-12 13:00:59 +08:00
|
|
|
|
}
|
|
|
|
|
|
},
|
|
|
|
|
|
watch: {
|
|
|
|
|
|
tableData: {
|
|
|
|
|
|
deep: true,
|
|
|
|
|
|
handler (n) {
|
|
|
|
|
|
if (n.length === 0 && this.pageObj.pageNo > 1) {
|
|
|
|
|
|
this.pageNo(this.pageObj.pageNo - 1)
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* if (!this.delFlag) { // 不是删除时回到顶部
|
|
|
|
|
|
this.$refs.dataTable.bodyWrapper.scrollTop = 0
|
|
|
|
|
|
} else {
|
|
|
|
|
|
this.delFlag = false
|
|
|
|
|
|
} */
|
|
|
|
|
|
}
|
|
|
|
|
|
},
|
|
|
|
|
|
'tools.customTableTitle': {
|
|
|
|
|
|
deep: true,
|
|
|
|
|
|
handler (n) {
|
|
|
|
|
|
this.dragend()
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
},
|
|
|
|
|
|
mounted () {
|
|
|
|
|
|
const pageSize = localStorage.getItem('nz-pageSize-' + localStorage.getItem('nz-username') + '-' + this.tableId)
|
|
|
|
|
|
if (pageSize && pageSize !== 'undefined') {
|
|
|
|
|
|
this.pageObj.pageSize = pageSize
|
|
|
|
|
|
}
|
2021-05-12 09:47:28 +08:00
|
|
|
|
let localStorageTableTitle = localStorage.getItem('nz-tableTitle-' + localStorage.getItem('nz-username') + '-' + this.tableId)
|
|
|
|
|
|
localStorageTableTitle = localStorageTableTitle ? JSON.parse(localStorageTableTitle) : this.$refs.dataTable.tableTitle
|
2021-05-13 11:40:22 +08:00
|
|
|
|
this.tools.customTableTitle = this.$refs.dataTable.tableTitle.map((item, index) => { // 修复切换中英文的问题
|
|
|
|
|
|
item.show = localStorageTableTitle[index].show
|
2021-05-12 09:47:28 +08:00
|
|
|
|
return item
|
|
|
|
|
|
})
|
2021-05-13 11:40:22 +08:00
|
|
|
|
if (localStorageTableTitle && (localStorageTableTitle.length > this.$refs.dataTable.tableTitle.length)) {
|
2021-06-01 14:26:09 +08:00
|
|
|
|
const arr = localStorageTableTitle.splice(this.$refs.dataTable.tableTitle.length, localStorageTableTitle.length)
|
2021-09-13 17:35:45 +08:00
|
|
|
|
arr.forEach(item => {
|
|
|
|
|
|
item.minWidth = item.label.length * 16 + 20
|
|
|
|
|
|
})
|
2021-05-13 11:40:22 +08:00
|
|
|
|
this.tools.customTableTitle = this.tools.customTableTitle.concat(arr)
|
|
|
|
|
|
}
|
2021-04-20 14:38:24 +08:00
|
|
|
|
if (!this.fromBottom) {
|
|
|
|
|
|
this.getTableData()
|
2021-09-13 17:35:45 +08:00
|
|
|
|
this.$nextTick(() => {
|
|
|
|
|
|
this.$refs.dataTable.$refs.dataTable.doLayout()
|
|
|
|
|
|
})
|
2021-04-20 14:38:24 +08:00
|
|
|
|
}
|
2021-04-12 13:00:59 +08:00
|
|
|
|
},
|
|
|
|
|
|
beforeDestroy () {
|
|
|
|
|
|
if (this.scrollbarWrap) {
|
|
|
|
|
|
this.scrollbarWrap.removeEventListener('scroll', bus.debounce)
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|