2021-09-02 17:12:27 +08:00
|
|
|
|
import { ElMessageBox, ElMessage } from 'element-plus'
|
2021-06-11 10:00:22 +08:00
|
|
|
|
import i18n from '@/i18n'
|
2021-06-24 17:59:51 +08:00
|
|
|
|
import _ from 'lodash'
|
2022-09-30 07:35:09 +08:00
|
|
|
|
import { storageKey, iso36112, topDomain, echartsFontSize, dbGeoDataTableName, networkTable, dbDrilldownTableConfig } from '@/utils/constants'
|
2022-11-09 15:22:09 +08:00
|
|
|
|
import { getIso36112JsonData, getDictList } from '@/utils/api'
|
2021-07-05 22:58:12 +08:00
|
|
|
|
import { format } from 'echarts'
|
2021-12-14 16:42:45 +08:00
|
|
|
|
import router from '@/router'
|
2022-08-19 10:06:27 +08:00
|
|
|
|
import { db } from '@/indexedDB'
|
2022-12-15 17:42:01 +08:00
|
|
|
|
import { useRoute } from 'vue-router'
|
2021-06-11 10:00:22 +08:00
|
|
|
|
|
|
|
|
|
|
export const tableSort = {
|
|
|
|
|
|
// 是否需要排序
|
|
|
|
|
|
sortableShow (prop, from) {
|
|
|
|
|
|
switch (prop) {
|
|
|
|
|
|
case 'state': {
|
|
|
|
|
|
if (from === 'operationlog' || from === 'alertSilence') {
|
|
|
|
|
|
return false
|
|
|
|
|
|
}
|
|
|
|
|
|
break
|
|
|
|
|
|
}
|
|
|
|
|
|
case 'startAt': {
|
|
|
|
|
|
if (from === 'alertSilence') {
|
|
|
|
|
|
return false
|
|
|
|
|
|
}
|
|
|
|
|
|
break
|
|
|
|
|
|
}
|
|
|
|
|
|
case 'id':
|
|
|
|
|
|
case 'alertRule':
|
|
|
|
|
|
case 'severity':
|
|
|
|
|
|
case 'endAt':
|
|
|
|
|
|
case 'ID':
|
|
|
|
|
|
case 'HOST':
|
|
|
|
|
|
case 'SN':
|
|
|
|
|
|
case 'assetType':
|
|
|
|
|
|
case 'purchaseDate':
|
|
|
|
|
|
case 'pingStatus':
|
|
|
|
|
|
case 'dataCenter':
|
|
|
|
|
|
case 'cabinet':
|
|
|
|
|
|
case 'model':
|
|
|
|
|
|
case 'principal':
|
|
|
|
|
|
case 'asset':
|
|
|
|
|
|
case 'port':
|
|
|
|
|
|
case 'project':
|
|
|
|
|
|
case 'module':
|
|
|
|
|
|
case 'type':
|
|
|
|
|
|
case 'name':
|
|
|
|
|
|
case 'area':
|
|
|
|
|
|
case 'vendor':
|
|
|
|
|
|
case 'filename':
|
|
|
|
|
|
case 'updateAt':
|
|
|
|
|
|
case 'username':
|
|
|
|
|
|
case 'ip':
|
|
|
|
|
|
case 'operation':
|
|
|
|
|
|
case 'createDate':
|
|
|
|
|
|
case 'time':
|
|
|
|
|
|
case 'host':
|
|
|
|
|
|
case 'protocol':
|
|
|
|
|
|
case 'user':
|
|
|
|
|
|
case 'cmd':
|
|
|
|
|
|
case 'alertName':
|
|
|
|
|
|
case 'threshold':
|
|
|
|
|
|
case 'idc':
|
|
|
|
|
|
case 'alertNum':
|
|
|
|
|
|
case 'gname':
|
|
|
|
|
|
return 'custom'
|
|
|
|
|
|
default : return false
|
|
|
|
|
|
}
|
|
|
|
|
|
},
|
|
|
|
|
|
// prop字段
|
|
|
|
|
|
propTitle (prop, from) {
|
|
|
|
|
|
switch (from) {
|
|
|
|
|
|
case 'asset':
|
|
|
|
|
|
switch (prop) {
|
|
|
|
|
|
case 'ID': return 'ass.id'
|
|
|
|
|
|
case 'HOST': return 'ass.host'
|
|
|
|
|
|
case 'SN': return 'ass.sn'
|
|
|
|
|
|
case 'assetType': return 'sdtt.value'
|
|
|
|
|
|
case 'purchaseDate': return 'ass.purchase_date'
|
|
|
|
|
|
case 'state': return 'ass.state'
|
|
|
|
|
|
case 'pingStatus': return 'assp.rtt'
|
|
|
|
|
|
case 'dataCenter': return 'idc.name'
|
|
|
|
|
|
case 'cabinet': return 'cab.name'
|
|
|
|
|
|
case 'model': return 'mo.name'
|
|
|
|
|
|
case 'vendor': return 'sdt.value'
|
|
|
|
|
|
case 'principal': return 'su.username'
|
|
|
|
|
|
default : return prop
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
case 'alertMessage':
|
|
|
|
|
|
switch (prop) {
|
|
|
|
|
|
case 'id': return 'am.id'
|
|
|
|
|
|
case 'state': return 'am.state'
|
|
|
|
|
|
case 'alertRule': return 'ar.alert_name'
|
|
|
|
|
|
case 'severity': return 'am.severity'
|
|
|
|
|
|
case 'startAt': return 'am.start_at'
|
|
|
|
|
|
case 'endAt': return 'am.end_at'
|
|
|
|
|
|
default : return prop
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
case 'project':
|
|
|
|
|
|
switch (prop) {
|
|
|
|
|
|
case 'id': return 'e.id'
|
|
|
|
|
|
case 'asset': return 'a.host'
|
|
|
|
|
|
case 'port': return 'e.port'
|
|
|
|
|
|
case 'project': return 'p.name'
|
|
|
|
|
|
case 'module': return 'm.name'
|
|
|
|
|
|
case 'type': return 'm.type'
|
|
|
|
|
|
case 'state' :return 'es.state'
|
|
|
|
|
|
// case 'path': return'e.path';
|
|
|
|
|
|
default : return prop
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
case 'dc':
|
|
|
|
|
|
switch (prop) {
|
|
|
|
|
|
case 'id': return 'i.id'
|
|
|
|
|
|
case 'name': return 'i.name'
|
|
|
|
|
|
case 'area': return 'sa.name'
|
|
|
|
|
|
default : return prop
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
case 'endpointTab':
|
|
|
|
|
|
switch (prop) {
|
|
|
|
|
|
case 'id': return 'e.id'
|
|
|
|
|
|
case 'asset': return 'a.host'
|
|
|
|
|
|
case 'port': return 'e.port'
|
|
|
|
|
|
case 'project': return 'p.name'
|
|
|
|
|
|
case 'module': return 'm.name'
|
|
|
|
|
|
case 'type': return 'm.type'
|
|
|
|
|
|
case 'state' :return 'es.state'
|
|
|
|
|
|
// case 'path': return'e.path';
|
|
|
|
|
|
default : return prop
|
|
|
|
|
|
}
|
|
|
|
|
|
case 'model':
|
|
|
|
|
|
switch (prop) {
|
|
|
|
|
|
case 'id': return 'mo.id'
|
|
|
|
|
|
case 'name': return 'mo.name'
|
|
|
|
|
|
case 'type': return 'dictt.value'
|
|
|
|
|
|
case 'vendor': return 'dict.value'
|
|
|
|
|
|
default : return prop
|
|
|
|
|
|
}
|
|
|
|
|
|
case 'promServer':
|
|
|
|
|
|
switch (prop) {
|
|
|
|
|
|
case 'id': return 'id'
|
|
|
|
|
|
case 'idc': return 'idc_id'
|
|
|
|
|
|
case 'host': return 'host'
|
|
|
|
|
|
case 'port': return 'port'
|
|
|
|
|
|
case 'type': return 'type'
|
|
|
|
|
|
default : return prop
|
|
|
|
|
|
}
|
|
|
|
|
|
case 'mib':
|
|
|
|
|
|
switch (prop) {
|
|
|
|
|
|
case 'id': return 'sm.id'
|
|
|
|
|
|
case 'name': return 'sm.name'
|
|
|
|
|
|
case 'filename': return 'sm.file_name'
|
|
|
|
|
|
case 'updateAt': return 'sm.update_at'
|
|
|
|
|
|
default : return prop
|
|
|
|
|
|
}
|
|
|
|
|
|
case 'operationlog':
|
|
|
|
|
|
switch (prop) {
|
|
|
|
|
|
case 'id': return 'sl.id'
|
|
|
|
|
|
case 'username': return 'su.username'
|
|
|
|
|
|
case 'ip': return 'sl.ip'
|
|
|
|
|
|
case 'operation': return 'sl.operation'
|
|
|
|
|
|
case 'type': return 'sl.type'
|
|
|
|
|
|
case 'createDate': return 'sl.create_date'
|
|
|
|
|
|
case 'time': return 'sl.time'
|
|
|
|
|
|
default : return prop
|
|
|
|
|
|
}
|
|
|
|
|
|
case 'temrminallog':
|
|
|
|
|
|
switch (prop) {
|
|
|
|
|
|
case 'protocol': return 'protocol'
|
|
|
|
|
|
case 'startTime': return 'startTime'
|
|
|
|
|
|
default : return prop
|
|
|
|
|
|
}
|
|
|
|
|
|
case 'alertRules':
|
|
|
|
|
|
switch (prop) {
|
|
|
|
|
|
case 'id': return 'ar.id'
|
|
|
|
|
|
case 'alertName': return 'ar.alert_name'
|
|
|
|
|
|
case 'threshold': return 'ar.threshold'
|
|
|
|
|
|
case 'severity': return 'ar.severity'
|
|
|
|
|
|
default : return prop
|
|
|
|
|
|
}
|
|
|
|
|
|
case 'exprTemp':
|
|
|
|
|
|
switch (prop) {
|
|
|
|
|
|
case 'id': return 'id'
|
|
|
|
|
|
case 'name': return 'name'
|
|
|
|
|
|
case 'gname': return 'gname'
|
|
|
|
|
|
default : return prop
|
|
|
|
|
|
}
|
|
|
|
|
|
default: return prop
|
|
|
|
|
|
}
|
|
|
|
|
|
},
|
|
|
|
|
|
// 本地正序
|
|
|
|
|
|
asce (prop) {
|
|
|
|
|
|
return function (obj1, obj2) {
|
|
|
|
|
|
const { val1, val2 } = this.format(prop, obj1, obj2)
|
|
|
|
|
|
if (val1 < val2) {
|
|
|
|
|
|
return -1
|
|
|
|
|
|
} else if (val1 > val2) {
|
|
|
|
|
|
return 1
|
|
|
|
|
|
} else {
|
|
|
|
|
|
return 0
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
},
|
|
|
|
|
|
// 本地倒序
|
|
|
|
|
|
desc (prop) {
|
|
|
|
|
|
return function (obj1, obj2) {
|
|
|
|
|
|
const { val1, val2 } = this.format(prop, obj1, obj2)
|
|
|
|
|
|
if (val1 < val2) {
|
|
|
|
|
|
return 1
|
|
|
|
|
|
} else if (val1 > val2) {
|
|
|
|
|
|
return -1
|
|
|
|
|
|
} else {
|
|
|
|
|
|
return 0
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
},
|
|
|
|
|
|
format (prop, obj1, obj2) {
|
|
|
|
|
|
let val1 = obj1[prop]
|
|
|
|
|
|
let val2 = obj2[prop]
|
|
|
|
|
|
if (!isNaN(Number(val1)) && !isNaN(Number(val2)) && prop !== 'time') {
|
|
|
|
|
|
val1 = Number(val1)
|
|
|
|
|
|
val2 = Number(val2)
|
|
|
|
|
|
}
|
|
|
|
|
|
if (prop === 'time') {
|
|
|
|
|
|
val1 = tableSort.strTodate(val1)
|
|
|
|
|
|
val2 = tableSort.strTodate(val2)
|
|
|
|
|
|
}
|
|
|
|
|
|
if (prop === 'element') {
|
|
|
|
|
|
if (val1.alias) {
|
|
|
|
|
|
val1 = JSON.stringify(obj1[prop].alias).replace(/\s*/g, '')
|
|
|
|
|
|
} else {
|
|
|
|
|
|
val1 = JSON.stringify(obj1[prop].element).replace(/\s*/g, '')
|
|
|
|
|
|
}
|
|
|
|
|
|
if (val2.alias) {
|
|
|
|
|
|
val2 = JSON.stringify(obj2[prop].alias).replace(/\s*/g, '')
|
|
|
|
|
|
} else {
|
|
|
|
|
|
val2 = JSON.stringify(obj2[prop].element).replace(/\s*/g, '')
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
return { val1, val2 }
|
|
|
|
|
|
},
|
|
|
|
|
|
// 转化时间字符串为时间戳
|
|
|
|
|
|
strToDate (str) {
|
|
|
|
|
|
let date = str.trim()
|
|
|
|
|
|
date = date.substring(0, 19)
|
|
|
|
|
|
date = date.replace(/-/g, '/') // 必须把日期'-'转为'/'
|
|
|
|
|
|
return new Date(date).getTime()
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
/* cancel提醒保存指令 */
|
|
|
|
|
|
export const cancelWithChange = {
|
|
|
|
|
|
mounted (el, binding) {
|
|
|
|
|
|
if (!binding.value || !binding.value.object) return
|
|
|
|
|
|
const oldValue = JSON.parse(JSON.stringify(binding.value.object))
|
|
|
|
|
|
function domClick (e) {
|
|
|
|
|
|
const newValue = JSON.parse(JSON.stringify(binding.value.object))
|
2021-12-14 16:42:45 +08:00
|
|
|
|
if (!isEqual(oldValue, newValue)) {
|
2021-07-14 15:40:05 +08:00
|
|
|
|
ElMessageBox.confirm(i18n.global.t('tip.confirmCancel'), {
|
|
|
|
|
|
confirmButtonText: i18n.global.t('tip.yes'),
|
|
|
|
|
|
cancelButtonText: i18n.global.t('tip.no'),
|
2021-06-11 10:00:22 +08:00
|
|
|
|
type: 'warning'
|
|
|
|
|
|
}).then(() => {
|
|
|
|
|
|
if (binding.value.func) {
|
|
|
|
|
|
binding.value.func()
|
|
|
|
|
|
}
|
|
|
|
|
|
})
|
|
|
|
|
|
} else {
|
|
|
|
|
|
binding.value.func()
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
el.__vueDomClick__ = domClick
|
|
|
|
|
|
el.addEventListener('click', domClick)
|
|
|
|
|
|
},
|
|
|
|
|
|
unmounted (el, binding) {
|
|
|
|
|
|
// 解除事件监听
|
|
|
|
|
|
document.removeEventListener('click', el.__vueDomClick__)
|
|
|
|
|
|
delete el.__vueDomClick__
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2021-11-11 23:07:01 +08:00
|
|
|
|
|
2021-12-27 17:10:11 +08:00
|
|
|
|
function noDataDomFactory () {
|
|
|
|
|
|
const noDataDom = document.createElement('div')
|
|
|
|
|
|
noDataDom.setAttribute('class', 'no-data')
|
|
|
|
|
|
noDataDom.innerText = 'No data'
|
|
|
|
|
|
return noDataDom
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2021-08-15 15:49:29 +08:00
|
|
|
|
export const noData = {
|
|
|
|
|
|
updated (el, binding) {
|
2021-12-27 17:10:11 +08:00
|
|
|
|
if (el) {
|
2021-08-15 15:49:29 +08:00
|
|
|
|
if (binding.value) {
|
2021-11-11 23:07:01 +08:00
|
|
|
|
setTimeout(() => {
|
2022-01-06 17:32:20 +08:00
|
|
|
|
// 是否已有no data
|
|
|
|
|
|
let alreadyHasNoData = false
|
2021-11-11 23:07:01 +08:00
|
|
|
|
el.childNodes.forEach(node => {
|
2022-01-06 17:32:20 +08:00
|
|
|
|
if (node.classList && node.classList.value.indexOf('no-data') > -1) {
|
|
|
|
|
|
alreadyHasNoData = true
|
|
|
|
|
|
} else {
|
|
|
|
|
|
node.style && (node.style.display = 'none')
|
|
|
|
|
|
}
|
2021-11-11 23:07:01 +08:00
|
|
|
|
})
|
2022-01-06 17:32:20 +08:00
|
|
|
|
if (!alreadyHasNoData) {
|
|
|
|
|
|
el.insertBefore(noDataDomFactory(), el.childNodes[0])
|
|
|
|
|
|
}
|
2021-11-11 23:07:01 +08:00
|
|
|
|
})
|
|
|
|
|
|
} else {
|
|
|
|
|
|
setTimeout(() => {
|
|
|
|
|
|
for (let i = 0; i < el.childNodes.length; i++) {
|
|
|
|
|
|
const node = el.childNodes[i]
|
2022-01-06 17:32:20 +08:00
|
|
|
|
if (node.classList && node.classList.value.indexOf('no-data') > -1) {
|
2021-11-11 23:07:01 +08:00
|
|
|
|
el.removeChild(node)
|
|
|
|
|
|
break
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
el.childNodes.forEach(node => {
|
2021-11-12 11:46:09 +08:00
|
|
|
|
node.style && (node.style.display = '')
|
2021-11-11 23:07:01 +08:00
|
|
|
|
})
|
|
|
|
|
|
})
|
2021-08-15 15:49:29 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2021-06-11 10:00:22 +08:00
|
|
|
|
export function isEqual (o1, o2) {
|
|
|
|
|
|
const isEqualForInner = function (obj1, obj2) {
|
|
|
|
|
|
const o1 = obj1 instanceof Object
|
|
|
|
|
|
const o2 = obj2 instanceof Object
|
|
|
|
|
|
if (!o1 || !o2) {
|
|
|
|
|
|
return obj1 === obj2
|
|
|
|
|
|
}
|
|
|
|
|
|
if (Object.keys(obj1).length !== Object.keys(obj2).length) {
|
|
|
|
|
|
return false
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
for (const attr of Object.keys(obj1)) {
|
|
|
|
|
|
const t1 = obj1[attr] instanceof Object
|
|
|
|
|
|
const t2 = obj2[attr] instanceof Object
|
|
|
|
|
|
if (t1 && t2) {
|
|
|
|
|
|
if (!isEqualForInner(obj1[attr], obj2[attr])) {
|
|
|
|
|
|
return false
|
|
|
|
|
|
}
|
|
|
|
|
|
} else if (obj1[attr] !== obj2[attr]) {
|
|
|
|
|
|
return false
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
return true
|
|
|
|
|
|
}
|
|
|
|
|
|
return isEqualForInner(o1, o2)
|
|
|
|
|
|
}
|
2021-06-20 13:31:55 +08:00
|
|
|
|
|
|
|
|
|
|
/* 计算文本的实际width,而不是length */
|
2021-07-05 22:58:12 +08:00
|
|
|
|
export function getTextRect (text, fontSize = 14) {
|
|
|
|
|
|
return format.getTextRect(text, `${fontSize}`)
|
2021-06-20 13:31:55 +08:00
|
|
|
|
}
|
2021-06-24 17:59:51 +08:00
|
|
|
|
|
|
|
|
|
|
/* url占位符处理 */
|
|
|
|
|
|
export function replaceUrlPlaceholder (url, params) {
|
|
|
|
|
|
_.forIn(params, (value, key) => {
|
|
|
|
|
|
url = url.replace('{{' + key + '}}', value)
|
|
|
|
|
|
})
|
2022-01-16 23:16:00 +08:00
|
|
|
|
url = url.replace(/{{(.*?)}}/g, '')
|
2021-08-26 17:14:51 +08:00
|
|
|
|
return url
|
2021-08-16 11:34:37 +08:00
|
|
|
|
}
|
|
|
|
|
|
// 双引号替换为单引号
|
|
|
|
|
|
export function doubleQuotationToSingle (content) {
|
|
|
|
|
|
return content.replace(/\"/g, "'")
|
2021-06-24 17:59:51 +08:00
|
|
|
|
}
|
2021-08-26 17:14:51 +08:00
|
|
|
|
// 双引号加斜杠转义
|
|
|
|
|
|
export function doubleQuotationEscape (content) {
|
|
|
|
|
|
return content.replace(/\"/g, '\\\"')
|
|
|
|
|
|
}
|
2021-06-25 19:11:00 +08:00
|
|
|
|
// 下划线转换驼峰
|
|
|
|
|
|
export function lineToHump (name) {
|
2021-07-01 15:39:48 +08:00
|
|
|
|
return name.replace(/\_(\w)/g, function (all, letter) {
|
2021-06-25 19:11:00 +08:00
|
|
|
|
return letter.toUpperCase()
|
|
|
|
|
|
})
|
|
|
|
|
|
}
|
2022-03-08 22:06:58 +08:00
|
|
|
|
// 驼峰转空格,首字母小写
|
|
|
|
|
|
export function humpToSpace (name) {
|
|
|
|
|
|
const str = name.replace(/([A-Z])/g, ' $1')
|
|
|
|
|
|
return str.split(' ').map(s => _.lowerFirst(s)).join(' ')
|
|
|
|
|
|
}
|
|
|
|
|
|
// 下划线转换空格
|
2021-07-14 15:40:05 +08:00
|
|
|
|
export function lineToSpace (name) {
|
2022-03-06 23:26:42 +08:00
|
|
|
|
if (_.isEmpty(name)) {
|
|
|
|
|
|
return ''
|
|
|
|
|
|
}
|
2022-03-08 22:06:58 +08:00
|
|
|
|
return name.replace(/\_(\w)/g, ' ')
|
2021-07-14 15:40:05 +08:00
|
|
|
|
}
|
2021-06-25 19:11:00 +08:00
|
|
|
|
// 驼峰转换下划线
|
|
|
|
|
|
export function humpToLine (name) {
|
2022-03-06 23:26:42 +08:00
|
|
|
|
if (_.isEmpty(name)) {
|
|
|
|
|
|
return ''
|
|
|
|
|
|
}
|
2021-07-01 15:39:48 +08:00
|
|
|
|
return name.replace(/([A-Z])/g, '_$1').toLowerCase()
|
|
|
|
|
|
}
|
2022-03-17 17:56:38 +08:00
|
|
|
|
// 排序功能:从大到小,降序排列
|
2022-03-11 15:40:33 +08:00
|
|
|
|
export function reverseSortBy (i) {
|
2022-03-08 12:09:41 +08:00
|
|
|
|
return function (a, b) {
|
|
|
|
|
|
return b[i] - a[i]
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2022-03-11 15:40:33 +08:00
|
|
|
|
|
2022-03-17 17:56:38 +08:00
|
|
|
|
// 排序功能:从小到大,升序排列
|
2022-03-11 15:40:33 +08:00
|
|
|
|
export function sortBy (i) {
|
|
|
|
|
|
return function (a, b) {
|
|
|
|
|
|
return a[i] - b[i]
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2022-03-17 17:56:38 +08:00
|
|
|
|
// echart图标,y轴鼠标悬浮时,显示标签所有内容
|
|
|
|
|
|
export function extensionEchartY (chart) {
|
|
|
|
|
|
// 判断是否创建过div框,如果创建过就不再创建了
|
|
|
|
|
|
// 该div用来盛放文本显示内容的,方便对其悬浮位置进行处理
|
|
|
|
|
|
const id = document.getElementById('extension')
|
|
|
|
|
|
if (!id) {
|
|
|
|
|
|
const contentDiv = document.createElement('div')
|
|
|
|
|
|
contentDiv.setAttribute('id', 'extension')
|
|
|
|
|
|
contentDiv.setAttribute('style', 'display:block')
|
2022-03-11 15:40:33 +08:00
|
|
|
|
document.documentElement.append(contentDiv)
|
|
|
|
|
|
}
|
2022-03-17 17:56:38 +08:00
|
|
|
|
chart.on('mouseover', function (params) {
|
|
|
|
|
|
// 注意这里,我是以Y轴显示内容过长为例,如果是x轴的话,需要改为xAxis
|
|
|
|
|
|
if (params.componentType === 'yAxis') {
|
|
|
|
|
|
// 设置悬浮文本的位置以及样式
|
|
|
|
|
|
const extEle = document.getElementById('extension')
|
|
|
|
|
|
extEle.style.cssText = 'display:inline;position:absolute;' +
|
|
|
|
|
|
' padding: 12px;' +
|
|
|
|
|
|
' max-width: 400px !important;' +
|
|
|
|
|
|
' color: #666;' +
|
|
|
|
|
|
' background-color: rgb(255, 255, 255);' +
|
|
|
|
|
|
' font-size: 14px;' +
|
|
|
|
|
|
' line-height: 20px;' +
|
|
|
|
|
|
' font-weight:400; ' +
|
|
|
|
|
|
' font-family: "Microsoft YaHei"' +
|
|
|
|
|
|
' border-style: solid;' +
|
|
|
|
|
|
' border-width: 1px;' +
|
|
|
|
|
|
' border-radius: 4px;' +
|
|
|
|
|
|
' border-color: transparent !important;' +
|
|
|
|
|
|
' box-shadow: rgb(0 0 0 / 30%) 0px 0px 3px;' +
|
|
|
|
|
|
' white-space: nowrap;' +
|
|
|
|
|
|
' z-index: 99999999;'
|
2022-03-11 15:40:33 +08:00
|
|
|
|
|
2022-03-17 17:56:38 +08:00
|
|
|
|
extEle.innerHTML = params.value
|
|
|
|
|
|
document.documentElement.onmousemove = function (event) {
|
|
|
|
|
|
const extEle = document.getElementById('extension')
|
|
|
|
|
|
const xx = event.pageX - extEle.offsetWidth - 20
|
|
|
|
|
|
const yy = event.pageY + 20
|
|
|
|
|
|
extEle.style.cssText = extEle.style.cssText + 'top:' + yy + 'px;left:' + xx + 'px;'
|
2022-03-11 15:40:33 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
})
|
2022-03-17 17:56:38 +08:00
|
|
|
|
chart.on('mouseout', function (params) {
|
|
|
|
|
|
// 注意这里,我是以Y轴显示内容过长为例,如果是x轴的话,需要改为xAxis
|
|
|
|
|
|
if (params.componentType == 'yAxis') {
|
|
|
|
|
|
const extEle = document.getElementById('extension')
|
|
|
|
|
|
extEle.style.cssText = 'display:none;'
|
2022-03-11 15:40:33 +08:00
|
|
|
|
}
|
|
|
|
|
|
})
|
|
|
|
|
|
}
|
2022-01-05 23:56:27 +08:00
|
|
|
|
// 搜索功能:对象转字符串
|
|
|
|
|
|
export function objToStr (obj) {
|
|
|
|
|
|
return Object.keys(obj).map(k => {
|
|
|
|
|
|
return `${k}='${obj[k]}'`
|
|
|
|
|
|
}).join(' AND ')
|
|
|
|
|
|
}
|
|
|
|
|
|
// 搜索功能:字符串转对象
|
|
|
|
|
|
export function strToObj (n) {
|
2022-01-10 18:23:50 +08:00
|
|
|
|
const paramsArr = n.split(/\sAND\s/)
|
2022-01-05 23:56:27 +08:00
|
|
|
|
const paramsObj = {}
|
|
|
|
|
|
paramsArr.forEach(string => {
|
|
|
|
|
|
const param = string.split('=')
|
|
|
|
|
|
if (param.length > 1) {
|
|
|
|
|
|
let value = param[1].trim()
|
|
|
|
|
|
const valueArr = value.split(/[\"\']/g)
|
|
|
|
|
|
if (valueArr.length > 2) {
|
|
|
|
|
|
value = valueArr[1].trim()
|
|
|
|
|
|
}
|
|
|
|
|
|
paramsObj[param[0].trim()] = value
|
|
|
|
|
|
}
|
|
|
|
|
|
})
|
|
|
|
|
|
return paramsObj
|
|
|
|
|
|
}
|
2021-07-05 17:40:43 +08:00
|
|
|
|
// 加载geo数据
|
2022-08-19 10:06:27 +08:00
|
|
|
|
export function loadGeoData () {
|
2021-07-05 17:40:43 +08:00
|
|
|
|
const keys = []
|
2022-08-19 10:06:27 +08:00
|
|
|
|
keys.push(storageKey.iso36112Capital)
|
|
|
|
|
|
keys.push(storageKey.iso36112WorldLow)
|
2021-07-05 17:40:43 +08:00
|
|
|
|
keys.forEach(async k => {
|
2022-08-19 10:06:27 +08:00
|
|
|
|
const queryData = await db[dbGeoDataTableName].get({ name: k })
|
|
|
|
|
|
if (!queryData) {
|
2021-07-05 17:40:43 +08:00
|
|
|
|
const data = await getIso36112JsonData(iso36112[k])
|
|
|
|
|
|
if (data) {
|
2022-08-19 10:06:27 +08:00
|
|
|
|
db[dbGeoDataTableName].add({
|
|
|
|
|
|
name: k,
|
|
|
|
|
|
geo: data
|
|
|
|
|
|
})
|
2021-07-05 17:40:43 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
})
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2022-08-19 10:06:27 +08:00
|
|
|
|
/* 返回geodata对象
|
|
|
|
|
|
* 使用indexedDB缓存地图数据
|
|
|
|
|
|
* */
|
|
|
|
|
|
export async function getGeoData (key) {
|
|
|
|
|
|
const data = await db[dbGeoDataTableName].get({ name: key })
|
2021-07-05 17:40:43 +08:00
|
|
|
|
if (data) {
|
2022-08-19 10:06:27 +08:00
|
|
|
|
return data.geo
|
2021-07-05 17:40:43 +08:00
|
|
|
|
} else {
|
2022-08-19 10:06:27 +08:00
|
|
|
|
if (iso36112[key]) {
|
|
|
|
|
|
const d = await getIso36112JsonData(iso36112[key])
|
|
|
|
|
|
if (d) {
|
|
|
|
|
|
db[dbGeoDataTableName].add({
|
|
|
|
|
|
name: key,
|
|
|
|
|
|
geo: d
|
|
|
|
|
|
})
|
|
|
|
|
|
return d[key]
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
return null
|
2021-07-05 17:40:43 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2021-07-01 15:39:48 +08:00
|
|
|
|
export function getCapitalGeo (countryId) {
|
2021-07-05 17:40:43 +08:00
|
|
|
|
const data = getGeoData(storageKey.iso36112Capital)
|
|
|
|
|
|
return data[countryId]
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2022-09-30 07:35:09 +08:00
|
|
|
|
export function getUserDrilldownTableGeo (userId) {
|
|
|
|
|
|
const data = getGeoData(storageKey.userCustomizationConfig)
|
|
|
|
|
|
return data[userId]
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2021-07-07 15:28:11 +08:00
|
|
|
|
function JSONParse (data) {
|
2021-07-05 17:40:43 +08:00
|
|
|
|
const firstParse = JSON.parse(data)
|
|
|
|
|
|
if (typeof firstParse === 'string') {
|
|
|
|
|
|
return JSON.parse(firstParse)
|
|
|
|
|
|
} else {
|
|
|
|
|
|
return firstParse
|
|
|
|
|
|
}
|
2021-06-25 19:11:00 +08:00
|
|
|
|
}
|
2021-09-02 17:12:27 +08:00
|
|
|
|
|
|
|
|
|
|
export function copyValue (item) {
|
|
|
|
|
|
const str = item
|
|
|
|
|
|
const domUrl = document.createElement('input')
|
|
|
|
|
|
domUrl.value = JSON.stringify(str)
|
|
|
|
|
|
domUrl.id = 'creatDom'
|
|
|
|
|
|
document.body.appendChild(domUrl)
|
|
|
|
|
|
domUrl.select() // 选择对象
|
|
|
|
|
|
document.execCommand('Copy') // 执行浏览器复制命令
|
|
|
|
|
|
const creatDom = document.getElementById('creatDom')
|
|
|
|
|
|
creatDom.parentNode.removeChild(creatDom)
|
|
|
|
|
|
ElMessage.success(i18n.global.t('tip.copySuccess'))
|
|
|
|
|
|
}
|
2021-12-14 16:42:45 +08:00
|
|
|
|
|
2022-03-21 11:56:54 +08:00
|
|
|
|
export function computeSecondaryDomain (name) {
|
|
|
|
|
|
// 命中的顶级域名
|
|
|
|
|
|
let hitTopDomain = ''
|
|
|
|
|
|
// 同顶级域名比对
|
|
|
|
|
|
const hits = []
|
|
|
|
|
|
topDomain.forEach(td => {
|
|
|
|
|
|
const hitIndex = name.lastIndexOf(td)
|
|
|
|
|
|
if (hitIndex > -1 && hitIndex + td.length === name.length) {
|
|
|
|
|
|
hits.push(td)
|
|
|
|
|
|
}
|
|
|
|
|
|
})
|
|
|
|
|
|
if (hits.length > 0) {
|
|
|
|
|
|
hits.sort((a, b) => {
|
|
|
|
|
|
return b.split('.').length - a.split('.').length
|
|
|
|
|
|
})
|
|
|
|
|
|
hitTopDomain = hits[0]
|
|
|
|
|
|
} else {
|
|
|
|
|
|
const arr = name.split('.')
|
|
|
|
|
|
hitTopDomain = arr[arr.length - 1]
|
|
|
|
|
|
}
|
|
|
|
|
|
const index = name.lastIndexOf(hitTopDomain)
|
|
|
|
|
|
const preArr = name.substring(0, index).split('.')
|
|
|
|
|
|
return [preArr[preArr.length - 2], hitTopDomain].join('.')
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2021-12-14 16:42:45 +08:00
|
|
|
|
export function getCurrentRoute () {
|
|
|
|
|
|
return router.currentRoute && router.currentRoute.path
|
|
|
|
|
|
}
|
2022-02-18 10:07:43 +08:00
|
|
|
|
|
2022-05-06 11:29:13 +08:00
|
|
|
|
export function getEchartsFontSize (e) {
|
|
|
|
|
|
let clientWidth
|
|
|
|
|
|
if (e) {
|
|
|
|
|
|
clientWidth = e.currentTarget.innerWidth
|
|
|
|
|
|
} else {
|
|
|
|
|
|
clientWidth = document.getElementsByTagName('html')[0].clientWidth
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
let echartLegendFontSize = echartsFontSize.legendFirstFontSize
|
|
|
|
|
|
let echartLabelFontSize = echartsFontSize.labelFirstFontSize
|
|
|
|
|
|
if (clientWidth < 1920) {
|
|
|
|
|
|
echartLegendFontSize = echartsFontSize.legendFirstFontSize
|
|
|
|
|
|
echartLabelFontSize = echartsFontSize.labelFirstFontSize
|
|
|
|
|
|
} else if (clientWidth >= 1920 && clientWidth < 2560) {
|
|
|
|
|
|
echartLegendFontSize = echartsFontSize.legendSecondFontSize
|
|
|
|
|
|
echartLabelFontSize = echartsFontSize.labelSecondFontSize
|
|
|
|
|
|
} else if (clientWidth >= 2560) {
|
|
|
|
|
|
echartLegendFontSize = echartsFontSize.legendThirdFontSize
|
|
|
|
|
|
echartLabelFontSize = echartsFontSize.labelThirdFontSize
|
|
|
|
|
|
}
|
|
|
|
|
|
localStorage.setItem(storageKey.echartLegendFontSize, echartLegendFontSize)
|
|
|
|
|
|
localStorage.setItem(storageKey.echartLabelFontSize, echartLabelFontSize)
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
export function handleEchartFontSize (option) {
|
|
|
|
|
|
// echarts相关图表文字动态调整大小
|
|
|
|
|
|
getEchartsFontSize()
|
|
|
|
|
|
const echartLegendFontSize = localStorage.getItem(storageKey.echartLegendFontSize)
|
|
|
|
|
|
const echartLabelFontSize = localStorage.getItem(storageKey.echartLabelFontSize)
|
|
|
|
|
|
let chartOption = option
|
2022-05-06 16:13:27 +08:00
|
|
|
|
const newSeries = []
|
|
|
|
|
|
const chartType = chartOption.series[0].type
|
|
|
|
|
|
chartOption.series.forEach((series) => {
|
2022-05-11 12:37:16 +08:00
|
|
|
|
if (series.markLine) {
|
|
|
|
|
|
const seriesNew = {
|
|
|
|
|
|
...series,
|
2022-05-06 11:29:13 +08:00
|
|
|
|
label: {
|
2022-05-11 12:37:16 +08:00
|
|
|
|
...series.label,
|
2022-05-06 11:29:13 +08:00
|
|
|
|
fontSize: echartLabelFontSize
|
2022-05-11 12:37:16 +08:00
|
|
|
|
},
|
|
|
|
|
|
markLine: {
|
|
|
|
|
|
...series.markLine,
|
|
|
|
|
|
label: {
|
|
|
|
|
|
...series.markLine.label,
|
|
|
|
|
|
fontSize: echartLabelFontSize
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
newSeries.push(seriesNew)
|
|
|
|
|
|
} else {
|
|
|
|
|
|
const seriesNew = {
|
|
|
|
|
|
...series,
|
|
|
|
|
|
label: {
|
|
|
|
|
|
...series.label,
|
|
|
|
|
|
fontSize: echartLabelFontSize
|
|
|
|
|
|
},
|
|
|
|
|
|
markLine: {
|
|
|
|
|
|
label: {
|
|
|
|
|
|
fontSize: echartLabelFontSize
|
|
|
|
|
|
}
|
2022-05-06 11:29:13 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
2022-05-11 12:37:16 +08:00
|
|
|
|
newSeries.push(seriesNew)
|
2022-05-06 16:13:27 +08:00
|
|
|
|
}
|
|
|
|
|
|
})
|
2022-05-06 11:29:13 +08:00
|
|
|
|
|
2022-05-06 16:13:27 +08:00
|
|
|
|
if (chartType === 'pie') {
|
|
|
|
|
|
chartOption = {
|
|
|
|
|
|
...chartOption,
|
|
|
|
|
|
legend: {
|
|
|
|
|
|
...chartOption.legend,
|
|
|
|
|
|
textStyle: {
|
|
|
|
|
|
...chartOption.legend.textStyle,
|
|
|
|
|
|
fontSize: echartLegendFontSize
|
|
|
|
|
|
}
|
|
|
|
|
|
},
|
|
|
|
|
|
axisLabel: {
|
|
|
|
|
|
...chartOption.axisLabel,
|
|
|
|
|
|
fontSize: echartLabelFontSize
|
|
|
|
|
|
},
|
|
|
|
|
|
series: newSeries
|
|
|
|
|
|
}
|
|
|
|
|
|
} else {
|
|
|
|
|
|
chartOption = {
|
|
|
|
|
|
...chartOption,
|
|
|
|
|
|
legend: {
|
|
|
|
|
|
...chartOption.legend,
|
|
|
|
|
|
textStyle: {
|
|
|
|
|
|
...chartOption.legend.textStyle,
|
|
|
|
|
|
fontSize: echartLegendFontSize
|
|
|
|
|
|
}
|
|
|
|
|
|
},
|
|
|
|
|
|
xAxis: {
|
|
|
|
|
|
...chartOption.xAxis,
|
2022-05-06 11:29:13 +08:00
|
|
|
|
axisLabel: {
|
2022-05-06 16:13:27 +08:00
|
|
|
|
...chartOption.xAxis.axisLabel,
|
2022-05-06 11:29:13 +08:00
|
|
|
|
fontSize: echartLabelFontSize
|
2022-05-06 16:13:27 +08:00
|
|
|
|
}
|
|
|
|
|
|
},
|
|
|
|
|
|
yAxis: {
|
|
|
|
|
|
...chartOption.yAxis,
|
2022-05-06 11:29:13 +08:00
|
|
|
|
axisLabel: {
|
2022-05-06 16:13:27 +08:00
|
|
|
|
...chartOption.yAxis.axisLabel,
|
2022-05-06 11:29:13 +08:00
|
|
|
|
fontSize: echartLabelFontSize
|
2022-05-06 16:13:27 +08:00
|
|
|
|
}
|
|
|
|
|
|
},
|
|
|
|
|
|
axisLabel: {
|
|
|
|
|
|
...chartOption.axisLabel,
|
|
|
|
|
|
fontSize: echartLabelFontSize
|
|
|
|
|
|
},
|
|
|
|
|
|
series: newSeries
|
2022-05-06 11:29:13 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
return chartOption
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2022-02-18 10:07:43 +08:00
|
|
|
|
// 判断数据相等
|
|
|
|
|
|
export function arrayIsEqual (arr1, arr2) {
|
|
|
|
|
|
if (arr1 === arr2) { // 如果2个数组对应的指针相同,那么肯定相等,同时也对比一下类型
|
|
|
|
|
|
return true
|
|
|
|
|
|
} else {
|
|
|
|
|
|
if (arr1.length !== arr2.length) {
|
|
|
|
|
|
return false
|
|
|
|
|
|
} else {
|
|
|
|
|
|
for (const i in arr1) { // 循环遍历对比每个位置的元素
|
|
|
|
|
|
if (arr1[i] !== arr2[i]) { // 只要出现一次不相等,那么2个数组就不相等
|
|
|
|
|
|
return false
|
|
|
|
|
|
}
|
|
|
|
|
|
} // for循环完成,没有出现不相等的情况,那么2个数组相等
|
|
|
|
|
|
return true
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2022-04-11 15:58:24 +08:00
|
|
|
|
|
2022-04-27 16:18:29 +08:00
|
|
|
|
// 字体长度缓存记录,{ 'fontSize': { 'limitWidth': { 'text': xxx } } }
|
|
|
|
|
|
const fontCache = {}
|
|
|
|
|
|
// 处理文本超长
|
|
|
|
|
|
export function truncateText (text, limitWidth, fontSize = 12, ellipsis = '...') {
|
|
|
|
|
|
if (!text || !limitWidth) {
|
|
|
|
|
|
return null
|
|
|
|
|
|
}
|
|
|
|
|
|
// hit cache
|
|
|
|
|
|
const cache = fontCache[`${fontSize}`] && fontCache[`${fontSize}`][`${limitWidth}`]
|
|
|
|
|
|
if (cache) {
|
|
|
|
|
|
const hit = Object.keys(cache).find(k => k === text)
|
|
|
|
|
|
if (hit) {
|
|
|
|
|
|
return cache[hit]
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
// 计算
|
|
|
|
|
|
const dom = document.createElement('span')
|
|
|
|
|
|
dom.classList.add('temp-dom')
|
|
|
|
|
|
dom.style.fontSize = `${fontSize}px`
|
|
|
|
|
|
dom.innerText = text
|
|
|
|
|
|
return dom.offsetWidth
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2022-04-11 15:58:24 +08:00
|
|
|
|
export function scrollToTop (dom, toTop, duration, direction) {
|
|
|
|
|
|
const clientHeight = dom.clientHeight
|
|
|
|
|
|
const currentTop = dom.scrollTop
|
|
|
|
|
|
const totalScrollDistance = Math.abs(currentTop - toTop)
|
|
|
|
|
|
let scrollY = currentTop
|
|
|
|
|
|
let oldTimestamp = null
|
|
|
|
|
|
|
|
|
|
|
|
function step (newTimestamp) {
|
|
|
|
|
|
if (oldTimestamp !== null) {
|
|
|
|
|
|
if (direction === 'up') {
|
|
|
|
|
|
scrollY -= totalScrollDistance * (newTimestamp - oldTimestamp) / duration
|
|
|
|
|
|
if (scrollY < 0) {
|
|
|
|
|
|
dom.scrollTop = 0
|
|
|
|
|
|
return
|
|
|
|
|
|
}
|
|
|
|
|
|
dom.scrollTop = scrollY
|
|
|
|
|
|
} else if (direction === 'down') {
|
|
|
|
|
|
scrollY += totalScrollDistance * (newTimestamp - oldTimestamp) / duration
|
|
|
|
|
|
if (scrollY > clientHeight) {
|
|
|
|
|
|
dom.scrollTop = clientHeight
|
|
|
|
|
|
return
|
|
|
|
|
|
}
|
|
|
|
|
|
dom.scrollTop = scrollY
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
oldTimestamp = newTimestamp
|
|
|
|
|
|
window.requestAnimationFrame(step)
|
|
|
|
|
|
}
|
|
|
|
|
|
window.requestAnimationFrame(step)
|
|
|
|
|
|
}
|
2022-08-09 21:19:21 +08:00
|
|
|
|
|
|
|
|
|
|
export function getChainRatio (current, prev) {
|
|
|
|
|
|
if (prev === 0) {
|
|
|
|
|
|
return '-'
|
|
|
|
|
|
} else {
|
|
|
|
|
|
return (current - prev) / prev
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2022-08-19 10:06:27 +08:00
|
|
|
|
|
2022-11-01 14:13:47 +08:00
|
|
|
|
export function computeScore (data) {
|
2022-08-19 10:06:27 +08:00
|
|
|
|
let score = 0
|
|
|
|
|
|
let k = 0
|
2022-11-01 14:13:47 +08:00
|
|
|
|
let totalScore = 0
|
|
|
|
|
|
const scoreArr = []
|
2022-11-03 10:56:06 +08:00
|
|
|
|
let num = 0
|
2022-11-01 14:13:47 +08:00
|
|
|
|
Object.keys(data).forEach(t => {
|
2022-11-03 10:56:06 +08:00
|
|
|
|
if (!data[t]) {
|
|
|
|
|
|
num += 1
|
|
|
|
|
|
}
|
2022-11-01 14:13:47 +08:00
|
|
|
|
if (t === 'establishLatencyMs' || t === 'tcpLostlenPercent' || t === 'pktRetransPercent') {
|
|
|
|
|
|
k = 0.3
|
|
|
|
|
|
} else if (t === 'httpResponseLatency' || t === 'sslConLatency') {
|
|
|
|
|
|
k = 0.05
|
2022-08-19 10:06:27 +08:00
|
|
|
|
}
|
2022-11-01 14:13:47 +08:00
|
|
|
|
if (t === 'establishLatencyMs' || t === 'httpResponseLatency' || t === 'sslConLatency') {
|
|
|
|
|
|
if (!data[t] && data[t] !== 0) {
|
2022-11-01 14:31:28 +08:00
|
|
|
|
score = 1
|
2022-11-01 14:13:47 +08:00
|
|
|
|
} else if (data[t] <= 50) {
|
|
|
|
|
|
score = 1
|
|
|
|
|
|
} else if (data[t] > 200) {
|
|
|
|
|
|
score = 0
|
|
|
|
|
|
} else {
|
|
|
|
|
|
score = (data[t] - 200) / (50 - 200)
|
|
|
|
|
|
}
|
|
|
|
|
|
} else if (t === 'tcpLostlenPercent' || t === 'pktRetransPercent') {
|
|
|
|
|
|
if (!data[t] && data[t] !== 0) {
|
2022-11-01 14:31:28 +08:00
|
|
|
|
score = 1
|
2022-11-01 14:13:47 +08:00
|
|
|
|
} else if (data[t] <= 0.01) {
|
|
|
|
|
|
score = 1
|
|
|
|
|
|
} else if (data[t] > 0.05) {
|
|
|
|
|
|
score = 0
|
|
|
|
|
|
} else {
|
|
|
|
|
|
score = (data[t] - 0.05) / (0.01 - 0.05)
|
|
|
|
|
|
}
|
2022-08-19 10:06:27 +08:00
|
|
|
|
}
|
2022-11-01 14:13:47 +08:00
|
|
|
|
scoreArr.push(score * k)
|
|
|
|
|
|
})
|
|
|
|
|
|
scoreArr.forEach(t => {
|
|
|
|
|
|
totalScore += t
|
|
|
|
|
|
})
|
|
|
|
|
|
totalScore = Math.ceil(totalScore * 6)
|
|
|
|
|
|
if (totalScore > 6) {
|
|
|
|
|
|
totalScore = 6
|
2022-08-19 10:06:27 +08:00
|
|
|
|
}
|
2022-11-03 10:56:06 +08:00
|
|
|
|
if (num === 5) {
|
|
|
|
|
|
return '-'
|
|
|
|
|
|
}
|
2022-11-01 14:13:47 +08:00
|
|
|
|
return totalScore
|
2022-08-19 10:06:27 +08:00
|
|
|
|
}
|
2022-09-07 20:17:38 +08:00
|
|
|
|
|
2022-09-16 17:46:20 +08:00
|
|
|
|
// 改变tab状态(url中):当前tab,
|
|
|
|
|
|
export function changeTabState (param, value) {
|
|
|
|
|
|
const query = router.query
|
|
|
|
|
|
query[param] = JSON.stringify(value)
|
|
|
|
|
|
router.push({
|
|
|
|
|
|
query: query
|
|
|
|
|
|
})
|
|
|
|
|
|
}
|
2022-09-30 07:35:09 +08:00
|
|
|
|
export function getTabList (curTable, curMetric) {
|
|
|
|
|
|
let tabs = []
|
|
|
|
|
|
if (curTable.hasMetricSearch) { // 有metric
|
|
|
|
|
|
const metricsList = curTable ? curTable.metrics : []
|
|
|
|
|
|
if (metricsList && metricsList.length > 0) {
|
|
|
|
|
|
const metricTab = metricsList.find(metric => metric.name === curMetric)
|
|
|
|
|
|
tabs = metricTab.tabs
|
|
|
|
|
|
}
|
|
|
|
|
|
} else { // 无metric
|
|
|
|
|
|
if (curTable.tabs) {
|
|
|
|
|
|
tabs = curTable.tabs
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
return tabs
|
|
|
|
|
|
}
|
2022-11-09 15:22:09 +08:00
|
|
|
|
export async function getDnsMapData (type) {
|
|
|
|
|
|
const codeValueMap = new Map()
|
|
|
|
|
|
const dnsData = await getDictList({ type: type, pageSize: -1 })
|
|
|
|
|
|
if (dnsData && dnsData.length > 0) {
|
2022-11-04 12:18:26 +08:00
|
|
|
|
dnsData.forEach(mapData => {
|
2022-11-09 15:22:09 +08:00
|
|
|
|
const code = mapData.code
|
|
|
|
|
|
if (code.indexOf('-') > -1) {
|
|
|
|
|
|
const range = mapData.code.split('-')
|
|
|
|
|
|
if (range && range.length >= 2) {
|
2022-12-15 17:42:01 +08:00
|
|
|
|
const start = Number(range[0].trim())
|
|
|
|
|
|
const eEnd = Number(range[1].trim())
|
2022-11-04 12:18:26 +08:00
|
|
|
|
for (let i = start; i <= eEnd; i++) {
|
2022-12-15 17:42:01 +08:00
|
|
|
|
mapData.value = (start <= i && i <= eEnd) ? mapData.value : i
|
2022-11-09 15:22:09 +08:00
|
|
|
|
codeValueMap.set(i, mapData.value)
|
2022-11-04 12:18:26 +08:00
|
|
|
|
}
|
2022-11-03 17:51:53 +08:00
|
|
|
|
}
|
2022-11-09 15:22:09 +08:00
|
|
|
|
} else {
|
|
|
|
|
|
codeValueMap.set(code, mapData.value)
|
2022-11-03 17:51:53 +08:00
|
|
|
|
}
|
|
|
|
|
|
})
|
|
|
|
|
|
}
|
2022-11-04 12:18:26 +08:00
|
|
|
|
return codeValueMap
|
2022-11-03 17:51:53 +08:00
|
|
|
|
}
|
2022-12-15 17:42:01 +08:00
|
|
|
|
export function handleSpecialValue (value) {
|
|
|
|
|
|
if (value) {
|
2022-12-08 16:26:01 +08:00
|
|
|
|
value = value.replaceAll("'", "\\\\'")
|
2022-12-15 17:42:01 +08:00
|
|
|
|
.replaceAll('"', '\\"')
|
|
|
|
|
|
.replaceAll('&', '%26')
|
2022-12-08 16:26:01 +08:00
|
|
|
|
}
|
2022-11-17 15:21:17 +08:00
|
|
|
|
return value
|
|
|
|
|
|
}
|
2022-09-23 19:01:30 +08:00
|
|
|
|
export function combineTabList (tableType, list, commonTabList) {
|
|
|
|
|
|
const curTableInCode = networkTable[tableType] ? networkTable[tableType] : networkTable.networkOverview
|
|
|
|
|
|
const listInCode = curTableInCode ? curTableInCode.tabList : []
|
|
|
|
|
|
list.forEach(tab => {
|
|
|
|
|
|
// 配置的内容
|
2022-11-01 09:12:14 +08:00
|
|
|
|
const tabName = tab ? (tab.name ? tab.name : tab) : ''
|
|
|
|
|
|
// 配置的内容
|
|
|
|
|
|
const commonTab = commonTabList.find(item => item.name === tabName)
|
|
|
|
|
|
tab.label = commonTab ? commonTab.i18n : ''
|
|
|
|
|
|
tab.prop = commonTab ? commonTab.prop : ''
|
2022-09-23 19:01:30 +08:00
|
|
|
|
if (!tab.hasOwnProperty('checked')) {
|
2022-11-01 09:12:14 +08:00
|
|
|
|
tab.checked = tab ? tab.show : true
|
|
|
|
|
|
}
|
|
|
|
|
|
if (!tab.hasOwnProperty('disabled')) {
|
|
|
|
|
|
tab.disabled = tab ? !tab.enable : false
|
2022-09-23 19:01:30 +08:00
|
|
|
|
}
|
2022-11-01 09:12:14 +08:00
|
|
|
|
if (!tab.hasOwnProperty('panelId')) {
|
|
|
|
|
|
tab.panelId = tab ? tab.panelIdOfFourthMenu : null
|
|
|
|
|
|
}
|
|
|
|
|
|
// 代码里写死的
|
|
|
|
|
|
const tabInCode = listInCode ? listInCode.find(item => item.label === tab.label) : {}
|
|
|
|
|
|
tab.queryCycleTotalProp = tabInCode ? tabInCode.queryCycleTotalProp : null
|
|
|
|
|
|
tab.dillDownProp = tabInCode ? tabInCode.dillDownProp : []
|
2022-09-23 19:01:30 +08:00
|
|
|
|
})
|
|
|
|
|
|
}
|
2022-11-01 09:12:14 +08:00
|
|
|
|
/*
|
2022-09-23 19:01:30 +08:00
|
|
|
|
export function setUserConfig () {
|
|
|
|
|
|
const userTableConfig = this.getUserLocalConfig()
|
|
|
|
|
|
if (userTableConfig) {
|
|
|
|
|
|
const newTabConfigs = []
|
|
|
|
|
|
userTableConfig.tabConfig.forEach(tab => {
|
|
|
|
|
|
const tabConfig = this.list.find(item => item.name === tab.name)
|
|
|
|
|
|
if (tabConfig) {
|
|
|
|
|
|
tabConfig.checked = tab ? tab.checked : true
|
|
|
|
|
|
} else {
|
|
|
|
|
|
tabConfig.checked = true
|
|
|
|
|
|
}
|
|
|
|
|
|
newTabConfigs.push(tabConfig)
|
|
|
|
|
|
})
|
|
|
|
|
|
this.list = newTabConfigs
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2022-11-01 09:12:14 +08:00
|
|
|
|
*/
|
2022-09-30 07:35:09 +08:00
|
|
|
|
export async function getDefaultCurTab (tableType, metric, columnName) {
|
|
|
|
|
|
const tabList = await getUserDrilldownTableConfig(tableType, metric)
|
|
|
|
|
|
const curTab = tabList.filter(item => item.label === columnName)[0]
|
|
|
|
|
|
return curTab
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2022-11-18 14:21:23 +08:00
|
|
|
|
export async function readDrilldownTableConfigByUser () {
|
2022-11-01 09:12:14 +08:00
|
|
|
|
// 获取用户定制的自定义配置
|
2022-09-30 07:35:09 +08:00
|
|
|
|
const userId = localStorage.getItem(storageKey.userId)
|
2022-12-21 11:40:49 +08:00
|
|
|
|
const userLocalConfig = await db[dbDrilldownTableConfig].get({ id: userId })
|
2022-09-30 07:35:09 +08:00
|
|
|
|
let defaultDrillDownTableConfigs = []
|
2022-12-21 11:40:49 +08:00
|
|
|
|
if (userLocalConfig) {
|
|
|
|
|
|
defaultDrillDownTableConfigs = userLocalConfig.config
|
2022-09-30 07:35:09 +08:00
|
|
|
|
}
|
2022-11-01 09:12:14 +08:00
|
|
|
|
return defaultDrillDownTableConfigs
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2022-11-18 14:21:23 +08:00
|
|
|
|
export async function getConfigVersion (id) {
|
2022-12-21 11:40:49 +08:00
|
|
|
|
let defaultConfigInDb = await db[dbDrilldownTableConfig].get({ id: id })
|
|
|
|
|
|
if (!defaultConfigInDb) {
|
|
|
|
|
|
defaultConfigInDb = await db[dbDrilldownTableConfig].get({ id: 'default' })
|
2022-11-18 14:21:23 +08:00
|
|
|
|
}
|
2022-12-21 11:40:49 +08:00
|
|
|
|
return defaultConfigInDb.version || ''
|
2022-11-18 14:21:23 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2022-12-21 11:40:49 +08:00
|
|
|
|
export async function combineDrilldownTableWithUserConfig () {
|
|
|
|
|
|
const defaultConfigInDb = await db[dbDrilldownTableConfig].get({ id: 'default' })
|
|
|
|
|
|
const defaultConfigGroup = defaultConfigInDb ? defaultConfigInDb.config : []
|
2022-12-15 17:42:01 +08:00
|
|
|
|
const currentUserConfigGroup = await readDrilldownTableConfigByUser()
|
|
|
|
|
|
if (defaultConfigGroup && currentUserConfigGroup && currentUserConfigGroup.length > 0) {
|
|
|
|
|
|
defaultConfigGroup.forEach(defaultConfig => {
|
|
|
|
|
|
const currentUserConfig = currentUserConfigGroup.find(config => config.route === defaultConfig.route)
|
|
|
|
|
|
if (currentUserConfig) {
|
|
|
|
|
|
const defaultTableConfig = defaultConfig.tables.find(table => table.id === defaultConfig.route)
|
|
|
|
|
|
const currentUserTableConfig = currentUserConfig.tables.find(table => table.id === defaultConfig.route)
|
|
|
|
|
|
defaultTableConfig.hiddenColumns = currentUserTableConfig.hiddenColumns
|
|
|
|
|
|
const sortTabs = []
|
|
|
|
|
|
currentUserTableConfig.tabs.forEach(currentUserTab => {
|
|
|
|
|
|
const defaultTab = defaultTableConfig.tabs.find(tab => tab.name === currentUserTab.name)
|
|
|
|
|
|
if (defaultTab) {
|
|
|
|
|
|
defaultTab.hiddenDrilldownTabs = currentUserTab.hiddenDrilldownTabs
|
|
|
|
|
|
defaultTab.checked = currentUserTab.checked
|
|
|
|
|
|
if (defaultTab && defaultTab.hasMetricSearch === true) {
|
|
|
|
|
|
defaultTab.metrics.forEach(metric => {
|
2022-12-21 11:40:49 +08:00
|
|
|
|
if (currentUserTableConfig.columns) {
|
2022-12-20 16:10:28 +08:00
|
|
|
|
const sortColumns = []
|
|
|
|
|
|
sortColumns.push(metric.columns[0])
|
|
|
|
|
|
currentUserTableConfig.columns.forEach((column, index) => {
|
|
|
|
|
|
const sortColumn = metric.columns.find(metricColumn => {
|
|
|
|
|
|
if (metricColumn.name) {
|
|
|
|
|
|
return metricColumn.name === column
|
|
|
|
|
|
} else {
|
|
|
|
|
|
return metricColumn === column
|
|
|
|
|
|
}
|
|
|
|
|
|
})
|
|
|
|
|
|
if (sortColumn) {
|
|
|
|
|
|
sortColumns.push(sortColumn)
|
|
|
|
|
|
}
|
|
|
|
|
|
})
|
|
|
|
|
|
metric.columns = sortColumns
|
|
|
|
|
|
}
|
|
|
|
|
|
})
|
|
|
|
|
|
} else {
|
2022-12-21 11:40:49 +08:00
|
|
|
|
if (currentUserTableConfig.columns) {
|
2022-12-15 17:42:01 +08:00
|
|
|
|
const sortColumns = []
|
2022-12-20 16:10:28 +08:00
|
|
|
|
sortColumns.push(defaultTab.columns[0])
|
2022-12-15 17:42:01 +08:00
|
|
|
|
currentUserTableConfig.columns.forEach((column, index) => {
|
2022-12-20 16:10:28 +08:00
|
|
|
|
const sortColumn = defaultTab.columns.find(metricColumn => {
|
2022-12-15 17:42:01 +08:00
|
|
|
|
if (metricColumn.name) {
|
|
|
|
|
|
return metricColumn.name === column
|
|
|
|
|
|
} else {
|
|
|
|
|
|
return metricColumn === column
|
|
|
|
|
|
}
|
|
|
|
|
|
})
|
|
|
|
|
|
if (sortColumn) {
|
|
|
|
|
|
sortColumns.push(sortColumn)
|
|
|
|
|
|
}
|
|
|
|
|
|
})
|
2022-12-20 16:10:28 +08:00
|
|
|
|
defaultTab.columns = sortColumns
|
|
|
|
|
|
}
|
2022-12-15 17:42:01 +08:00
|
|
|
|
}
|
|
|
|
|
|
sortTabs.push(defaultTab)
|
2022-11-10 15:29:12 +08:00
|
|
|
|
}
|
2022-11-01 09:12:14 +08:00
|
|
|
|
})
|
2022-12-15 17:42:01 +08:00
|
|
|
|
defaultTableConfig.tabs = sortTabs
|
2022-11-01 09:12:14 +08:00
|
|
|
|
}
|
|
|
|
|
|
})
|
|
|
|
|
|
}
|
2022-12-15 17:42:01 +08:00
|
|
|
|
return defaultConfigGroup
|
2022-11-01 09:12:14 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
export async function getUserDrilldownTableConfig (tableType, curMetric) {
|
|
|
|
|
|
let list = []
|
|
|
|
|
|
// 获取用户定制的自定义配置,如果没有,则使用默认的自定义配置
|
2022-12-21 11:40:49 +08:00
|
|
|
|
const drillDownTableConfigs = await combineDrilldownTableWithUserConfig()
|
2022-11-01 09:12:14 +08:00
|
|
|
|
const currentTableConfig = drillDownTableConfigs.find(config => config.route === tableType)
|
2022-09-23 19:01:30 +08:00
|
|
|
|
const commonTabList = currentTableConfig ? currentTableConfig.tabs : []
|
|
|
|
|
|
const tables = currentTableConfig ? currentTableConfig.tables : []
|
|
|
|
|
|
if (tables && tables.length > 0) {
|
|
|
|
|
|
const curTableOldConfig = tables.find(table => table.id === tableType)
|
|
|
|
|
|
const curTable = curTableOldConfig || null
|
|
|
|
|
|
if (curTable) {
|
2022-11-01 09:12:14 +08:00
|
|
|
|
list = curTable ? curTable.tabs : []
|
2022-09-23 19:01:30 +08:00
|
|
|
|
combineTabList(tableType, list, commonTabList)
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
return list
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2022-09-07 20:17:38 +08:00
|
|
|
|
// cleanOldParams: true|false,是否清除oldParams
|
|
|
|
|
|
export function urlParamsHandler (url, oldParams, newParams, cleanOldParams) {
|
|
|
|
|
|
let newUrl = url.split('?')[0]
|
|
|
|
|
|
let params
|
|
|
|
|
|
if (cleanOldParams) {
|
|
|
|
|
|
params = newParams
|
|
|
|
|
|
} else {
|
|
|
|
|
|
params = Object.assign(oldParams, newParams)
|
|
|
|
|
|
}
|
|
|
|
|
|
if (Object.keys(params).length > 0) {
|
|
|
|
|
|
newUrl += '?'
|
|
|
|
|
|
Object.keys(params).forEach(key => {
|
2022-09-07 20:41:55 +08:00
|
|
|
|
newUrl += `${key}=${params[key]}&`
|
2022-09-07 20:17:38 +08:00
|
|
|
|
})
|
|
|
|
|
|
newUrl = newUrl.substring(0, newUrl.length - 1)
|
|
|
|
|
|
}
|
|
|
|
|
|
return newUrl
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
export function overwriteUrl (url) {
|
2022-12-20 10:54:38 +08:00
|
|
|
|
window.history.replaceState({}, '', url)
|
2022-09-07 20:17:38 +08:00
|
|
|
|
}
|
2022-09-10 23:13:42 +08:00
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
|
startColor: 渐变起始颜色,对应最大值
|
|
|
|
|
|
endColor: 渐变结束颜色,对应最小值
|
|
|
|
|
|
values: 从大到小排好序的数值
|
|
|
|
|
|
*/
|
|
|
|
|
|
export function colorGradientCalculation (startColor, endColor, values) {
|
|
|
|
|
|
const colors = []
|
|
|
|
|
|
const startRgbArr = colorHexToRgbArr(startColor)
|
|
|
|
|
|
const endRgbArr = colorHexToRgbArr(endColor)
|
|
|
|
|
|
const rDiff = endRgbArr[0] - startRgbArr[0]
|
|
|
|
|
|
const gDiff = endRgbArr[1] - startRgbArr[1]
|
|
|
|
|
|
const bDiff = endRgbArr[2] - startRgbArr[2]
|
|
|
|
|
|
const valueDiff = values[0] - values[values.length - 1]
|
|
|
|
|
|
values.forEach((v, i) => {
|
|
|
|
|
|
colors.push(`rgb(${startRgbArr[0] + Math.floor(rDiff * (valueDiff - diff(v)) / valueDiff)},${startRgbArr[1] + Math.floor(gDiff * (valueDiff - diff(v)) / valueDiff)},${startRgbArr[2] + Math.floor(bDiff * (valueDiff - diff(v)) / valueDiff)})`)
|
|
|
|
|
|
})
|
|
|
|
|
|
function diff (v) {
|
|
|
|
|
|
return v - values[values.length - 1]
|
|
|
|
|
|
}
|
|
|
|
|
|
return colors
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// returns an array like [11,22,33]
|
|
|
|
|
|
export function colorHexToRgbArr (hex) {
|
|
|
|
|
|
return [1, 3, 5].map((h) => parseInt(hex.substring(h, h + 2), 16))
|
|
|
|
|
|
}
|