diff --git a/src/resources/api/cmdb/ci/ci.js b/src/resources/api/cmdb/ci/ci.js index bae135c2a33052e8e0a7113602544447b48dadb2..d6ef40a642e903425195bbeb64b02fa35ae1c3b1 100644 --- a/src/resources/api/cmdb/ci/ci.js +++ b/src/resources/api/cmdb/ci/ci.js @@ -165,6 +165,9 @@ const ci = { }, saveCiTreeItem(params) { return axios.post('/api/rest/cmdb/ci/tree/save', params); + }, + getCiForprocessmapping(params) { //获取模型信息(流程图cmdb节点关系映射专用) + return axios.post('/api/rest/cmdb/ci/get/forprocessmapping', params); } }; diff --git a/src/resources/assets/languages/term/en.json b/src/resources/assets/languages/term/en.json index e08de4675eb9a1ad002d468752a67e0c72f93cbe..aa6f713dd77a42d1505bf25ba498341ebe3a0f22 100644 --- a/src/resources/assets/languages/term/en.json +++ b/src/resources/assets/languages/term/en.json @@ -187,7 +187,10 @@ "asyncpolicy": "Synchronization strategy", "globaleditmodetip": "Global mode, do not delete attribute representatives", "partialeditmodetip": "Local mode, do not change if attribute is not given", - "treedraginfo": "Dragging a model can change the order and affiliation of the model, and cannot be dragged when in search mode" + "treedraginfo": "Dragging a model can change the order and affiliation of the model, and cannot be dragged when in search mode", + "writeci": "Write model", + "writecitip": "Select constants or specify the model for data writing through form mapping. If the parent model is an abstract model and does not support adding configuration items, data needs to be written into the child model.", + "abstractcireltip": "Firstly, configure the parent model, complete the mapping of common attributes in the parent model, and specify the model for data writing. After completing the configuration of the parent model, return to the current interface before clicking on the sub model to configure the mapping of non-public (non inherited) attributes in the sub model." }, "process": { "workordercenter": "Work Center", diff --git a/src/resources/assets/languages/term/zh.json b/src/resources/assets/languages/term/zh.json index 1cdc944a5feb1a7b0579cb690d2fd3bd25b470f7..d9674bd8a404a0c790efb212afd1f976bad7f106 100644 --- a/src/resources/assets/languages/term/zh.json +++ b/src/resources/assets/languages/term/zh.json @@ -187,7 +187,10 @@ "asyncpolicy": "同步策略", "globaleditmodetip": "全局模式,不给属性代表删除", "partialeditmodetip": "局部模式,不给属性则不改", - "treedraginfo": "拖动模型可以改变模型的顺序和从属关系,处于搜索状态时不可拖动" + "treedraginfo": "拖动模型可以改变模型的顺序和从属关系,处于搜索状态时不可拖动", + "writeci": "写入模型", + "writecitip": "选择常量或通过表单映射的方式,指定数据写入的模型。若父模型为抽象模型,不支持添加配置项,需将数据写入子模型。", + "abstractcireltip": "首先配置父模型,完成父模型中公共属性的映射,并指定数据写入的模型。完成父模型配置后,返回当前界面,才可点击子模型,配置子模型中的非公共(非继承)属性映射。" }, "process": { "workordercenter": "工单中心", diff --git a/src/views/pages/cmdb/flow/node/nodesetting/cmdbpolicy/cmdbsync-dialog.vue b/src/views/pages/cmdb/flow/node/nodesetting/cmdbpolicy/cmdbsync-dialog.vue index 18d20d53b31278a9d2ab9bae976f579af45d7476..f30ee0a2d1bbf32bbb26bde1b2ab9183aca5ba70 100644 --- a/src/views/pages/cmdb/flow/node/nodesetting/cmdbpolicy/cmdbsync-dialog.vue +++ b/src/views/pages/cmdb/flow/node/nodesetting/cmdbpolicy/cmdbsync-dialog.vue @@ -42,6 +42,7 @@ - -
- -
-
+ @@ -197,7 +198,6 @@ export default { url: 'api/rest/cmdb/ci/list', search: true, params: { - isAbstract: 0, isVirtual: 0 }, validateList: ['required'], @@ -270,7 +270,9 @@ export default { value: 'partial', description: this.$t('term.cmdb.partialeditmodetip') } - ] + ], + isInherit: false, //判断子模型需要继承根模型的策略 + subCiUuidList: [] //子模型临时数据(标识) }; }, beforeCreate() {}, @@ -300,7 +302,9 @@ export default { this.currentFormItemList = this.$utils.deepClone(this.allFormitemList); } }, - initValue(cientity, preCiEntity) { + initValue(cientity, preCiEntity, rootId, subCiUuidList) { + this.subCiUuidList = subCiUuidList || []; + this.isInherit = false; let findItem = this.saveCiEntityMap[cientity.uuid]; if (findItem) { Object.keys(findItem).forEach(key => { @@ -320,6 +324,8 @@ export default { } } }); + //标记为已保存的,用于点击“取消”后判断是否需要删除数据 + cientity._isnew = true; } if (preCiEntity && preCiEntity.batchDataSource && preCiEntity.batchDataSource.type && cientity.batchDataSource && cientity.batchDataSource.type && @@ -335,6 +341,21 @@ export default { } }); } + if (rootId && rootId != cientity.ciId) { + let rootConfig = null; + Object.keys(this.saveCiEntityMap).forEach(key => { + if (this.saveCiEntityMap[key].ciId === rootId) { + rootConfig = this.saveCiEntityMap[key]; + } + }); + if (rootConfig) { + this.$set(cientity, 'action', rootConfig.action); + this.$set(cientity, 'batchDataSource', rootConfig.batchDataSource); + this.$set(cientity, 'editMode', rootConfig.editMode); + this.$set(cientity, 'createPolicy', rootConfig.createPolicy); + this.isInherit = true; + } + } }, okDialog() { if (!this.valid()) { @@ -358,10 +379,10 @@ export default { }, getCiEntityById() { this.loadingShow = true; - this.$api.cmdb.ci.getCiById(this.ciData.ciId, true).then(async res => { + this.$api.cmdb.ci.getCiForprocessmapping({id: this.ciData.ciId}).then(res => { if (res.Return) { const ci = res.Return; - if (ci.isVirtual == 0 && ci.isAbstract == 0) { + if (ci.isVirtual == 0) { const cientity = { isStart: 1, uuid: this.ciData.uuid || this.$utils.setUuid(), @@ -369,14 +390,15 @@ export default { ciName: ci.name, ciLabel: ci.label, ciIcon: ci.icon, - editMode: this.ciData.editMode || '', + editMode: this.ciData.editMode || 'global', createPolicy: 'single', batchDataSource: {}, relEntityData: {}, - allAttrEntityData: {} + allAttrEntityData: {}, + isAbstract: ci.isAbstract }; - cientity['_elementList'] = await this.getElementByCiId(this.ciData.ciId); - cientity['_uniqueAttrList'] = await this.getCiUniqueByCiId(this.ciData.ciId); + cientity['_elementList'] = this.getElementByCiId(ci); + cientity['_uniqueAttrList'] = ci.uniqueAttrIdList; cientity['_description'] = this.descriptionConfig; this.initValue(cientity); this.ciEntityQueue = [cientity]; @@ -384,8 +406,6 @@ export default { } else { if (ci.isVirtual == 1) { this.error = this.$t('message.cmdb.virtualmodel'); - } else if (ci.isAbstract == 1) { - this.error = this.$t('message.cmdb.abstractmodel'); } } } @@ -393,18 +413,11 @@ export default { this.loadingShow = false; }); }, - async getCiUniqueByCiId(ciId) { - let uniqueList = []; - await this.$api.cmdb.ci.getCiUniqueByCiId(ciId).then(res => { - uniqueList = res.Return; - }); - return uniqueList; - }, - async getElementByCiId(ciId) { - const attrList = await this.getAttrByCiId(ciId); - const relList = await this.getRelByCiId(ciId); - const globalAttrList = await this.getGlobalAttr(); - const ciViewList = await this.getCiViewByCiId(ciId); + getElementByCiId(data) { + const attrList = data.attrList || []; + const relList = data.relList || []; + const globalAttrList = data.globalAttrList || []; + const ciViewList = data.viewList || []; const elementList = []; ciViewList.forEach((e, index) => { if (e.type === 'attr') { @@ -431,41 +444,6 @@ export default { }); return elementList; }, - async getGlobalAttr() { - let globalAttrList; - await this.$api.cmdb.globalattr.searchGlobalAttr({isActive: 1}).then(res => { - globalAttrList = res.Return.tbodyList; - }); - return globalAttrList; - }, - async getAttrByCiId(ciId) { - if (ciId) { - let attrList; - let allowEdit = 1; - await this.$api.cmdb.ci.getAttrByCiId(ciId, { allowEdit: allowEdit }).then(res => { - attrList = res.Return; - }); - return attrList; - } - }, - async getRelByCiId(ciId) { - if (ciId) { - let relList; - await this.$api.cmdb.ci.getRelByCiId(ciId, {needAction: true, allowEdit: 1}).then(res => { - relList = res.Return; - }); - return relList; - } - }, - async getCiViewByCiId(ciId) { - if (ciId) { - let ciViewList; - await this.$api.cmdb.ci.getCiViewByCiId(ciId).then(res => { - ciViewList = res.Return; - }); - return ciViewList; - } - }, addNewCiEntity(type, item) { if (!this.valid()) { return; @@ -477,7 +455,8 @@ export default { const relId = rel._relId; const direction = rel.direction == 'from' ? 'to' : 'from'; //目标关系需要取反 const uuid = rel.ciEntityUuid || this.$utils.setUuid(); //新的配置项标识 - this.$api.cmdb.ci.getCiById(ciId).then(async res => { + const rootId = rel._rootId || null; + this.$api.cmdb.ci.getCiForprocessmapping({id: ciId, rootId: rootId}).then(res => { if (res.Return) { const ci = res.Return; //获取当前配置项数据 @@ -491,28 +470,29 @@ export default { ciName: ci.name, ciLabel: ci.label, ciIcon: ci.icon, - editMode: '', + editMode: 'global', createPolicy: 'single', batchDataSource: {}, action: 'append', relEntityData: {}, _disableRel: 'rel' + direction + '_' + relId, //标记哪个关系不允许添加或选择 - allAttrEntityData: {} //所有的属性 + allAttrEntityData: {}, //所有的属性 + isAbstract: ci.isAbstract }; - newCiEntity['_elementList'] = await this.getElementByCiId(ciId); - newCiEntity['_uniqueAttrList'] = await this.getCiUniqueByCiId(ciId); + newCiEntity['_elementList'] = this.getElementByCiId(ci); + newCiEntity['_uniqueAttrList'] = ci.uniqueAttrIdList; newCiEntity['_description'] = this.descriptionConfig; newCiEntity['relEntityData']['rel' + direction + '_' + relId] = { valueList: [ { ciEntityUuid: currentCiEntity.uuid, - ciEntityName: this.$t('term.cmdb.fromcientity'), + ciEntityName: currentCiEntity.ciLabel, ciId: ciId, type: 'from' } ] }; - this.initValue(newCiEntity, currentCiEntity); + this.initValue(newCiEntity, currentCiEntity, rootId, rel.subCiUuidList); this.ciData = newCiEntity; this.ciEntityQueue.push(newCiEntity); this.updateCurrentFormItemList(); @@ -531,6 +511,7 @@ export default { } }, back() { + this.isInherit = false; const cientity = this.ciEntityQueue.pop(); if (cientity._isnew) { this.$set(this.saveCiEntityMap, cientity.uuid, this.tmpCiEntityData); @@ -549,7 +530,7 @@ export default { editNewCiEntity(rel) { let uuid = rel.ciEntityUuid; if (this.saveCiEntityMap[uuid]) { - this.tmpCiEntityData = JSON.parse(JSON.stringify(this.saveCiEntityMap[uuid])); + this.tmpCiEntityData = this.$utils.deepClone((this.saveCiEntityMap[uuid])); let index = -1; for (let i = 0; i < this.ciEntityQueue.length; i++) { if (this.ciEntityQueue[i].uuid == uuid) { @@ -643,6 +624,7 @@ export default { if (!this.valid()) { return false; } + this.isInherit = false; //队列只剩一个配置项时才写入数据库 if (this.ciEntityQueue.length > 1) { const cientity = this.ciEntityQueue.pop(); @@ -653,7 +635,7 @@ export default { const newRelEntity = { _relId: cientity['_relId'], ciEntityUuid: cientity.uuid, - ciEntityName: this.$t('term.cmdb.newcientity'), + ciEntityName: cientity.ciLabel, ciId: cientity.ciId, type: 'new' }; @@ -671,6 +653,7 @@ export default { this.saveCiEntityMap[cientity.uuid] = cientity; this.ciData = this.ciEntityQueue[this.ciEntityQueue.length - 1]; this.updateCurrentFormItemList(); + this.updateSubCiData(cientity); } else if (this.ciEntityQueue.length == 1) { const cientity = this.ciEntityQueue[0]; this.saveCiEntityMap[cientity.uuid] = cientity; @@ -962,6 +945,36 @@ export default { if (ciEntity) { this.$set(ciEntity, 'editMode', val); } + }, + updateSubCiData(cientity) { + //抽象模型修改遍历对象的时候,子模型,映射到旧的遍历对象的哪些属性,全部清空 + if (!this.$utils.isEmpty(this.subCiUuidList)) { + this.subCiUuidList.forEach(uuid => { + if (this.saveCiEntityMap[uuid]) { + this.$set(this.saveCiEntityMap[uuid], 'editMode', cientity.editMode); + this.$set(this.saveCiEntityMap[uuid], 'action', cientity.action); + if (cientity.createPolicy != this.saveCiEntityMap[uuid].createPolicy || + (!this.$utils.isEmpty(cientity.batchDataSource) && (cientity.batchDataSource.type != this.saveCiEntityMap[uuid].batchDataSource.type) || (cientity.batchDataSource.attributeUuid != this.saveCiEntityMap[uuid].batchDataSource.attributeUuid)) + ) { + if (!this.$utils.isEmpty(this.saveCiEntityMap[uuid].allAttrEntityData)) { + Object.keys(this.saveCiEntityMap[uuid].allAttrEntityData).forEach(key => { + let config = this.saveCiEntityMap[uuid].allAttrEntityData[key]; + if (config.mappingMode === 'formTableComponent' || config.mappingMode === 'formSubassemblyComponent') { + this.$set(config, 'valueList', []); + } + }); + } else if (!this.$utils.isEmpty(this.saveCiEntityMap[uuid].mappingList)) { + let mappingList = this.saveCiEntityMap[uuid].mappingList.filter(item => { + return item.mappingMode !== 'formTableComponent' && item.mappingMode !== 'formSubassemblyComponent'; + }); + this.$set(this.saveCiEntityMap[uuid], 'mappingList', mappingList); + } + } + this.$set(this.saveCiEntityMap[uuid], 'createPolicy', cientity.createPolicy); + this.$set(this.saveCiEntityMap[uuid], 'batchDataSource', cientity.batchDataSource); + } + }); + } } }, filter: {}, diff --git a/src/views/pages/cmdb/flow/node/nodesetting/cmdbpolicy/cmdbsync-edit.vue b/src/views/pages/cmdb/flow/node/nodesetting/cmdbpolicy/cmdbsync-edit.vue index cbcb581d7db9276c439613c472fc16504bc54d06..7388a14d7389015aa8424cd48edd36fd9a056fc0 100644 --- a/src/views/pages/cmdb/flow/node/nodesetting/cmdbpolicy/cmdbsync-edit.vue +++ b/src/views/pages/cmdb/flow/node/nodesetting/cmdbpolicy/cmdbsync-edit.vue @@ -1,250 +1,274 @@