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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
<template>
<div class="context-tree-cmp">
<el-form :model="form">
<el-form-item label="上下文类型">
<el-select v-model="form.app" placeholder="选择上下文类型进行查询" @change="onAppChange">
<el-option
v-for="item in appList"
:key="item.value"
:label="item.label"
:value="item.value"
/>
</el-select>
</el-form-item>
</el-form>
<div class="root">
<span>Root</span>
<span class="add-root" @click="addRootNode" />
</div>
<div class="tree-wrap">
<DeeDefaultTree
:key="cmpKey"
ref="defTree"
type-name="DxContext"
:base="treeBase"
:tree-obj="treeTools"
@handerTreeFun="onTreeClick"
@nodeClick="onNodeClick"
/>
</div>
</div>
</template>
<script>
// import _get from 'lodash.get'
export default {
name: 'ContextTree',
props: {
appList: {
type: Array,
default: () => []
},
stateOption: {
type: Array,
default: () => []
}
},
data() {
const that = this
return {
form: {
app: 1
},
cmpKey: 0,
treeBase: {
isPaging: true,
isShowSerach: false,
isAutoLoadData: true,
pageSize: 50,
searchItemsParams: null,
url: '/DxContext/getAllContext',
// 查询根节点的时候默认给的 parentId
defaultParentId: 0,
labelWord: (data, node) => {
const names = []
const subType = (that.appList || []).find(m => m.value === data.subTypeName)
data.name && names.push(data.name)
subType && names.push(subType.label)
if (that.stateOption.length > 0 || data.state) {
const item = that.stateOption.find(m => m.value === data.state)
item && names.push(item.label)
}
return names.join(' | ')
}
},
treeTools: {
nodeTools: [
{
icon: '/icons/add-L.png',
name: '添加',
btnValue: 'addNode',
obscure: '!node.data.operationFlag'
// keyName: 'addNode',
// key: 'addNode'
},
{
icon: '/icons/edit-L.png',
name: '编辑',
btnValue: 'editNode',
obscure: '!node.data.operationFlag'
},
{
icon: '/icons/delete-L.png',
name: '删除',
btnValue: 'delNode',
obscure: '!node.data.operationFlag'
}
]
}
}
},
methods: {
updateTree(data, type) {
if (type && type === 'MODIFY') {
this.$refs.defTree.updateTreeNode(data)
} else {
this.cmpKey = ~~(!this.cmpKey)
}
},
onAppChange(val) {
let params = null
if (val !== 1) {
params = [{ fieldName: 'subTypeName', operator: 'EQ', value: val }]
}
this.treeBase = {
...this.treeBase,
searchItemsParams: params ? JSON.stringify(params) : ''
}
},
onTreeClick(item, data, node) {
this[item.btnValue](data, node)
},
onNodeClick(data) {
this.$emit('getList', data)
},
addRootNode() {
this.$emit('handleEditGroup', false, null)
},
addNode(data) {
this.$emit('handleEditGroup', false, data)
},
editNode(data) {
this.$emit('handleEditGroup', true, data)
},
delNode(data) {
this.$emit('handleDelGroup', data)
}
}
}
</script>
<style lang="scss">
.context-tree-cmp {
height: 100%;
.el-form-item {
margin-bottom: 0;
}
.el-select {
width:calc(100% - 82px)
}
.tree-wrap {
height: calc(100% - 75px);
overflow-y: auto;
}
.root{
display: flex;
justify-content: space-between;
padding:0 8px;
height: 40px;
line-height: 40px;
// &:hover .add-root{
// visibility: visible;
// }
.add-root{
display: inline-block;
width:14px;
height:14px;
margin: auto 4px;
background-size: cover;
background-position: center;
background-image: url('/icons/add-L.png');
// visibility: hidden;
}
}
}
</style>