mirror of https://github.com/veops/cmdb.git
模型关联 展示反向关系
This commit is contained in:
parent
78c542e71d
commit
d8646f8e7c
|
@ -18,18 +18,30 @@
|
||||||
keep-source
|
keep-source
|
||||||
:max-height="windowHeight - 180"
|
:max-height="windowHeight - 180"
|
||||||
class="ops-stripe-table"
|
class="ops-stripe-table"
|
||||||
|
:row-class-name="rowClass"
|
||||||
>
|
>
|
||||||
<vxe-column field="source_ci_type_name" title="源模型英文名"></vxe-column>
|
<vxe-column field="source_ci_type_name" title="源模型英文名"></vxe-column>
|
||||||
<vxe-column field="relation_type" title="关联类型"></vxe-column>
|
<vxe-column field="relation_type" title="关联类型">
|
||||||
|
<template #default="{row}">
|
||||||
|
<span style="color:#2f54eb" v-if="row.isParent">被</span>
|
||||||
|
{{ row.relation_type }}
|
||||||
|
</template>
|
||||||
|
</vxe-column>
|
||||||
<vxe-column field="alias" title="目标模型名"></vxe-column>
|
<vxe-column field="alias" title="目标模型名"></vxe-column>
|
||||||
<vxe-column field="constraint" title="关系约束">
|
<vxe-column field="constraint" title="关系约束">
|
||||||
<template #default="{row}">
|
<template #default="{row}">
|
||||||
<span>{{ constraintMap[row.constraint] }}</span>
|
<span v-if="row.isParent && constraintMap[row.constraint]">{{
|
||||||
|
constraintMap[row.constraint]
|
||||||
|
.split('')
|
||||||
|
.reverse()
|
||||||
|
.join('')
|
||||||
|
}}</span>
|
||||||
|
<span v-else>{{ constraintMap[row.constraint] }}</span>
|
||||||
</template>
|
</template>
|
||||||
</vxe-column>
|
</vxe-column>
|
||||||
<vxe-column field="operation" title="操作" width="100">
|
<vxe-column field="operation" title="操作" width="100">
|
||||||
<template #default="{row}">
|
<template #default="{row}">
|
||||||
<a-space>
|
<a-space v-if="!row.isParent && row.source_ci_type_id">
|
||||||
<a @click="handleOpenGrant(row)"><a-icon type="user-add"/></a>
|
<a @click="handleOpenGrant(row)"><a-icon type="user-add"/></a>
|
||||||
<a-popconfirm title="确认删除?" @confirm="handleDelete(row)">
|
<a-popconfirm title="确认删除?" @confirm="handleDelete(row)">
|
||||||
<a style="color: red;"><a-icon type="delete"/></a>
|
<a style="color: red;"><a-icon type="delete"/></a>
|
||||||
|
@ -37,6 +49,12 @@
|
||||||
</a-space>
|
</a-space>
|
||||||
</template>
|
</template>
|
||||||
</vxe-column>
|
</vxe-column>
|
||||||
|
<template #empty>
|
||||||
|
<div>
|
||||||
|
<img :style="{ width: '100px' }" :src="require('@/assets/data_empty.png')" />
|
||||||
|
<div>暂无数据</div>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
</vxe-table>
|
</vxe-table>
|
||||||
<a-modal
|
<a-modal
|
||||||
:closable="false"
|
:closable="false"
|
||||||
|
@ -95,7 +113,13 @@
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
import { createRelation, deleteRelation, getCITypeChildren, getRelationTypes } from '@/modules/cmdb/api/CITypeRelation'
|
import {
|
||||||
|
createRelation,
|
||||||
|
deleteRelation,
|
||||||
|
getCITypeChildren,
|
||||||
|
getCITypeParent,
|
||||||
|
getRelationTypes,
|
||||||
|
} from '@/modules/cmdb/api/CITypeRelation'
|
||||||
import { getCITypes } from '@/modules/cmdb/api/CIType'
|
import { getCITypes } from '@/modules/cmdb/api/CIType'
|
||||||
import CMDBGrant from '../../components/cmdbGrant'
|
import CMDBGrant from '../../components/cmdbGrant'
|
||||||
|
|
||||||
|
@ -127,6 +151,7 @@ export default {
|
||||||
'2': '多对多',
|
'2': '多对多',
|
||||||
},
|
},
|
||||||
tableData: [],
|
tableData: [],
|
||||||
|
parentTableData: [],
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
computed: {
|
computed: {
|
||||||
|
@ -137,12 +162,25 @@ export default {
|
||||||
return this.$store.state.windowHeight
|
return this.$store.state.windowHeight
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
mounted() {
|
async mounted() {
|
||||||
this.getCITypes()
|
this.getCITypes()
|
||||||
this.getRelationTypes()
|
this.getRelationTypes()
|
||||||
|
await this.getCITypeParent()
|
||||||
this.getData()
|
this.getData()
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
|
async getCITypeParent() {
|
||||||
|
await getCITypeParent(this.CITypeId).then((res) => {
|
||||||
|
this.parentTableData = res.parents.map((item) => {
|
||||||
|
return {
|
||||||
|
...item,
|
||||||
|
source_ci_type_name: this.CITypeName,
|
||||||
|
source_ci_type_id: this.CITypeId,
|
||||||
|
isParent: true,
|
||||||
|
}
|
||||||
|
})
|
||||||
|
})
|
||||||
|
},
|
||||||
getData() {
|
getData() {
|
||||||
getCITypeChildren(this.CITypeId).then((res) => {
|
getCITypeChildren(this.CITypeId).then((res) => {
|
||||||
const data = res.children.map((obj) => {
|
const data = res.children.map((obj) => {
|
||||||
|
@ -152,7 +190,11 @@ export default {
|
||||||
source_ci_type_id: this.CITypeId,
|
source_ci_type_id: this.CITypeId,
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
if (this.parentTableData && this.parentTableData.length) {
|
||||||
|
this.tableData = [...data, { isDivider: true }, ...this.parentTableData]
|
||||||
|
} else {
|
||||||
this.tableData = data
|
this.tableData = data
|
||||||
|
}
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
getCITypes() {
|
getCITypes() {
|
||||||
|
@ -217,8 +259,25 @@ export default {
|
||||||
filterOption(input, option) {
|
filterOption(input, option) {
|
||||||
return option.componentOptions.children[0].text.toLowerCase().indexOf(input.toLowerCase()) >= 0
|
return option.componentOptions.children[0].text.toLowerCase().indexOf(input.toLowerCase()) >= 0
|
||||||
},
|
},
|
||||||
|
rowClass({ row }) {
|
||||||
|
if (row.isDivider) return 'relation-table-divider'
|
||||||
|
if (row.isParent) return 'relation-table-parent'
|
||||||
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<style lang="less" scoped></style>
|
<style lang="less">
|
||||||
|
.ops-stripe-table .vxe-body--row.row--stripe.relation-table-divider {
|
||||||
|
background-color: #b1b8d3 !important;
|
||||||
|
}
|
||||||
|
.ops-stripe-table .vxe-body--row.relation-table-parent {
|
||||||
|
background-color: #f5f8ff !important;
|
||||||
|
}
|
||||||
|
.relation-table-divider {
|
||||||
|
td {
|
||||||
|
height: 1px !important;
|
||||||
|
line-height: 1px !important;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
</style>
|
||||||
|
|
Loading…
Reference in New Issue