ソースを参照

update: 功能优化

liuyang 2 年 前
コミット
6539611e74
共有1 個のファイルを変更した25 個の追加2 個の削除を含む
  1. 25 2
      src/views/_components/drag/DragComments.vue

+ 25 - 2
src/views/_components/drag/DragComments.vue

@ -6,6 +6,7 @@
6 6
        <h5 class="title">属性树形结构</h5>
7 7
        <div class="tree-content">
8 8
          <el-tree
9
            ref="myTree"
9 10
            :allow-drop="allowDrop"
10 11
            :allow-drag="allowDrag"
11 12
            :data="treeData"
@ -14,6 +15,7 @@
14 15
            default-expand-all
15 16
            node-key="'id'"
16 17
            @node-click="getCurrentNode"
18
            @node-contextmenu="cancelCurrent"
17 19
            @node-drag-start="handleDragStart"
18 20
            @node-drag-enter="handleDragEnter"
19 21
            @node-drag-leave="handleDragLeave"
@ -135,6 +137,7 @@ const treeData = ref<any>([]);
135 137
const jsonData = ref<any>({});
136 138
137 139
const currentNode = ref<any>({});
140
const myTree = ref<any>(null);
138 141
139 142
/**
140 143
 * el-tree拖拽start
@ -169,8 +172,12 @@ function handleDrop() {}
169 172
170 173
// 获取当前节点
171 174
function getCurrentNode(node: any) {
172
  console.log(node);
173
  currentNode.value = node;
175
  if (currentNode.value === node) {
176
    myTree.value.setCurrentKey(null);
177
    currentNode.value = {};
178
  } else {
179
    currentNode.value = node;
180
  }
174 181
}
175 182
176 183
/**
@ -203,6 +210,11 @@ function handleClickTag(tag: any) {
203 210
  }
204 211
}
205 212
213
function cancelCurrent() {
214
  myTree.value.setCurrentKey(null);
215
  currentNode.value = {};
216
}
217
206 218
// 删除树结构
207 219
function removeItem(node: any, data: any) {
208 220
  if (data.children?.length) {
@ -215,6 +227,9 @@ function removeItem(node: any, data: any) {
215 227
  const index = child.findIndex((d: any) => d.id === data.id);
216 228
  child.splice(index, 1);
217 229
  treeData.value = [...treeData.value];
230
  if (!treeData.value?.length) {
231
    currentNode.value = {};
232
  }
218 233
}
219 234
function assignment(type: any) {
220 235
  let r;
@ -429,6 +444,14 @@ watch(
429 444
  color: #606266;
430 445
  font-weight: 400;
431 446
}
447
:deep(.el-tree-node) {
448
  line-height: 30px;
449
  padding: 3px 0;
450
}
451
:deep(.is-current) {
452
  line-height: 30px;
453
  padding: 3px 0;
454
}
432 455
.tree-item {
433 456
  display: flex;
434 457
  justify-content: space-between;