fix(ui): load ci type error

This commit is contained in:
songlh 2024-06-28 17:42:10 +08:00
parent c1813f525d
commit 688f4e0ea4
4 changed files with 31 additions and 5 deletions

View File

@ -252,6 +252,8 @@ export default {
cursor: pointer; cursor: pointer;
position: relative; position: relative;
min-width: 100px;
text-align: center;
&:hover { &:hover {
background-color: @layout-sidebar-selected-color; background-color: @layout-sidebar-selected-color;

View File

@ -645,7 +645,7 @@ export default {
width: 100%; width: 100%;
display: flex; display: flex;
flex-wrap: wrap; flex-wrap: wrap;
justify-content: space-between; justify-content: flex-start;
min-height: 20px; min-height: 20px;
> i { > i {
width: 182px; width: 182px;

View File

@ -14,17 +14,18 @@
<TriggerTable ref="triggerTable" :CITypeId="CITypeId"></TriggerTable> <TriggerTable ref="triggerTable" :CITypeId="CITypeId"></TriggerTable>
</a-tab-pane> </a-tab-pane>
<a-tab-pane key="6" :tab="$t('cmdb.ciType.grant')"> <a-tab-pane key="6" :tab="$t('cmdb.ciType.grant')">
<template v-if="activeKey === '6'"> <div class="grant-config-wrap" :style="{ maxHeight: `${windowHeight - 150}px` }" v-if="activeKey === '6'">
<GrantComp :CITypeId="CITypeId" resourceType="CIType" :resourceTypeName="CITypeName"></GrantComp> <GrantComp :CITypeId="CITypeId" resourceType="CIType" :resourceTypeName="CITypeName"></GrantComp>
<div class="citype-detail-title">{{ $t('cmdb.components.relationGrant') }}</div> <div class="citype-detail-title">{{ $t('cmdb.components.relationGrant') }}</div>
<RelationTable isInGrantComp :CITypeId="CITypeId" :CITypeName="CITypeName"></RelationTable> <RelationTable isInGrantComp :CITypeId="CITypeId" :CITypeName="CITypeName"></RelationTable>
</template> </div>
</a-tab-pane> </a-tab-pane>
</a-tabs> </a-tabs>
</a-card> </a-card>
</template> </template>
<script> <script>
import { mapState } from 'vuex'
import AttributesTable from './attributesTable' import AttributesTable from './attributesTable'
import RelationTable from './relationTable' import RelationTable from './relationTable'
import TriggerTable from './triggerTable.vue' import TriggerTable from './triggerTable.vue'
@ -57,6 +58,11 @@ export default {
}, },
beforeCreate() {}, beforeCreate() {},
mounted() {}, mounted() {},
computed: {
...mapState({
windowHeight: (state) => state.windowHeight,
}),
},
methods: { methods: {
changeTab(activeKey) { changeTab(activeKey) {
this.activeKey = activeKey this.activeKey = activeKey
@ -81,4 +87,7 @@ export default {
margin-left: 20px; margin-left: 20px;
margin-bottom: 10px; margin-bottom: 10px;
} }
.grant-config-wrap {
overflow: auto;
}
</style> </style>

View File

@ -586,7 +586,7 @@ export default {
searchResourceType({ page_size: 9999, app_id: 'cmdb' }).then((res) => { searchResourceType({ page_size: 9999, app_id: 'cmdb' }).then((res) => {
this.resource_type = { groups: res.groups, id2perms: res.id2perms } this.resource_type = { groups: res.groups, id2perms: res.id2perms }
}) })
this.loadCITypes(!_currentId) this.loadCITypes(!_currentId, true)
this.getAttributes() this.getAttributes()
}, },
methods: { methods: {
@ -598,7 +598,7 @@ export default {
handleSearch(e) { handleSearch(e) {
this.searchValue = e.target.value this.searchValue = e.target.value
}, },
async loadCITypes(isResetCurrentId = false) { async loadCITypes(isResetCurrentId = false, isInit = false) {
const groups = await getCITypeGroupsConfig({ need_other: true }) const groups = await getCITypeGroupsConfig({ need_other: true })
let alreadyReset = false let alreadyReset = false
if (isResetCurrentId) { if (isResetCurrentId) {
@ -618,6 +618,21 @@ export default {
g.ci_types = [] g.ci_types = []
} }
}) })
if (isInit) {
const isMatch = groups.some((g) => {
const matchGroup = `${g?.id}%null%null` === this.currentId
const matchCITypes = g?.ci_types?.some((item) => `${g?.id}%${item?.id}%${item?.name}` === this.currentId)
return matchGroup || matchCITypes
})
if (!isMatch) {
if (groups?.[0]?.ci_types?.[0]?.id) {
this.currentId = `${groups[0].id}%${groups[0].ci_types[0].id}%${groups[0].ci_types[0].name}`
}
}
}
this.CITypeGroups = groups this.CITypeGroups = groups
localStorage.setItem('ops_cityps_currentId', this.currentId) localStorage.setItem('ops_cityps_currentId', this.currentId)
}) })