main.vue
2.2 KB
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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
<template>
<div class="menu-box box">
<div class="title">{{title}}</div>
<div class="console-btn">
<div><gl-button @click="openAll(openOrClose)">{{openOrClose ? '全部展开' : '全部收起'}}</gl-button></div>
<div><gl-button @click="pushSublings" type='primary' :disabled="value.push">添加同级菜单</gl-button></div>
<div><gl-button @click="pushChildren" type='primary' :disabled="value.push">添加子菜单</gl-button></div>
</div>
<tree
ref='tree'
@node-click='nodeClick'
></tree>
</div>
</template>
<script type='text/ecmascript-6'>
const timeTip = '系统自动生成(格式yyyy-MM-dd HH:mm:ss)'
export default {
name: 'leftManager',
data() {
return {
openOrClose: true
}
},
props: {
value: null,
title: {
type: String,
default: '标题'
},
nodeClick: {
type: Function,
default: () => {
return null
}
}
},
methods: {
// 展开与关闭
openAll(val) {
this.searchChildren(this.$refs.tree.$children[0].$children[0].store._getAllNodes(), val)
this.openOrClose = !this.openOrClose
},
searchChildren(data, val) {
data.forEach(el => {
this.$set(el, 'expanded', val)
if (el.childNodes) {
this.searchChildren(el.childNodes, val)
}
})
},
// 添加同级菜单
pushSublings() {
this.value.sublings = true
this.clearFrom()
},
// 添加子菜单
pushChildren() {
this.value.children = true
this.clearFrom()
},
clearFrom() {
this.value.btnTxt = '保存'
this.value.del = false
for (const key in this.value.form) {
this.value.form[key] = null
}
if (this.value.form.createTime !== undefined) {
this.value.form.createTime = timeTip
this.value.form.changeTime = timeTip
}
}
}
}
</script>
<style scoped>
.console-btn{
padding: 15px;
display: flex;
flex-wrap:wrap;
width: 100%;
box-sizing: border-box;
}
.console-btn div{
flex: 1;
height: 40px;
margin-bottom: 10px;
text-align: center;
}
.console-btn div button{
width: 126px;
box-sizing: border-box
}
</style>