|
@@ -58,7 +58,11 @@ export default {
|
|
|
return false
|
|
|
} else if (this.topologyLevel === 2) {
|
|
|
// console.log('情况2:被拖拽的是场景,拖拽到一级分组中');
|
|
|
- return false
|
|
|
+ if (this.parentNode.children.length === 0) { // 如果目标一级分组内容显示是空的,即其下只有一个(内容肯定是空的)默认二级分组
|
|
|
+ return true
|
|
|
+ } else { // 如果目标一级分组之下显示了内容,则肯定是显示了二级分组。
|
|
|
+ return false
|
|
|
+ }
|
|
|
} else if (this.topologyLevel === 3) {
|
|
|
// console.log('情况3:被拖拽的是场景,拖拽到二级分组中');
|
|
|
return true
|
|
@@ -152,35 +156,67 @@ export default {
|
|
|
switch (this.dragInfo.type) {
|
|
|
case 'scene': // 被拖拽的是场景
|
|
|
{
|
|
|
- // console.log('情况3:被拖拽的是场景,插入到二级分组中')
|
|
|
+ if (this.topologyLevel === 2) {
|
|
|
+ // console.log('情况2:被拖拽的是场景,拖拽到一级分组中。只有一种可能:目标一级分组内容显示是空的,即其下只有一个(内容肯定是空的)默认二级分组。')
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 找到被拖拽的场景
|
|
|
+ */
|
|
|
+ const draggedNode = this.info.scenes.find((item) => {
|
|
|
+ return item.id === this.dragInfo.node.id
|
|
|
+ })
|
|
|
|
|
|
- /**
|
|
|
- * 确定要插入的分组中各场景应有的weight(从1开始递增,小的先显示)
|
|
|
- */
|
|
|
- const belongGroupCopy = deepClone(this.parentNode.children)
|
|
|
- const draggedNodeCopy = deepClone(this.dragInfo.node)
|
|
|
- draggedNodeCopy.isCopy = true
|
|
|
- belongGroupCopy.splice(this.index, 0, draggedNodeCopy)
|
|
|
- const toDeleteIndex = belongGroupCopy.findIndex((item) => {
|
|
|
- return (item.id === this.dragInfo.node.id && !item.isCopy)
|
|
|
- })
|
|
|
- if (toDeleteIndex >= 0) {
|
|
|
- belongGroupCopy.splice(toDeleteIndex, 1)
|
|
|
- }
|
|
|
- for (let [index, elem] of belongGroupCopy.entries()) {
|
|
|
- elem.weight = index + 1
|
|
|
- }
|
|
|
+ /**
|
|
|
+ * 找到目标一级分组
|
|
|
+ */
|
|
|
+ const targetGroupLevel1 = this.info.catalogRoot.find((item) => {
|
|
|
+ return item.id === this.parentNode.id
|
|
|
+ })
|
|
|
+ console.log(targetGroupLevel1);
|
|
|
|
|
|
- /**
|
|
|
- * 真正修改场景原始数据的weight和所属分组
|
|
|
- */
|
|
|
- for (const eachSceneCopy of belongGroupCopy) {
|
|
|
- for (const eachScene of this.info.scenes) {
|
|
|
- if (eachSceneCopy.id === eachScene.id) {
|
|
|
- this.$set( eachScene, 'weight', eachSceneCopy.weight )
|
|
|
- }
|
|
|
- if (this.dragInfo.node.id === eachScene.id) {
|
|
|
- eachScene.category = this.parentNode.id // 注意category拼写!
|
|
|
+ /**
|
|
|
+ * 找到目标一级分组下辖的默认二级分组
|
|
|
+ */
|
|
|
+ const targetGroupLevel2 = this.info.catalogs.find((item) => {
|
|
|
+ console.log(item.id);
|
|
|
+ return item.id === targetGroupLevel1.children[0]
|
|
|
+ })
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 被拖拽的场景的所属二级分组记录修改
|
|
|
+ */
|
|
|
+ draggedNode.category = targetGroupLevel2.id
|
|
|
+ } else if (this.topologyLevel === 3) {
|
|
|
+ // console.log('情况3:被拖拽的是场景,插入到二级分组中')
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 确定要插入的分组中各场景应有的weight(从1开始递增,小的先显示)
|
|
|
+ */
|
|
|
+ const belongGroupCopy = deepClone(this.parentNode.children)
|
|
|
+ const draggedNodeCopy = deepClone(this.dragInfo.node)
|
|
|
+ draggedNodeCopy.isCopy = true
|
|
|
+ belongGroupCopy.splice(this.index, 0, draggedNodeCopy)
|
|
|
+ const toDeleteIndex = belongGroupCopy.findIndex((item) => {
|
|
|
+ return (item.id === this.dragInfo.node.id && !item.isCopy)
|
|
|
+ })
|
|
|
+ if (toDeleteIndex >= 0) {
|
|
|
+ belongGroupCopy.splice(toDeleteIndex, 1)
|
|
|
+ }
|
|
|
+ for (let [index, elem] of belongGroupCopy.entries()) {
|
|
|
+ elem.weight = index + 1
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 真正修改场景原始数据的weight和所属分组
|
|
|
+ */
|
|
|
+ for (const eachSceneCopy of belongGroupCopy) {
|
|
|
+ for (const eachScene of this.info.scenes) {
|
|
|
+ if (eachSceneCopy.id === eachScene.id) {
|
|
|
+ this.$set( eachScene, 'weight', eachSceneCopy.weight )
|
|
|
+ }
|
|
|
+ if (this.dragInfo.node.id === eachScene.id) {
|
|
|
+ eachScene.category = this.parentNode.id // 注意category拼写!
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
}
|