kibana.vue
3.9 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
<template>
<div class="main">
<div class="header">
<div class="item" style="width: 20px;background-color:#a1dcf8;text-align: center;" title="新建栏">
<svg @click="add"
style="width: 1em;height: 1em;vertical-align: middle;fill: currentColor;overflow: hidden;"
viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="2498">
<path d="M576 448h384v128H576v384H448V576H64V448h384V64h128z" fill="#4A4A4A" p-id="2499"></path>
</svg>
</div>
<div v-for="(item,index) in items" :key="item.id">
<div
:class="{item:1,active:index===useKey}"
@click="load(index)"
:key="item.id">
<el-popover placement="bottom" trigger="contextmenu">
<template #reference> <span>{{item.name}}</span></template>
<template #default>
<div style="display: flex;width: 300px;">
<el-input v-model="item.name" style="min-width: 200px;"></el-input>
<el-button v-if="index>0" type="danger" style="margin-left: 20px;" @click="del(index)">删除</el-button>
</div>
</template>
</el-popover>
</div>
</div>
</div>
<div>
<kibanaitem ref="kibana"></kibanaitem>
</div>
</div>
</template>
<script>
@import("/static/css/jsoneditor.min.css")
@import("/static/js/jsoneditor.min.js")
export default {
name: "kibana",
data() {
return {
useKey: 0,
items:[]
}
},
created() {},
methods: {
save(){
let q = this.$refs.kibana.getQuery();
let r = this.$refs.kibana.getResult();
if(q){
this.items[this.useKey].query = JSON.parse(JSON.stringify(q));
}
if(r){
this.items[this.useKey].result = JSON.parse(JSON.stringify(r));
}
window.localStorage.setItem('kibana',JSON.stringify(this.items));
window.localStorage.setItem('kibana_key',this.useKey);
},
del(index){
if(this.items.length===1) return;
this.items.splice(index,1);
},
add(){
this.items.push({
id: parseInt((Math.random()*100000)+''),
name:"default",
query:{},
result:{}
})
},
load(val){
if(this.useKey!==val){
this.save();
this.useKey = val;
}
this.$refs.kibana.setQuery(JSON.parse(JSON.stringify(this.items[val].query)));
this.$refs.kibana.setResult(JSON.parse(JSON.stringify(this.items[val].result)));
}
},
mounted() {
this.items = JSON.parse(window.localStorage.getItem('kibana')) || [];
let index = parseInt(window.localStorage.getItem('kibana_key'));
if(typeof this.items[index] === "undefined"){
this.useKey = 0;
}else {
this.useKey = index;
}
if (this.items.length === 0) this.add();
this.load(this.useKey);
setInterval(() => {
this.save();
},1000)
},
//加载组件
components: {
kibanaitem:"@component(kibanaItem)"
}
}
</script>
<style scoped>
.main{
position: fixed;
top: 0;
left: 0;
width: 100%;
height: 100%;
}
.header{
display: flex;
height: 32px;
background-color: #d0dbf0;
}
.item{
height: 22px;
line-height: 22px;
padding: 5px 10px;
cursor: pointer;
}
.item.active{
background-color: #fff;
}
</style>
<style>
.el-popper.el-tooltip.el-popover{
width: auto !important;
}
</style>