Device1078Tree.vue
6.36 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
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
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
<template>
<div class="device-tree-main-box">
<div id="DeviceTree" style="width: 100%;height: 100%; background-color: #FFFFFF; overflow: auto">
<el-container>
<el-header>设备列表</el-header>
<el-main style="background-color: #ffffff;">
<el-input
placeholder="输入关键字进行过滤"
v-model="filterText">
</el-input>
<el-tree
class="filter-tree"
:data="treeData"
:props="defaultProps"
:default-expanded-keys="expandedKeys"
node-key="id"
ref="tree"
:highlight-current="true"
:filter-node-method="filterNode"
:check-strictly="true"
@node-click="nodeClick"
@node-contextmenu="nodeContextmenu"
:expand-on-click-node="false"
@node-expand="handleNodeExpand"
@node-collapse="handleNodeCollapse"
style="margin-top: 10px"
>
<span class="custom-tree-node" slot-scope="{ node, data }">
<el-tooltip :disabled="data.abnormalStatus === undefined"
:visible="tooltipVisible && hoveredNode === data" placement="right"
>
<div slot="content" style="line-height: 23px">
<b style="font-size: medium;margin-bottom: 10px">{{ `车牌号: ${data.carPlate}` }}</b><br>
状态: <span class="status green" v-if="data.abnormalStatus === 1"><span class="dot"></span> 在线</span>
<span class="status red" v-else-if="data.abnormalStatus === 20"><span class="dot"></span> 离线</span>
<span v-else> 未接入</span><br>
</div>
<span v-if="data.abnormalStatus !== undefined && data.children && data.abnormalStatus === 1">
<i class="el-icon-location" style="color: #409EFF"></i>{{ `${data.name}(在线)` }}
</span>
<span v-if="data.abnormalStatus !== undefined && data.abnormalStatus === 20">
<i class="el-icon-location" style="color: #909399"></i>{{ `${data.name}(离线)` }}
</span>
<span v-if="data.abnormalStatus !== undefined && data.abnormalStatus === 10">
<i class="el-icon-location" style="color: #909399"></i>{{ `${data.name}(未接入)` }}
</span>
<span v-if="data.abnormalStatus === undefined && data.children && data.children.length > 0 ">
{{ `${data.name}(${data.onlineData.length}/${data.children.length})` }}
</span>
<span v-if="data.abnormalStatus === undefined && data.children && data.children.length === 0 ">
{{ `${data.name}(0/0)` }}
</span>
<span v-if="data.abnormalStatus === undefined && data.children === undefined ">
<i class="el-icon-video-camera-solid"> </i>{{ `${data.name}` }}
</span>
</el-tooltip>
</span>
</el-tree>
</el-main>
</el-container>
</div>
</div>
</template>
<script>
//这里可以导入其他文件(比如:组件,工具js,第三方插件js,json文件,图片文件等等),
//例如:import 《组件名称》 from '《组件路径》,
export default {
//import引入的组件需要注入到对象中才能使用"
components: {},
props: {
//树 数据
treeData: {
type: Array,
default: []
},
},
data() {
//这里存放数据"
return {
//搜索值
filterText: '',
//默认的prop
defaultProps: {
label: 'name',
children: 'children',
},
pointsList: [],
expandedKeys: [],
tooltipVisible: false,
hoveredNode: null,
};
},
//计算属性 类似于data概念",
computed: {
},
//监控data中的数据变化",
watch: {
filterText(val) {
this.$refs.tree.filter(val);
},
treeData(val) {
console.log(val);
this.treeData = val
}
},
//方法集合",
methods: {
handleNodeExpand(data, node, el) {
if (!this.expandedKeys.includes(node.key)) {
this.expandedKeys.push(node.key);
}
},
handleNodeCollapse(data, node, el) {
const index = this.expandedKeys.indexOf(node.key);
if (index > -1) {
this.expandedKeys.splice(index, 1);
}
},
/**
* 模糊查询树
*/
filterNode(value, data, node) {
if (!value) return true;
return this.findSearKey(node, value)
},
/**
* 点击事件
*/
nodeClick(data, node, fun){
console.log(data)
console.log("node ===> ", node)
this.$emit('node-click', data, node);
},
nodeContextmenu(event, data, node, fun){
},
//递归搜索父级是否包含关键字
findSearKey(node, key) {
if (node.label.indexOf(key) !== -1) {
return true;
} else {
if (node.parent.parent == null) {
return false;
} else {
return this.findSearKey(node.parent, key);
}
}
},
},
//生命周期 - 创建完成(可以访问当前this实例)",
created() {
},
//生命周期 - 挂载完成(可以访问DOM元素)",
mounted() {
},
beforeCreate() {
}, //生命周期 - 创建之前",
beforeMount() {
}, //生命周期 - 挂载之前",
beforeUpdate() {
}, //生命周期 - 更新之前",
updated() {
}, //生命周期 - 更新之后",
beforeDestroy() {
}, //生命周期 - 销毁之前",
destroyed() {
}, //生命周期 - 销毁完成",
activated() {
} //如果页面有keep-alive缓存功能,这个函数会触发",
};
</script>
<style>
/* 覆盖默认高亮背景色 */
.el-tree--highlight-current .el-tree-node.is-current > .el-tree-node__content {
background-color: #ffd591 !important; /* 橙色示例 */
}
.el-tree-node.is-current > .el-tree-node__content .el-tree-node__label {
font-weight: bold;
color: #1890ff;
}
.dot {
width: 10px;
height: 10px;
border-radius: 50%;
display: inline-block;
}
.green .dot {
background-color: #28a745;
}
.red .dot {
background-color: #dc3545;
}
</style>