55 <div class =" ci-relation-table-wrap" >
66 <div class =" ci-relation-table-tab" >
77 <div
8- v-for =" (item) in tabList"
9- :key =" item.value"
10- :class =" `tab-item ${item.value === currentTab ? 'tab-item-active' : ''}`"
11- @click =" clickTab(item.value)"
8+ v-for =" (group) in tabList"
9+ :key =" group.key"
10+ class =" tab-group"
1211 >
13- <span class =" tab-item-name" >
14- <a-tooltip :title =" item.name" >
15- <span class =" tab-item-name-text" >{{ item.name }}</span >
16- </a-tooltip >
12+ <div
13+ v-if =" group.name"
14+ class =" tab-group-name"
15+ >
16+ {{ group.name }}
17+ </div >
18+ <div
19+ v-for =" (item) in group.list"
20+ :key =" item.key"
21+ :class =" `tab-item ${item.key === currentTab ? 'tab-item-active' : ''}`"
22+ :style =" {
23+ paddingLeft: item.key === 'all' ? '8px' : '16px'
24+ }"
25+ @click =" clickTab(item.key)"
26+ >
27+ <span class =" tab-item-name" >
28+ <a-tooltip :title =" item.name" >
29+ <span class =" tab-item-name-text" >{{ item.name }}</span >
30+ </a-tooltip >
31+ <span
32+ v-if =" item.count"
33+ class =" tab-item-name-count"
34+ >
35+ ({{ item.count }})
36+ </span >
37+ </span >
1738 <span
18- v-if =" item.count"
19- class =" tab-item-name-count"
39+ v-if =" item.key === currentTab && item.showAdd"
40+ class =" tab-item-add"
41+ @click =" openAddModal(item)"
2042 >
21- ({{ item.count }})
43+ < a-icon type = " plus " />
2244 </span >
23- </span >
24- <span
25- v-if =" item.value === currentTab && item.showAdd"
26- class =" tab-item-add"
27- @click =" openAddModal(item)"
28- >
29- <a-icon type =" plus" />
30- </span >
45+ </div >
3146 </div >
3247 </div >
3348
3752 >
3853 <div
3954 v-for =" (item) in tableIDList"
40- :key =" item.id "
55+ :key =" item.key "
4156 class =" ci-relation-table-item"
4257 >
4358 <div
5166 <vxe-grid
5267 bordered
5368 size =" mini"
54- :columns =" allColumns[item.id ]"
55- :data =" allCIList[item.id ]"
69+ :columns =" allColumns[item.value ]"
70+ :data =" allCIList[item.key ]"
5671 overflow
5772 showOverflow =" tooltip"
5873 showHeaderOverflow =" tooltip"
7792 @confirm =" deleteRelation(row)"
7893 >
7994 <a
80- :disabled =" !allCanEdit[item.id ]"
95+ :disabled =" !allCanEdit[item.value ]"
8196 :style =" {
82- color: !allCanEdit[item.id ] ? 'rgba(0, 0, 0, 0.25)' : 'red',
97+ color: !allCanEdit[item.value ] ? 'rgba(0, 0, 0, 0.25)' : 'red',
8398 }"
8499 >
85100 <a-icon type =" delete" />
@@ -105,6 +120,9 @@ import { getSubscribeAttributes } from '@/modules/cmdb/api/preference'
105120import CIDetailTableTitle from ' ./ciDetailTableTitle.vue'
106121import AddTableModal from ' @/modules/cmdb/views/relation_views/modules/AddTableModal.vue'
107122
123+ const PARENT_KEY = ' parents'
124+ const CHILDREN_KEY = ' children'
125+
108126export default {
109127 name: ' CIRelationTable' ,
110128 components: {
@@ -151,24 +169,26 @@ export default {
151169 },
152170
153171 computed: {
172+ tabListFlat () {
173+ return this .tabList .reduce ((list , group ) => list .concat (group .list ), [])
174+ },
154175 tableIDList () {
155- let baseIDs = []
156-
157- switch (this .currentTab ) {
158- case ' all' :
159- baseIDs = this .tabList .filter ((item ) => item .value !== ' all' ).map ((item ) => item .value )
160- break
161- default :
162- baseIDs = [this .currentTab ]
163- break
164- }
176+ const baseKeys = this .currentTab === ' all'
177+ ? this .tabListFlat .filter (item => item .value !== ' all' ).map (item => item .key )
178+ : [this .currentTab ]
165179
166- return baseIDs .filter ((id ) => this .allCIList ? .[id]? .length ).map ((id ) => {
167- const findTab = this .tabList .find ((item ) => item .value === id) || {}
180+ return baseKeys .filter ((key ) => this .allCIList ? .[key]? .length ).map ((key ) => {
181+ const findTab = this .tabListFlat .find ((item ) => item .key === key) || {}
182+
183+ let name = findTab? .name || ' '
184+ if (name && findTab? .value === this .ci ._type ) {
185+ name = ` ${ findTab? .isParent ? this .$t (' cmdb.ci.upstream' ) : this .$t (' cmdb.ci.downstream' )} - ${name}`
186+ }
168187
169188 return {
170- id,
171- name: findTab? .name || ' ' ,
189+ key,
190+ value: findTab?.value || '',
191+ name,
172192 count: findTab?.count || ''
173193 }
174194 })
@@ -234,23 +254,46 @@ export default {
234254 ...childCIs
235255 }
236256
237- const tabList = this .allCITypes .map ((item ) => {
257+ const tabList = []
258+
259+ tabList[0] = {
260+ name: '',
261+ key: 'all',
262+ list: [{
263+ name: this.$t('all'),
264+ key: 'all',
265+ value: 'all',
266+ count: Object.values(this.allCIList).reduce((acc, cur) => acc + (cur?.length || 0), 0),
267+ showAdd: false
268+ }]
269+ }
270+ tabList[1] = {
271+ name: this.$t('cmdb.ci.upstream'),
272+ key: PARENT_KEY,
273+ list: this.buildTabList(cloneRelationData.parentCITypeList, PARENT_KEY, true)
274+ }
275+ tabList[2] = {
276+ name: this.$t('cmdb.ci.downstream'),
277+ key: CHILDREN_KEY,
278+ list: this.buildTabList(cloneRelationData.childCITypeList, CHILDREN_KEY, false)
279+ }
280+ this.tabList = tabList
281+
282+ this.handleReferenceCINameMap()
283+ },
284+
285+ buildTabList(list, keyPrefix, isParent) {
286+ return list.map((item) => {
287+ const key = ` ${keyPrefix}- ${item .id }`
238288 return {
239289 name: item?.alias ?? item?.name ?? '',
290+ key,
291+ isParent,
240292 value: item.id,
241- count: this .allCIList ? .[item . id ]? .length || 0 ,
293+ count: this.allCIList?.[key ]?.length || 0,
242294 showAdd: this.allCanEdit?.[item.id] ?? false
243295 }
244296 })
245- tabList .unshift ({
246- name: this .$t (' all' ),
247- value: ' all' ,
248- count: Object .values (this .allCIList ).reduce ((acc , cur ) => acc + (cur? .length || 0 ), 0 ),
249- showAdd: false
250- })
251- this .tabList = tabList
252-
253- this .handleReferenceCINameMap ()
254297 },
255298
256299 handleCITypeList(list, isParent) {
@@ -365,11 +408,12 @@ export default {
365408 })
366409 this.formatCI(item)
367410 item.isParent = isParent
411+ const CIKey = ` ${isParent ? PARENT_KEY : CHILDREN_KEY }- ${item ._type }`
368412
369- if (item . _type in cis) {
370- cis[item . _type ].push (item)
413+ if (CIKey in cis) {
414+ cis[CIKey ].push(item)
371415 } else {
372- cis[item . _type ] = [item]
416+ cis[CIKey ] = [item]
373417 }
374418 })
375419
@@ -398,9 +442,11 @@ export default {
398442 async handleReferenceCINameMap() {
399443 const referenceCINameMap = {}
400444 this.allCITypes.forEach((CIType) => {
445+ const CIKey = ` ${CIType .isParent ? PARENT_KEY : CHILDREN_KEY }- ${CIType .id }`
446+
401447 CIType.attributes.forEach((attr) => {
402448 if (attr?.is_reference && attr?.reference_type_id) {
403- const currentCIList = this .allCIList [CIType . id ]
449+ const currentCIList = this.allCIList[CIKey ]
404450 if (currentCIList?.length) {
405451 currentCIList.forEach((ci) => {
406452 const ids = Array.isArray(ci[attr.name]) ? ci[attr.name] : ci[attr.name] ? [ci[attr.name]] : []
@@ -461,8 +507,8 @@ export default {
461507 return this.referenceCINameMap?.[typeId]?.[id] || id
462508 },
463509
464- clickTab (value ) {
465- this .currentTab = value
510+ clickTab(key ) {
511+ this.currentTab = key
466512 },
467513
468514 deleteRelation(row) {
@@ -486,7 +532,7 @@ export default {
486532 },
487533 this.ciId,
488534 ciType,
489- ciType ? .isParent ? ' parents' : ' children'
535+ tabData ?.isParent ? 'parents' : 'children'
490536 )
491537 },
492538
@@ -512,12 +558,26 @@ export default {
512558 &-tab {
513559 flex-shrink: 0;
514560 width: 160px;
515- max- height: 300px ;
561+ min-height: 300px;
562+ max-height: 600px;
516563 overflow-y: auto;
517564 overflow-x: hidden;
518565 padding: 6px 0px;
519566 border-right: solid 1px #E4E7ED;
520567
568+ .tab-group {
569+ width: 100%;
570+
571+ &-name {
572+ padding-left: 8px;
573+ height: 32px;
574+ line-height: 32px;
575+ width: 100%;
576+ font-weight: 600;
577+ color: rgba(0, 0, 0, .45);
578+ }
579+ }
580+
521581 .tab-item {
522582 height: 32px;
523583 width: 100%;
@@ -586,6 +646,9 @@ export default {
586646 padding: 15px 17px;
587647 overflow: hidden;
588648 min-height: 300px;
649+ max-height: 600px;
650+ overflow-y: auto;
651+ overflow-x: hidden;
589652 }
590653
591654 &-item {
0 commit comments