|
@@ -1,11 +1,11 @@
|
|
<template>
|
|
<template>
|
|
<div>
|
|
<div>
|
|
<!--
|
|
<!--
|
|
- 拖拽
|
|
|
|
- draggable
|
|
|
|
- @node-drop="handleDrop"
|
|
|
|
- @node-drag-enter="handleDragEnter"
|
|
|
|
- :allow-drop="allowDrop"
|
|
|
|
|
|
+ 拖拽
|
|
|
|
+ draggable
|
|
|
|
+ @node-drop="handleDrop"
|
|
|
|
+ @node-drag-enter="handleDragEnter"
|
|
|
|
+ :allow-drop="allowDrop"
|
|
-->
|
|
-->
|
|
<el-tree
|
|
<el-tree
|
|
:props="props"
|
|
:props="props"
|
|
@@ -16,14 +16,25 @@
|
|
:expand-on-click-node="expand"
|
|
:expand-on-click-node="expand"
|
|
ref="tree"
|
|
ref="tree"
|
|
v-loading="loading"
|
|
v-loading="loading"
|
|
|
|
+ @check-change="handleCheckChange"
|
|
>
|
|
>
|
|
<template slot-scope="{data,node}">
|
|
<template slot-scope="{data,node}">
|
|
<div class="row">
|
|
<div class="row">
|
|
<span class="content">{{data.name}}</span>
|
|
<span class="content">{{data.name}}</span>
|
|
<span class="handle">
|
|
<span class="handle">
|
|
<el-button type="text" size="mini" @click.stop.prevent="addNode(data,node)">新增</el-button>
|
|
<el-button type="text" size="mini" @click.stop.prevent="addNode(data,node)">新增</el-button>
|
|
- <el-button v-if="data.id!=-1" type="text" size="mini" @click.stop.prevent="delNode(data,node)">删除</el-button>
|
|
|
|
- <el-button v-if="data.id!=-1" type="text" size="mini" @click.stop.prevent="putNode(data,node)">更新</el-button>
|
|
|
|
|
|
+ <el-button
|
|
|
|
+ v-if="data.id!=-1"
|
|
|
|
+ type="text"
|
|
|
|
+ size="mini"
|
|
|
|
+ @click.stop.prevent="delNode(data,node)"
|
|
|
|
+ >删除</el-button>
|
|
|
|
+ <el-button
|
|
|
|
+ v-if="data.id!=-1"
|
|
|
|
+ type="text"
|
|
|
|
+ size="mini"
|
|
|
|
+ @click.stop.prevent="putNode(data,node)"
|
|
|
|
+ >更新</el-button>
|
|
</span>
|
|
</span>
|
|
</div>
|
|
</div>
|
|
</template>
|
|
</template>
|
|
@@ -32,7 +43,8 @@
|
|
</template>
|
|
</template>
|
|
|
|
|
|
<script>
|
|
<script>
|
|
-import { getNode, addNode, delNode, putNode } from "@/Api/tree";
|
|
|
|
|
|
+// import { getNode, addNode, delNode, putNode } from "@/Api/tree";
|
|
|
|
+import { getNode, addNode, delNode, putNode } from "@/Api/dept";
|
|
export default {
|
|
export default {
|
|
name: "tree",
|
|
name: "tree",
|
|
data() {
|
|
data() {
|
|
@@ -59,7 +71,7 @@ export default {
|
|
methods: {
|
|
methods: {
|
|
//加载节点
|
|
//加载节点
|
|
loadNode(node, resolve) {
|
|
loadNode(node, resolve) {
|
|
- // console.log(node);
|
|
|
|
|
|
+ // console.log(resolve);
|
|
if (node.level === 0) {
|
|
if (node.level === 0) {
|
|
let data = [
|
|
let data = [
|
|
{
|
|
{
|
|
@@ -67,12 +79,19 @@ export default {
|
|
id: -1
|
|
id: -1
|
|
}
|
|
}
|
|
];
|
|
];
|
|
- return resolve(data);
|
|
|
|
|
|
+ resolve(data);
|
|
|
|
+ this.$nextTick(() => {
|
|
|
|
+ this.$emit("check-node", this.$refs.tree.getCheckedNodes()); //返回所有节点
|
|
|
|
+ });
|
|
|
|
+ // return resolve(data);
|
|
} else if (node.level === 1) {
|
|
} else if (node.level === 1) {
|
|
getNode().then(res => {
|
|
getNode().then(res => {
|
|
// console.log(res.data);
|
|
// console.log(res.data);
|
|
// res.data.leaf = false
|
|
// res.data.leaf = false
|
|
- return resolve(res.data);
|
|
|
|
|
|
+ resolve(res.data);
|
|
|
|
+ this.$nextTick(() => {
|
|
|
|
+ this.$emit("check-node", this.$refs.tree.getCheckedNodes()); //返回所有节点
|
|
|
|
+ });
|
|
});
|
|
});
|
|
} else {
|
|
} else {
|
|
// console.log(node);
|
|
// console.log(node);
|
|
@@ -82,6 +101,9 @@ export default {
|
|
.then(res => {
|
|
.then(res => {
|
|
// console.log(res);
|
|
// console.log(res);
|
|
resolve(res.data);
|
|
resolve(res.data);
|
|
|
|
+ this.$nextTick(() => {
|
|
|
|
+ this.$emit("check-node", this.$refs.tree.getCheckedNodes()); //返回所有节点
|
|
|
|
+ });
|
|
})
|
|
})
|
|
.catch(e => {
|
|
.catch(e => {
|
|
// console.log(e);
|
|
// console.log(e);
|
|
@@ -92,7 +114,7 @@ export default {
|
|
//添加节点
|
|
//添加节点
|
|
addNode(data, node) {
|
|
addNode(data, node) {
|
|
// this.expand = false;
|
|
// this.expand = false;
|
|
- console.log(data, node);
|
|
|
|
|
|
+ // console.log(data, node);
|
|
this.$prompt("请输入名字", "插入节点", {
|
|
this.$prompt("请输入名字", "插入节点", {
|
|
confirmButtonText: "确定",
|
|
confirmButtonText: "确定",
|
|
cancelButtonText: "取消"
|
|
cancelButtonText: "取消"
|
|
@@ -140,6 +162,9 @@ export default {
|
|
console.log("删除节点", res);
|
|
console.log("删除节点", res);
|
|
this.$refs.tree.remove(node);
|
|
this.$refs.tree.remove(node);
|
|
this.loading = false;
|
|
this.loading = false;
|
|
|
|
+ this.$nextTick(() => {
|
|
|
|
+ this.$emit("check-node", this.$refs.tree.getCheckedNodes()); //返回所有节点
|
|
|
|
+ });
|
|
// this.expand = true;
|
|
// this.expand = true;
|
|
})
|
|
})
|
|
.catch(e => {
|
|
.catch(e => {
|
|
@@ -166,8 +191,11 @@ export default {
|
|
console.log(data.id, data);
|
|
console.log(data.id, data);
|
|
data.name = value;
|
|
data.name = value;
|
|
this.$refs.tree.updateKeyChildren(data.id, data);
|
|
this.$refs.tree.updateKeyChildren(data.id, data);
|
|
- this.$forceUpdate();
|
|
|
|
|
|
+ // this.$forceUpdate();
|
|
this.loading = false;
|
|
this.loading = false;
|
|
|
|
+ this.$nextTick(() => {
|
|
|
|
+ this.$emit("check-node", this.$refs.tree.getCheckedNodes()); //返回所有节点
|
|
|
|
+ });
|
|
})
|
|
})
|
|
.catch(e => {
|
|
.catch(e => {
|
|
this.loading = false;
|
|
this.loading = false;
|
|
@@ -181,6 +209,15 @@ export default {
|
|
console.log("取消修改", e);
|
|
console.log("取消修改", e);
|
|
});
|
|
});
|
|
},
|
|
},
|
|
|
|
+ /** 选择状态改变
|
|
|
|
+ * @param {Object} data 节点详细数据
|
|
|
|
+ * @param {Boolean} checked 是否被选中
|
|
|
|
+ * @param {Boolean} indeterminate 是否内部被选择部分
|
|
|
|
+ */
|
|
|
|
+ handleCheckChange(data, checked, indeterminate) {
|
|
|
|
+ // console.log(data, checked, indeterminate);
|
|
|
|
+ this.$emit("check-node", this.$refs.tree.getCheckedNodes()); //返回所有节点
|
|
|
|
+ },
|
|
|
|
|
|
// 以下未使用 ✳
|
|
// 以下未使用 ✳
|
|
//拖拽 更新节点
|
|
//拖拽 更新节点
|
|
@@ -239,7 +276,7 @@ export default {
|
|
align-items: center;
|
|
align-items: center;
|
|
justify-content: space-between;
|
|
justify-content: space-between;
|
|
font-size: 14px;
|
|
font-size: 14px;
|
|
- padding-right: 8px;
|
|
|
|
|
|
+ // padding-right: 8px;
|
|
.handle {
|
|
.handle {
|
|
// background-color: #ccc;
|
|
// background-color: #ccc;
|
|
padding: 0px 5px;
|
|
padding: 0px 5px;
|
|
@@ -248,7 +285,5 @@ export default {
|
|
line-height: 15px;
|
|
line-height: 15px;
|
|
margin-left: 30px;
|
|
margin-left: 30px;
|
|
}
|
|
}
|
|
- .content {
|
|
|
|
- }
|
|
|
|
}
|
|
}
|
|
</style>
|
|
</style>
|