Skip to content

Commit 4837ac8

Browse files
committed
feat(ui): add navigation buttons to the model configuration page and resource view page
1 parent bdf9bc5 commit 4837ac8

File tree

5 files changed

+90
-9
lines changed

5 files changed

+90
-9
lines changed

cmdb-ui/src/modules/cmdb/lang/en.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ const cmdb_en = {
3838
attributeAD: 'Attributes AutoDiscovery',
3939
relationAD: 'Relation AutoDiscovery',
4040
grant: 'Grant',
41+
resourceViewTip: 'Not subscribed yet. Please go to the Preference page to complete your subscription.',
4142
addGroup: 'New Group',
4243
editGroup: 'Edit Group',
4344
group: 'Group',

cmdb-ui/src/modules/cmdb/lang/zh.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ const cmdb_zh = {
3838
attributeAD: '属性自动发现',
3939
relationAD: '关系自动发现',
4040
grant: '权限配置',
41+
resourceViewTip: '暂未订阅, 请先到我的订阅页面完成订阅',
4142
addGroup: '新增分组',
4243
editGroup: '修改分组',
4344
group: '分组',

cmdb-ui/src/modules/cmdb/views/ci/instanceList.vue

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,13 @@
4747
<a-icon type="star" />
4848
{{ $t('cmdb.preference.cancelSub') }}
4949
</a-menu-item>
50+
<a-menu-item
51+
key="citypeConfig"
52+
@click="handleCITypeConfig"
53+
>
54+
<ops-icon type="ops-cmdb-citype" />
55+
{{ $t('cmdb.menu.citypeManage') }}
56+
</a-menu-item>
5057
</a-menu>
5158
</a-dropdown>
5259
</a-space>
@@ -782,6 +789,28 @@ export default {
782789
},
783790
})
784791
},
792+
793+
handleCITypeConfig() {
794+
const { id, name } = this.CIType || {}
795+
if (id && name) {
796+
roleHasPermissionToGrant({
797+
app_id: 'cmdb',
798+
resource_type_name: 'CIType',
799+
perm: 'config',
800+
resource_name: name,
801+
}).then((res) => {
802+
if (res?.result) {
803+
const storageId = `null%${id}%${name}`
804+
localStorage.setItem('ops_cityps_currentId', storageId)
805+
localStorage.setItem('ops_model_config_tab_key', '1')
806+
window.open('/cmdb/ci_types', '_blank')
807+
} else {
808+
this.$message.error(this.$t('noPermission'))
809+
}
810+
})
811+
}
812+
},
813+
785814
handlePerm() {
786815
roleHasPermissionToGrant({
787816
app_id: 'cmdb',

cmdb-ui/src/modules/cmdb/views/ci_types/ciTypedetail.vue

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,18 @@
2020
<RelationTable isInGrantComp :CITypeId="CITypeId" :CITypeName="CITypeName"></RelationTable>
2121
</div>
2222
</a-tab-pane>
23+
24+
<a-button
25+
slot="tabBarExtraContent"
26+
type="primary"
27+
ghost
28+
size="small"
29+
class="ops-button-ghost ops-tab-button"
30+
@click="jumpResourceView"
31+
>
32+
<ops-icon type="ops-cmdb-resource" />
33+
{{ $t('cmdb.menu.ciTable') }}
34+
</a-button>
2335
</a-tabs>
2436
</a-card>
2537
</template>
@@ -52,6 +64,10 @@ export default {
5264
type: String,
5365
default: '',
5466
},
67+
preferenceData: {
68+
type: Object,
69+
default: () => {}
70+
}
5571
},
5672
data() {
5773
return {
@@ -91,6 +107,16 @@ export default {
91107
break
92108
}
93109
})
110+
},
111+
jumpResourceView() {
112+
const isSub = this?.preferenceData?.type_ids?.includes(this.CITypeId)
113+
114+
if (!isSub) {
115+
this.$message.error(this.$t('cmdb.ciType.resourceViewTip'))
116+
return
117+
}
118+
localStorage.setItem('ops_ci_typeid', this.CITypeId)
119+
window.open('/cmdb/instances/types', '_blank')
94120
}
95121
},
96122
}

cmdb-ui/src/modules/cmdb/views/ci_types/index.vue

Lines changed: 33 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,12 @@
182182
</template>
183183
<template #two>
184184
<div class="ci-types-right">
185-
<CITypeDetail v-if="currentCId" :CITypeId="currentCId" :CITypeName="currentCName" />
185+
<CITypeDetail
186+
v-if="currentCId"
187+
:CITypeId="currentCId"
188+
:CITypeName="currentCName"
189+
:preferenceData="preferenceData"
190+
/>
186191
<div v-else class="ci-types-right-empty">
187192
<a-empty :image="emptyImage" description=""></a-empty>
188193
<a-button icon="plus" size="small" type="primary" @click="handleCreateCiFromEmpty">{{
@@ -413,6 +418,7 @@ import {
413418
exportCITypeGroups
414419
} from '@/modules/cmdb/api/ciTypeGroup'
415420
import { searchAttributes, getCITypeAttributesById } from '@/modules/cmdb/api/CITypeAttr'
421+
import { getPreference } from '@/modules/cmdb/api/preference'
416422
import CreateNewAttribute from './ceateNewAttribute.vue'
417423
import CITypeDetail from './ciTypedetail.vue'
418424
import emptyImage from '@/assets/data_empty.png'
@@ -489,7 +495,9 @@ export default {
489495
490496
searchValue: '',
491497
modelExportVisible: false,
492-
pageLoading: false
498+
pageLoading: false,
499+
500+
preferenceData: {}
493501
}
494502
},
495503
computed: {
@@ -510,23 +518,29 @@ export default {
510518
},
511519
currentGId() {
512520
if (this.currentId) {
513-
return Number(this.currentId.split('%')[0])
521+
const id = this?.currentId?.split?.('%')?.[0]
522+
if (id !== 'null') {
523+
return Number(id)
524+
}
525+
return null
514526
}
515527
return null
516528
},
517529
currentCId() {
518530
if (this.currentId) {
519-
if (this.currentId.split('%')[1] !== 'null') {
520-
return Number(this.currentId.split('%')[1])
531+
const id = this?.currentId?.split?.('%')?.[1]
532+
if (id !== 'null') {
533+
return Number(id)
521534
}
522535
return null
523536
}
524537
return null
525538
},
526539
currentCName() {
527540
if (this.currentId) {
528-
if (this.currentId.split('%')[2] !== 'null') {
529-
return this.currentId.split('%')[2]
541+
const name = this?.currentId?.split?.('%')?.[2]
542+
if (name !== 'null') {
543+
return name
530544
}
531545
return null
532546
}
@@ -598,6 +612,7 @@ export default {
598612
this.pageLoading = false
599613
600614
this.getAttributes()
615+
this.getPreference()
601616
},
602617
methods: {
603618
getAllDepAndEmployee() {
@@ -608,6 +623,13 @@ export default {
608623
handleSearch(e) {
609624
this.searchValue = e.target.value
610625
},
626+
627+
getPreference() {
628+
getPreference().then((res) => {
629+
this.preferenceData = res || {}
630+
})
631+
},
632+
611633
async loadCITypes(isResetCurrentId = false, isInit = false) {
612634
const groups = await getCITypeGroupsConfig({ need_other: true })
613635
let alreadyReset = false
@@ -632,8 +654,10 @@ export default {
632654
if (isInit) {
633655
const isMatch = groups.some((g) => {
634656
const matchGroup = `${g?.id}%null%null` === this.currentId
635-
const matchCITypes = g?.ci_types?.some((item) => `${g?.id}%${item?.id}%${item?.name}` === this.currentId)
636-
return matchGroup || matchCITypes
657+
const matchCIType = g?.ci_types?.some((item) => {
658+
return `${g?.id}%${item?.id}%${item?.name}` === this.currentId || `null%${item?.id}%${item?.name}` === this.currentId
659+
})
660+
return matchGroup || matchCIType
637661
})
638662
639663
if (!isMatch) {

0 commit comments

Comments
 (0)