1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
| <template>
| <el-dialog
| title="选择父级菜单"
| :visible.sync="open"
| width="30%"
| :destroy-on-close="true"
| :close-on-click-modal="false"
| :append-to-body="true">
| <el-tree
| style="padding-bottom: 30px"
| ref="tree"
| :data="treeData"
| node-key="id"
| :expand-on-click-node="false"
| :default-expand-all="false"
| :highlight-current="true"
| :check-strictly="true"
| @check-change="setCurrentCheck"
| :default-expanded-keys="[1, 1]"
| show-checkbox
| :props="defaultProps">
| </el-tree>
| <div slot="footer" class="dialog-footer">
| <el-button @click="close" size="small">取 消</el-button>
| <el-button type="primary" @click="save" size="small">确 定</el-button>
| </div>
| </el-dialog>
| </template>
|
| <script>
| export default {
| name: "TreeDialog",
| data() {
| return {
| open: false,
| selectMenu: null,
| defaultProps: {
| children: 'children',
| label: 'menuName'
| }
| }
| },
| props: {
| treeData: {
| type: Array
| }
| },
| methods: {
| // 回显
| setChecked(id) {
| this.open = true
| this.$nextTick(() => {
| if (id) {
| this.$refs.tree.setCheckedKeys([id])
| }
| })
| },
| // 单选控制
| setCurrentCheck(data, checked) {
| if (checked) {
| this.$refs.tree.setCheckedKeys([data.id])
| this.selectMenu = data
| } else {
| this.selectMenu = null
| }
| },
| save(){
| this.$emit("save", this.selectMenu)
| },
| close() {
| this.open = false
| },
| }
| }
| </script>
|
| <style scoped>
|
| </style>
|
|