feat(ui): topology view & batch import - update CI Type select component

This commit is contained in:
LH_R
2025-07-09 16:23:18 +08:00
parent 40a53a0213
commit 5048f2a788
3 changed files with 47 additions and 43 deletions

View File

@@ -71,7 +71,7 @@ export default {
watch: { watch: {
CITypeGroup: { CITypeGroup: {
deep: true, deep: true,
handler(newValue) { handler() {
this.handleSelectOptions() this.handleSelectOptions()
} }
} }

View File

@@ -1,19 +1,14 @@
<template> <template>
<div> <div>
<p class="cmdb-batch-upload-label"><span>*</span>1. {{ $t('cmdb.batch.selectCIType') }}</p> <p class="cmdb-batch-upload-label"><span>*</span>1. {{ $t('cmdb.batch.selectCIType') }}</p>
<a-select <CMDBTypeSelectAntd
showSearch
:placeholder="$t('cmdb.batch.selectCITypeTips')"
@change="selectCiType"
:style="{ width: '50%', marginBottom: '1em' }"
class="ops-select"
:filter-option="filterOption"
v-model="selectNum" v-model="selectNum"
> ref="CMDBTypeSelectAntd"
<a-select-option v-for="ciType in ciTypeList" :key="ciType.name" :value="ciType.id">{{ :placeholder="$t('cmdb.batch.selectCITypeTips')"
ciType.alias :style="{ width: '50%', marginBottom: '1em' }"
}}</a-select-option> :CITypeGroup="CITypeGroup"
</a-select> @change="selectCiType"
/>
<p class="cmdb-batch-upload-label">&nbsp;&nbsp;2. {{ $t('cmdb.batch.downloadTemplate') }}</p> <p class="cmdb-batch-upload-label">&nbsp;&nbsp;2. {{ $t('cmdb.batch.downloadTemplate') }}</p>
<a-button <a-button
:style="{ marginBottom: '1em' }" :style="{ marginBottom: '1em' }"
@@ -99,16 +94,21 @@ import _ from 'lodash'
import { mapState } from 'vuex' import { mapState } from 'vuex'
import ExcelJS from 'exceljs' import ExcelJS from 'exceljs'
import FileSaver from 'file-saver' import FileSaver from 'file-saver'
import { getCITypes } from '@/modules/cmdb/api/CIType' import { getCITypeGroupsConfig } from '@/modules/cmdb/api/ciTypeGroup'
import { getCITypeAttributesById } from '@/modules/cmdb/api/CITypeAttr' import { getCITypeAttributesById } from '@/modules/cmdb/api/CITypeAttr'
import { getCITypeParent, getCanEditByParentIdChildId } from '@/modules/cmdb/api/CITypeRelation' import { getCITypeParent, getCanEditByParentIdChildId } from '@/modules/cmdb/api/CITypeRelation'
import { searchPermResourceByRoleId } from '@/modules/acl/api/permission' import { searchPermResourceByRoleId } from '@/modules/acl/api/permission'
import CMDBTypeSelectAntd from '@/modules/cmdb/components/cmdbTypeSelect/cmdbTypeSelectAntd'
export default { export default {
name: 'CiTypeChoice', name: 'CiTypeChoice',
components: {
CMDBTypeSelectAntd
},
data() { data() {
return { return {
ciTypeList: [], CITypeGroup: [],
ciTypeName: '', ciTypeName: '',
selectNum: undefined, selectNum: undefined,
selectCiTypeAttrList: [], selectCiTypeAttrList: [],
@@ -132,12 +132,17 @@ export default {
resource_type_id: 'CIType', resource_type_id: 'CIType',
app_id: 'cmdb', app_id: 'cmdb',
}) })
getCITypes().then((res) => {
this.ciTypeList = res.ci_types.filter((type) => { getCITypeGroupsConfig({ need_other: true }).then((res) => {
const _findRe = resources.find((re) => re.name === type.name) const CITypeGroup = res || []
return _findRe?.permissions.includes('create') ?? false CITypeGroup.forEach((group) => {
group.ci_types = (group.ci_types || []).filter((type) => {
const _find = resources.find((resource) => resource.name === type.name)
return _find?.permissions?.includes?.('create') ?? false
}) })
}) })
this.CITypeGroup = CITypeGroup.filter((group) => group?.ci_types?.length)
})
}, },
watch: { watch: {
checkedAttrs() { checkedAttrs() {
@@ -152,18 +157,27 @@ export default {
}, },
}, },
methods: { methods: {
selectCiType(el) { selectCiType(id) {
// Callback function when a template type is selected // Callback function when a template type is selected
getCITypeAttributesById(el).then((res) => { getCITypeAttributesById(id).then((res) => {
this.$emit('getCiTypeAttr', res) this.$emit('getCiTypeAttr', res)
this.selectCiTypeAttrList = res this.selectCiTypeAttrList = res
}) })
this.ciTypeList.forEach((item) => { const selectOptions = this.$refs?.CMDBTypeSelectAntd?.selectOptions
if (this.selectNum === item.id) { let ciTypeName = ''
this.ciTypeName = item.alias || item.name if (selectOptions?.length) {
selectOptions.forEach((option) => {
if (option?.ci_types?.length) {
option.ci_types.forEach((type) => {
if (type?.id === id) {
ciTypeName = type.alias || type.name
} }
}) })
}
})
}
this.ciTypeName = ciTypeName
}, },
openModal() { openModal() {
@@ -188,9 +202,6 @@ export default {
this.checkedAttrs = this.selectCiTypeAttrList.attributes.map((item) => item.alias || item.name) this.checkedAttrs = this.selectCiTypeAttrList.attributes.map((item) => item.alias || item.name)
}) })
}, },
filterOption(input, option) {
return option.componentOptions.children[0].text.toLowerCase().indexOf(input.toLowerCase()) >= 0
},
handleCancel() { handleCancel() {
this.visible = false this.visible = false
}, },

View File

@@ -238,9 +238,11 @@
/> />
</a-form-item> </a-form-item>
<a-form-item :label="$t('cmdb.topo.centralNodeType')" prop="central_node_type"> <a-form-item :label="$t('cmdb.topo.centralNodeType')" prop="central_node_type">
<a-select @change="CITypeChange" v-decorator="['central_node_type', { rules: [{ required: true, message: $t('cmdb.topo.typeRequired') }]}]" :showSearch="true" optionFilterProp="label"> <CMDBTypeSelectAntd
<a-select-option v-for="t in ciTypes" :key="t.id" :value="t.id" :label="t.alias">{{ t.alias }}</a-select-option> v-decorator="['central_node_type', { rules: [{ required: true, message: $t('cmdb.topo.typeRequired') }]}]"
</a-select> :placeholder="$t('cmdb.ciType.selectModel')"
@change="CITypeChange"
/>
</a-form-item> </a-form-item>
<a-form-item :label="$t('cmdb.topo.filterInstances')" prop="central_node_instances"> <a-form-item :label="$t('cmdb.topo.filterInstances')" prop="central_node_instances">
<a-input <a-input
@@ -325,7 +327,6 @@ import draggable from 'vuedraggable'
import emptyImage from '@/assets/data_empty.png' import emptyImage from '@/assets/data_empty.png'
import SplitPane from '@/components/SplitPane' import SplitPane from '@/components/SplitPane'
import { ops_move_icon as OpsMoveIcon } from '@/core/icons' import { ops_move_icon as OpsMoveIcon } from '@/core/icons'
import { getCITypeGroups } from '@/modules/cmdb/api/ciTypeGroup'
import { roleHasPermissionToGrant } from '@/modules/acl/api/permission' import { roleHasPermissionToGrant } from '@/modules/acl/api/permission'
import { searchResourceType } from '@/modules/acl/api/resource' import { searchResourceType } from '@/modules/acl/api/resource'
import SeeksRelationGraph from '@/modules/cmdb/3rd/relation-graph' import SeeksRelationGraph from '@/modules/cmdb/3rd/relation-graph'
@@ -336,6 +337,7 @@ import { searchCI } from '@/modules/cmdb/api/ci'
import { getTopoGroups, postTopoGroup, putTopoGroupByGId, putTopoGroupsOrder, deleteTopoGroup, getTopoView, addTopoView, updateTopoView, deleteTopoView, getRelationsByTypeId, previewTopoView, showTopoView } from '@/modules/cmdb/api/topology' import { getTopoGroups, postTopoGroup, putTopoGroupByGId, putTopoGroupsOrder, deleteTopoGroup, getTopoView, addTopoView, updateTopoView, deleteTopoView, getRelationsByTypeId, previewTopoView, showTopoView } from '@/modules/cmdb/api/topology'
import CMDBExprDrawer from '@/components/CMDBExprDrawer' import CMDBExprDrawer from '@/components/CMDBExprDrawer'
import { v4 as uuidv4 } from 'uuid' import { v4 as uuidv4 } from 'uuid'
import CMDBTypeSelectAntd from '@/modules/cmdb/components/cmdbTypeSelect/cmdbTypeSelectAntd'
const currentTopoKey = 'ops_cmdb_topo_currentId' const currentTopoKey = 'ops_cmdb_topo_currentId'
export default { export default {
@@ -348,6 +350,7 @@ export default {
SeeksRelationGraph, SeeksRelationGraph,
RelationGraph, RelationGraph,
CMDBGrant, CMDBGrant,
CMDBTypeSelectAntd
}, },
data() { data() {
const defaultOptions = { const defaultOptions = {
@@ -421,7 +424,6 @@ export default {
currentId: null, currentId: null,
topoGroups: [], topoGroups: [],
CITypeId: null, CITypeId: null,
ciTypes: [],
startId: null, startId: null,
endId: null, endId: null,
@@ -500,15 +502,6 @@ export default {
this.currentId = _currentId this.currentId = _currentId
} }
this.loadTopoViews(!_currentId) this.loadTopoViews(!_currentId)
let ciTypes = []
getCITypeGroups({ need_other: true }).then((res) => {
res.forEach((item) => {
if (item.ci_types && item.ci_types.length) {
ciTypes = ciTypes.concat(item.ci_types)
}
})
this.ciTypes = ciTypes
})
this.showTopoView(this.currentId.split('%')[1]) this.showTopoView(this.currentId.split('%')[1])
}, },
computed: { computed: {