|
@@ -98,7 +98,7 @@ export default {
|
|
this.newGroupName = ''
|
|
this.newGroupName = ''
|
|
this.addGroupLevel = 1
|
|
this.addGroupLevel = 1
|
|
},
|
|
},
|
|
- onConfirmAddingGroup() {
|
|
|
|
|
|
+ onConfirmAddingGroup() {
|
|
if (this.addGroupLevel === 1) {
|
|
if (this.addGroupLevel === 1) {
|
|
let newGroupLevel2Id = 'c_' + this.$randomWord(true, 8, 8)
|
|
let newGroupLevel2Id = 'c_' + this.$randomWord(true, 8, 8)
|
|
const newGroupLevel1 = {
|
|
const newGroupLevel1 = {
|
|
@@ -165,10 +165,11 @@ export default {
|
|
},
|
|
},
|
|
onDeleteGroup(groupId, groupLevel) {
|
|
onDeleteGroup(groupId, groupLevel) {
|
|
const deleteGroupLevel2 = (groupId) => {
|
|
const deleteGroupLevel2 = (groupId) => {
|
|
- // 删除所属一级分组中的children中元素
|
|
|
|
- // 因为用户无法看到、操作默认二级分组,所以这里要删除的group不可能是默认二级分组
|
|
|
|
|
|
+ // 要删除的二级分组在catalogRoot[x].children中的索引
|
|
let targetGroupIdxLevel2 = null
|
|
let targetGroupIdxLevel2 = null
|
|
|
|
+ // 要删除的二级分组所属的一级分组在catalogRoot中的索引
|
|
let belongGroupIdxLevel1 = null
|
|
let belongGroupIdxLevel1 = null
|
|
|
|
+ // 确定上边两个变量的取值
|
|
for (const [groupIdxLevel1, groupLevel1] of this.info.catalogRoot.entries()) {
|
|
for (const [groupIdxLevel1, groupLevel1] of this.info.catalogRoot.entries()) {
|
|
for (const [groupIdxLevel2, childId] of groupLevel1.children.entries()) {
|
|
for (const [groupIdxLevel2, childId] of groupLevel1.children.entries()) {
|
|
if (childId === groupId) {
|
|
if (childId === groupId) {
|
|
@@ -185,9 +186,11 @@ export default {
|
|
console.log(targetGroupIdxLevel2, belongGroupIdxLevel1);
|
|
console.log(targetGroupIdxLevel2, belongGroupIdxLevel1);
|
|
throw('一级分组列表中没有找到要删除的二级分组!')
|
|
throw('一级分组列表中没有找到要删除的二级分组!')
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+ // 删除catalogRoot[x].children中那个二级分组条目
|
|
this.info.catalogRoot[belongGroupIdxLevel1].children.splice(targetGroupIdxLevel2, 1)
|
|
this.info.catalogRoot[belongGroupIdxLevel1].children.splice(targetGroupIdxLevel2, 1)
|
|
|
|
|
|
- // 删除二级分组列表中元素
|
|
|
|
|
|
+ // 删除catalogs中那个二级分组条目
|
|
const targetIdx = this.info.catalogs.findIndex((item) => {
|
|
const targetIdx = this.info.catalogs.findIndex((item) => {
|
|
return item.id === groupId
|
|
return item.id === groupId
|
|
})
|
|
})
|
|
@@ -200,6 +203,17 @@ export default {
|
|
this.info.scenes = this.info.scenes.filter((item) => {
|
|
this.info.scenes = this.info.scenes.filter((item) => {
|
|
return item.category !== groupId
|
|
return item.category !== groupId
|
|
})
|
|
})
|
|
|
|
+
|
|
|
|
+ // 如果所属一级分组中没有任何二级分组了,则新增一个默认二级分组
|
|
|
|
+ if (this.info.catalogRoot[belongGroupIdxLevel1].children.length === 0) {
|
|
|
|
+ let newGroupLevel2Id = 'c_' + this.$randomWord(true, 8, 8)
|
|
|
|
+ this.info.catalogRoot[belongGroupIdxLevel1].children.push(newGroupLevel2Id)
|
|
|
|
+ this.info.catalogs.push({
|
|
|
|
+ id: newGroupLevel2Id,
|
|
|
|
+ name: '默认二级分组',
|
|
|
|
+ })
|
|
|
|
+ }
|
|
|
|
+
|
|
return
|
|
return
|
|
}
|
|
}
|
|
|
|
|