diff --git a/cmdb-ui/src/modules/cmdb/lang/en.js b/cmdb-ui/src/modules/cmdb/lang/en.js index ee4322f..c58100a 100644 --- a/cmdb-ui/src/modules/cmdb/lang/en.js +++ b/cmdb-ui/src/modules/cmdb/lang/en.js @@ -130,6 +130,7 @@ const cmdb_en = { selectAttribute: 'Select Attribute', groupExisted: 'Group name already exists', attributeSortedTips: 'Attributes in other groups cannot be sorted. If you need to sort, please drag them to a custom group first!', + attributeSortedTips2: 'Non-inherited attributes cannot be inserted before inherited attributes!', buildinAttribute: 'built-in attributes', expr: 'Expression', code: 'Code', diff --git a/cmdb-ui/src/modules/cmdb/lang/zh.js b/cmdb-ui/src/modules/cmdb/lang/zh.js index 184dd92..fc26f2b 100644 --- a/cmdb-ui/src/modules/cmdb/lang/zh.js +++ b/cmdb-ui/src/modules/cmdb/lang/zh.js @@ -130,6 +130,7 @@ const cmdb_zh = { selectAttribute: '添加属性', groupExisted: '分组名称已存在', attributeSortedTips: '其他分组中的属性不能进行排序,如需排序请先拖至自定义的分组!', + attributeSortedTips2: '非继承属性不能插入到继承属性前!', buildinAttribute: '内置字段', expr: '表达式', code: '代码', diff --git a/cmdb-ui/src/modules/cmdb/views/ci_types/attributesTable.vue b/cmdb-ui/src/modules/cmdb/views/ci_types/attributesTable.vue index 8d25822..74d67e6 100644 --- a/cmdb-ui/src/modules/cmdb/views/ci_types/attributesTable.vue +++ b/cmdb-ui/src/modules/cmdb/views/ci_types/attributesTable.vue @@ -233,6 +233,7 @@ export default { attrTypeFilter: [], unique: '', show_id: null, + groupMaxCount: {}, } }, computed: { @@ -340,6 +341,7 @@ export default { }) this.CITypeGroups = values[1] this.CITypeGroups.forEach((g) => { + this.groupMaxCount[g.name] = g.attributes.filter(a => a.inherited).length g.attributes.forEach((a) => { a.is_required = (temp[a.id] && temp[a.id].is_required) || false a.default_show = (temp[a.id] && temp[a.id].default_show) || false @@ -475,44 +477,43 @@ export default { handleChange(e, group) { console.log('changess', group) if (e.hasOwnProperty('moved') && e.moved.oldIndex !== e.moved.newIndex) { - if (group === -1) { - this.$message.error(this.$t('cmdb.ciType.attributeSortedTips')) + if (group === -1 || group === null) { + this.refreshPage(this.$t('cmdb.ciType.attributeSortedTips')) + } else if (e.moved.newIndex < this.groupMaxCount[group]) { + this.refreshPage(this.$t('cmdb.ciType.attributeSortedTips2')) } else { transferCITypeAttrIndex(this.CITypeId, { from: { attr_id: e.moved.element.id, group_name: group }, - to: { order: e.moved.newIndex, group_name: group }, + to: { order: e.moved.newIndex, group_name: group } }) - .then((res) => this.$message.success(this.$t('updateSuccess'))) - .catch(() => { - this.abortDraggable() - }) + .then(() => this.$message.success(this.$t('updateSuccess'))) + .catch(() => this.init()) } } - if (e.hasOwnProperty('added')) { this.addRemoveGroupFlag = { to: { group_name: group, order: e.added.newIndex }, inited: true } } - if (e.hasOwnProperty('removed')) { this.$nextTick(() => { - transferCITypeAttrIndex(this.CITypeId, { - from: { attr_id: e.removed.element.id, group_name: group }, - to: { group_name: this.addRemoveGroupFlag.to.group_name, order: this.addRemoveGroupFlag.to.order }, - }) - .then((res) => this.$message.success(this.$t('saveSuccess'))) - .catch(() => { - this.abortDraggable() - }) - .finally(() => { - this.addRemoveGroupFlag = {} + if (this.addRemoveGroupFlag.to.order < this.groupMaxCount[this.addRemoveGroupFlag.to.group_name]) { + this.refreshPage(this.$t('cmdb.ciType.attributeSortedTips2')) + } else { + transferCITypeAttrIndex(this.CITypeId, { + from: { attr_id: e.removed.element.id, group_name: group }, + to: { group_name: this.addRemoveGroupFlag.to.group_name, order: this.addRemoveGroupFlag.to.order } }) + .then(() => this.$message.success(this.$t('saveSuccess'))) + .catch(() => this.init()) + .finally(() => { + this.addRemoveGroupFlag = {} + }) + } }) } }, - abortDraggable() { - this.$nextTick(() => { - this.$router.push({ name: 'ci_type' }) - }) + refreshPage(errorMessage) { + this.$message.error(errorMessage) + this.init() }, updatePropertyIndex() { const attributes = [] // All attributes @@ -594,7 +595,7 @@ export default { return attrTypeFilter.includes(valueType) } }) - }, + } }, }