fix: operation history table

This commit is contained in:
songlh 2024-06-14 17:27:13 +08:00
parent 735ddb334c
commit 6437af19b9
3 changed files with 112 additions and 55 deletions

View File

@ -416,6 +416,9 @@ const cmdb_en = {
itsmUninstalled: 'Please use it in combination with VE ITSM', itsmUninstalled: 'Please use it in combination with VE ITSM',
applyItsm: 'Free Apply ITSM', applyItsm: 'Free Apply ITSM',
ticketId: 'Ticket ID', ticketId: 'Ticket ID',
addReconciliation: 'Add Reconciliation',
updateReconciliation: 'Update Reconciliation',
deleteReconciliation: 'Delete Reconciliation',
}, },
relation_type: { relation_type: {
addRelationType: 'New', addRelationType: 'New',

View File

@ -416,6 +416,9 @@ const cmdb_zh = {
itsmUninstalled: '请结合维易ITSM使用', itsmUninstalled: '请结合维易ITSM使用',
applyItsm: '免费申请', applyItsm: '免费申请',
ticketId: '工单ID', ticketId: '工单ID',
addReconciliation: '新增合规检查',
updateReconciliation: '修改合规检查',
deleteReconciliation: '删除合规检查',
}, },
relation_type: { relation_type: {
addRelationType: '新增关系类型', addRelationType: '新增关系类型',

View File

@ -162,6 +162,9 @@ export default {
{ [this.$t('cmdb.history.deleteUniqueConstraint')]: 11 }, { [this.$t('cmdb.history.deleteUniqueConstraint')]: 11 },
{ [this.$t('cmdb.history.addRelation')]: 12 }, { [this.$t('cmdb.history.addRelation')]: 12 },
{ [this.$t('cmdb.history.deleteRelation')]: 13 }, { [this.$t('cmdb.history.deleteRelation')]: 13 },
{ [this.$t('cmdb.history.addReconciliation')]: 14 },
{ [this.$t('cmdb.history.updateReconciliation')]: 15 },
{ [this.$t('cmdb.history.deleteReconciliation')]: 16 },
], ],
}, },
], ],
@ -198,6 +201,9 @@ export default {
['11', this.$t('cmdb.history.deleteUniqueConstraint')], ['11', this.$t('cmdb.history.deleteUniqueConstraint')],
['12', this.$t('cmdb.history.addRelation')], ['12', this.$t('cmdb.history.addRelation')],
['13', this.$t('cmdb.history.deleteRelation')], ['13', this.$t('cmdb.history.deleteRelation')],
['14', this.$t('cmdb.history.addReconciliation')],
['15', this.$t('cmdb.history.updateReconciliation')],
['16', this.$t('cmdb.history.deleteReconciliation')],
]) ])
}, },
}, },
@ -312,27 +318,22 @@ export default {
// update CIType // update CIType
case '1': { case '1': {
item.changeArr = [] item.changeArr = []
for (const key in item.change.old) { const diffs = this.deepCompare({
const newVal = item.change.new[key] obj1: item?.change?.old,
const oldVal = item.change.old[key] obj2: item?.change?.new,
if (!_.isEqual(newVal, oldVal) && key !== 'updated_at') { ignoreKeys: ['updated_at']
if (oldVal === null) { })
const str = ` [ ${key} : ${newVal || '""'} ] ` for (const val of diffs) {
item.changeDescription += str const str = ` [ ${val.path} : ${val.value1} -> ${val.value2} ] `
item.changeArr.push(str) item.changeDescription += str
} else { item.changeArr.push(str)
const str = ` [ ${key} : ${oldVal || '""'} -> ${newVal || '""'} ] `
item.changeDescription += ` [ ${key} : ${oldVal || '""'} -> ${newVal || '""'} ] `
item.changeArr.push(str)
}
}
} }
if (!item.changeDescription) item.changeDescription = this.$t('cmdb.history.noModifications') if (!item.changeDescription) item.changeDescription = this.$t('cmdb.history.noModifications')
break break
} }
// delete CIType // delete CIType
case '2': { case '2': {
item.changeDescription = this.$t('cmdb.history.addCIType') + ': ' + `${item.change.alias}` item.changeDescription = this.$t('cmdb.history.deleteCIType') + ': ' + `${item.change.alias}`
break break
} }
// add Attribute // add Attribute
@ -343,24 +344,15 @@ export default {
// update Attribute // update Attribute
case '4': { case '4': {
item.changeArr = [] item.changeArr = []
for (const key in item.change.old) { const diffs = this.deepCompare({
if (!_.isEqual(item.change.new[key], item.change.old[key]) && key !== 'updated_at') { obj1: item?.change?.old,
let newStr = item.change.new[key] obj2: item?.change?.new,
let oldStr = item.change.old[key] ignoreKeys: ['updated_at']
if (key === 'choice_value') { })
newStr = newStr ? newStr.map((item) => item[0]).join(',') : '' for (const val of diffs) {
oldStr = oldStr ? oldStr.map((item) => item[0]).join(',') : '' const str = ` [ ${val.path} : ${val.value1} -> ${val.value2} ] `
} item.changeDescription += str
if (Object.prototype.toString.call(newStr) === '[object Object]') { item.changeArr.push(str)
newStr = JSON.stringify(newStr)
}
if (Object.prototype.toString.call(oldStr) === '[object Object]') {
oldStr = JSON.stringify(oldStr)
}
const str = `${key} : ${oldStr ? ` ${oldStr || '""'} ` : ''} -> ${newStr || '""'}`
item.changeDescription += ` [ ${str} ] `
item.changeArr.push(str)
}
} }
if (!item.changeDescription) item.changeDescription = this.$t('cmdb.history.noModifications') if (!item.changeDescription) item.changeDescription = this.$t('cmdb.history.noModifications')
break break
@ -372,39 +364,29 @@ export default {
} }
// add trigger // add trigger
case '6': { case '6': {
item.changeDescription = this.$t('cmdb.history.noModifications', { item.changeDescription = `${this.$t('cmdb.history.addTrigger')}${item?.change?.option?.name || ''}`
attr_id: item.change.attr_id,
before_days: item.change.option.before_days,
subject: item.change.option.subject,
body: item.change.option.body,
notify_at: item.change.option.notify_at,
})
break break
} }
// update trigger // update trigger
case '7': { case '7': {
item.changeArr = [] item.changeArr = []
for (const key in item.change.old.option) { const diffs = this.deepCompare({
const newVal = item.change.new.option[key] obj1: item?.change?.old,
const oldVal = item.change.old.option[key] obj2: item?.change?.new,
if (!_.isEqual(newVal, oldVal) && key !== 'updated_at') { directDeepKeys: ['notifies'],
const str = ` [ ${key} : ${oldVal} -> ${newVal} ] ` ignoreKeys: ['updated_at']
item.changeDescription += str })
item.changeArr.push(str) for (const val of diffs) {
} const str = ` [ ${val.path} : ${val.value1} -> ${val.value2} ] `
item.changeDescription += str
item.changeArr.push(str)
} }
if (!item.changeDescription) item.changeDescription = this.$t('cmdb.history.noModifications') if (!item.changeDescription) item.changeDescription = this.$t('cmdb.history.noModifications')
break break
} }
// delete trigger // delete trigger
case '8': { case '8': {
item.changeDescription = this.$t('cmdb.history.noModifications', { item.changeDescription = `${this.$t('cmdb.history.deleteTrigger')}${item?.change?.option?.name || ''}`
attr_id: item.change.attr_id,
before_days: item.change.option.before_days,
subject: item.change.option.subject,
body: item.change.option.body,
notify_at: item.change.option.notify_at,
})
break break
} }
// add unique constraint // add unique constraint
@ -441,8 +423,77 @@ export default {
)} -> ${item.change.child.alias}` )} -> ${item.change.child.alias}`
break break
} }
case '14': {
item.changeDescription = this.$t('cmdb.history.addReconciliation') + ': ' + item.change.name || item.change.alias
break
}
case '15': {
item.changeArr = []
const diffs = this.deepCompare({
obj1: item?.change?.old,
obj2: item?.change?.new,
directDeepKeys: ['notifies'],
ignoreKeys: ['updated_at']
})
for (const val of diffs) {
const str = ` [ ${val.path} : ${val.value1} -> ${val.value2} ] `
item.changeDescription += str
item.changeArr.push(str)
}
if (!item.changeDescription) item.changeDescription = this.$t('cmdb.history.updateReconciliation')
break
}
case '16': {
item.changeDescription = this.$t('cmdb.history.deleteReconciliation') + ': ' + item.change.name || item.change.alias
break
}
} }
}, },
deepCompare({
obj1,
obj2,
directDeepKeys = [],
ignoreKeys = [],
}) {
const diffs = []
function compare(obj1, obj2, path = '') {
if (typeof obj1 !== 'object' || typeof obj2 !== 'object' || obj1 === null || obj2 === null) {
if (obj1 !== obj2) {
diffs.push({ path, value1: formatValue(obj1), value2: formatValue(obj2) })
}
return
}
const keys1 = new Set(Object.keys(obj1))
const keys2 = new Set(Object.keys(obj2))
const allKeys = new Set([...keys1, ...keys2])
allKeys.forEach(key => {
const newPath = path ? `${path}.${key}` : key
if (!ignoreKeys.includes(key)) {
if (directDeepKeys.includes(key) && !_.isEqual(obj1[key], obj2[key])) {
diffs.push({ path: newPath, value1: formatValue(obj1[key]), value2: formatValue(obj2[key]) })
} else if (!keys1.has(key)) {
diffs.push({ path: newPath, value1: undefined, value2: formatValue(obj2[key]) })
} else if (!keys2.has(key)) {
diffs.push({ path: newPath, value1: formatValue(obj1[key]), value2: undefined })
} else {
compare(obj1[key], obj2[key], newPath)
}
}
})
}
function formatValue(val) {
return _.isObject(val) ? JSON.stringify(val) : val
}
compare(obj1, obj2)
return diffs
},
filterOperate() { filterOperate() {
this.queryParams.page = 1 this.queryParams.page = 1
this.queryParams.page_size = 50 this.queryParams.page_size = 50