| 
1
 | 
 <template>
 | 
1
 | 
 <template>
 | 
| 
2
 | 
     <div class="main">
 | 
2
 | 
     <div class="main">
 | 
| 
3
 | 
-    <div id="edit">
 | 
 | 
   | 
| 
4
 | 
-
 | 
3
 | 
+        <div class="header">
 | 
| 
 | 
   | 
4
 | 
+            <div class="item" style="width: 20px;background-color:#a1dcf8;text-align: center;" title="新建栏">
 | 
| 
 | 
   | 
5
 | 
+                <svg @click="add"
 | 
| 
 | 
   | 
6
 | 
+                     style="width: 1em;height: 1em;vertical-align: middle;fill: currentColor;overflow: hidden;"
 | 
| 
 | 
   | 
7
 | 
+                     viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="2498">
 | 
| 
 | 
   | 
8
 | 
+                    <path d="M576 448h384v128H576v384H448V576H64V448h384V64h128z" fill="#4A4A4A" p-id="2499"></path>
 | 
| 
 | 
   | 
9
 | 
+                </svg>
 | 
| 
 | 
   | 
10
 | 
+            </div>
 | 
| 
 | 
   | 
11
 | 
+            <div v-for="(item,index) in items" :key="item.id">
 | 
| 
 | 
   | 
12
 | 
+                <div
 | 
| 
 | 
   | 
13
 | 
+                    :class="{item:1,active:index===useKey}"
 | 
| 
 | 
   | 
14
 | 
+                    @click="load(index)"
 | 
| 
 | 
   | 
15
 | 
+                    :key="item.id">
 | 
| 
 | 
   | 
16
 | 
+                    <el-popover placement="bottom" trigger="contextmenu">
 | 
| 
 | 
   | 
17
 | 
+                        <template #reference> <span>{{item.name}}</span></template>
 | 
| 
 | 
   | 
18
 | 
+                        <template #default>
 | 
| 
 | 
   | 
19
 | 
+                            <div style="display: flex;width: 300px;">
 | 
| 
 | 
   | 
20
 | 
+                                <el-input v-model="item.name" style="min-width: 200px;"></el-input>
 | 
| 
 | 
   | 
21
 | 
+                                <el-button v-if="index>0" type="danger" style="margin-left: 20px;" @click="del(index)">删除</el-button>
 | 
| 
 | 
   | 
22
 | 
+                            </div>
 | 
| 
 | 
   | 
23
 | 
+                        </template>
 | 
| 
 | 
   | 
24
 | 
+                    </el-popover>
 | 
| 
 | 
   | 
25
 | 
+                </div>
 | 
| 
5
 | 
             </div>
 | 
26
 | 
             </div>
 | 
| 
6
 | 
-    <div id="result">
 | 
 | 
   | 
| 
7
 | 
 
 | 
27
 | 
 
 | 
| 
8
 | 
         </div>
 | 
28
 | 
         </div>
 | 
| 
9
 | 
-    <el-button class="submit" @click="submit" :loading="loading">提交</el-button>
 | 
29
 | 
+        <div>
 | 
| 
 | 
   | 
30
 | 
+            <kibanaitem ref="kibana"></kibanaitem>
 | 
| 
 | 
   | 
31
 | 
+        </div>
 | 
| 
10
 | 
     </div>
 | 
32
 | 
     </div>
 | 
| 
11
 | 
 </template>
 | 
33
 | 
 </template>
 | 
| 
12
 | 
 
 | 
34
 | 
 
 | 
 | 
@@ -17,66 +39,104 @@ export default { | 
 | 
@@ -17,66 +39,104 @@ export default { | 
| 
17
 | 
     name: "kibana",
 | 
39
 | 
     name: "kibana",
 | 
| 
18
 | 
     data() {
 | 
40
 | 
     data() {
 | 
| 
19
 | 
         return {
 | 
41
 | 
         return {
 | 
| 
20
 | 
-      loading:false,
 | 
 | 
   | 
| 
21
 | 
-      editor: null,
 | 
 | 
   | 
| 
22
 | 
-      result: null
 | 
42
 | 
+            useKey: 0,
 | 
| 
 | 
   | 
43
 | 
+            items:[]
 | 
| 
23
 | 
         }
 | 
44
 | 
         }
 | 
| 
24
 | 
     },
 | 
45
 | 
     },
 | 
| 
25
 | 
     created() {},
 | 
46
 | 
     created() {},
 | 
| 
26
 | 
     methods: {
 | 
47
 | 
     methods: {
 | 
| 
27
 | 
-    submit(){
 | 
 | 
   | 
| 
28
 | 
-      const data = {
 | 
 | 
   | 
| 
29
 | 
-        json:this.editor.get()
 | 
 | 
   | 
| 
30
 | 
-      };
 | 
 | 
   | 
| 
31
 | 
-      console.log(data)
 | 
 | 
   | 
| 
32
 | 
-      this.loading = true;
 | 
 | 
   | 
| 
33
 | 
-      ajax().post('/kibana.result',data).then(res=>{
 | 
 | 
   | 
| 
34
 | 
-        console.log(res)
 | 
 | 
   | 
| 
35
 | 
-        this.loading = false;
 | 
 | 
   | 
| 
36
 | 
-        this.result.set(res);
 | 
48
 | 
+        save(){
 | 
| 
 | 
   | 
49
 | 
+
 | 
| 
 | 
   | 
50
 | 
+            let q = this.$refs.kibana.getQuery();
 | 
| 
 | 
   | 
51
 | 
+            let r = this.$refs.kibana.getResult();
 | 
| 
 | 
   | 
52
 | 
+            if(q){
 | 
| 
 | 
   | 
53
 | 
+                this.items[this.useKey].query = JSON.parse(JSON.stringify(q));
 | 
| 
 | 
   | 
54
 | 
+            }
 | 
| 
 | 
   | 
55
 | 
+            if(r){
 | 
| 
 | 
   | 
56
 | 
+                this.items[this.useKey].result = JSON.parse(JSON.stringify(r));
 | 
| 
 | 
   | 
57
 | 
+            }
 | 
| 
 | 
   | 
58
 | 
+
 | 
| 
 | 
   | 
59
 | 
+            window.localStorage.setItem('kibana',JSON.stringify(this.items));
 | 
| 
 | 
   | 
60
 | 
+
 | 
| 
 | 
   | 
61
 | 
+            window.localStorage.setItem('kibana_key',this.useKey);
 | 
| 
 | 
   | 
62
 | 
+        },
 | 
| 
 | 
   | 
63
 | 
+        del(index){
 | 
| 
 | 
   | 
64
 | 
+            if(this.items.length===1) return;
 | 
| 
 | 
   | 
65
 | 
+            this.items.splice(index,1);
 | 
| 
 | 
   | 
66
 | 
+        },
 | 
| 
 | 
   | 
67
 | 
+        add(){
 | 
| 
 | 
   | 
68
 | 
+            this.items.push({
 | 
| 
 | 
   | 
69
 | 
+                id: parseInt((Math.random()*100000)+''),
 | 
| 
 | 
   | 
70
 | 
+                name:"default",
 | 
| 
 | 
   | 
71
 | 
+                query:{},
 | 
| 
 | 
   | 
72
 | 
+                result:{}
 | 
| 
37
 | 
             })
 | 
73
 | 
             })
 | 
| 
 | 
   | 
74
 | 
+        },
 | 
| 
 | 
   | 
75
 | 
+        load(val){
 | 
| 
 | 
   | 
76
 | 
+
 | 
| 
 | 
   | 
77
 | 
+            if(this.useKey!==val){
 | 
| 
 | 
   | 
78
 | 
+                this.save();
 | 
| 
 | 
   | 
79
 | 
+
 | 
| 
 | 
   | 
80
 | 
+                this.useKey = val;
 | 
| 
 | 
   | 
81
 | 
+            }
 | 
| 
 | 
   | 
82
 | 
+
 | 
| 
 | 
   | 
83
 | 
+            this.$refs.kibana.setQuery(JSON.parse(JSON.stringify(this.items[val].query)));
 | 
| 
 | 
   | 
84
 | 
+            this.$refs.kibana.setResult(JSON.parse(JSON.stringify(this.items[val].result)));
 | 
| 
38
 | 
         }
 | 
85
 | 
         }
 | 
| 
39
 | 
     },
 | 
86
 | 
     },
 | 
| 
40
 | 
     mounted() {
 | 
87
 | 
     mounted() {
 | 
| 
41
 | 
 
 | 
88
 | 
 
 | 
| 
42
 | 
-    this.editor = new JSONEditor(document.getElementById("edit"), {
 | 
 | 
   | 
| 
43
 | 
-      mode:"code",
 | 
 | 
   | 
| 
44
 | 
-      enableSort: false,
 | 
 | 
   | 
| 
45
 | 
-      enableTransform: false,
 | 
 | 
   | 
| 
46
 | 
-    });
 | 
89
 | 
+        this.items = JSON.parse(window.localStorage.getItem('kibana')) || [];
 | 
| 
 | 
   | 
90
 | 
+
 | 
| 
 | 
   | 
91
 | 
+        let index = parseInt(window.localStorage.getItem('kibana_key'));
 | 
| 
 | 
   | 
92
 | 
+        if(typeof this.items[index] === "undefined"){
 | 
| 
 | 
   | 
93
 | 
+            this.useKey = 0;
 | 
| 
 | 
   | 
94
 | 
+        }else {
 | 
| 
 | 
   | 
95
 | 
+            this.useKey = index;
 | 
| 
 | 
   | 
96
 | 
+        }
 | 
| 
 | 
   | 
97
 | 
+
 | 
| 
 | 
   | 
98
 | 
+        if (this.items.length === 0) this.add();
 | 
| 
 | 
   | 
99
 | 
+
 | 
| 
 | 
   | 
100
 | 
+        this.load(this.useKey);
 | 
| 
47
 | 
 
 | 
101
 | 
 
 | 
| 
48
 | 
-    this.result = new JSONEditor(document.getElementById("result"), {
 | 
 | 
   | 
| 
49
 | 
-      mode:"code",
 | 
 | 
   | 
| 
50
 | 
-      enableSort: false,
 | 
 | 
   | 
| 
51
 | 
-      enableTransform: false,
 | 
 | 
   | 
| 
52
 | 
-      editable : false,
 | 
 | 
   | 
| 
53
 | 
-      mainMenuBar : false
 | 
 | 
   | 
| 
54
 | 
-    });
 | 
102
 | 
+        setInterval(() => {
 | 
| 
 | 
   | 
103
 | 
+            this.save();
 | 
| 
 | 
   | 
104
 | 
+        },1000)
 | 
| 
55
 | 
 
 | 
105
 | 
 
 | 
| 
 | 
   | 
106
 | 
+
 | 
| 
 | 
   | 
107
 | 
+    },
 | 
| 
 | 
   | 
108
 | 
+    //加载组件
 | 
| 
 | 
   | 
109
 | 
+    components: {
 | 
| 
 | 
   | 
110
 | 
+        kibanaitem:"@component(kibanaItem)"
 | 
| 
56
 | 
     }
 | 
111
 | 
     }
 | 
| 
57
 | 
 }
 | 
112
 | 
 }
 | 
| 
58
 | 
 </script>
 | 
113
 | 
 </script>
 | 
| 
59
 | 
 
 | 
114
 | 
 
 | 
| 
60
 | 
 <style scoped>
 | 
115
 | 
 <style scoped>
 | 
| 
61
 | 
 .main{
 | 
116
 | 
 .main{
 | 
| 
62
 | 
-  display: flex;
 | 
 | 
   | 
| 
63
 | 
     position: fixed;
 | 
117
 | 
     position: fixed;
 | 
| 
64
 | 
     top: 0;
 | 
118
 | 
     top: 0;
 | 
| 
65
 | 
     left: 0;
 | 
119
 | 
     left: 0;
 | 
| 
66
 | 
     width: 100%;
 | 
120
 | 
     width: 100%;
 | 
| 
67
 | 
     height: 100%;
 | 
121
 | 
     height: 100%;
 | 
| 
68
 | 
 }
 | 
122
 | 
 }
 | 
| 
69
 | 
-#edit{
 | 
 | 
   | 
| 
70
 | 
-  width: 50%;
 | 
123
 | 
+.header{
 | 
| 
 | 
   | 
124
 | 
+    display: flex;
 | 
| 
 | 
   | 
125
 | 
+    height: 32px;
 | 
| 
 | 
   | 
126
 | 
+    background-color: #d0dbf0;
 | 
| 
71
 | 
 }
 | 
127
 | 
 }
 | 
| 
72
 | 
-#result{
 | 
 | 
   | 
| 
73
 | 
-  width: 50%;
 | 
128
 | 
+.item{
 | 
| 
 | 
   | 
129
 | 
+    height: 22px;
 | 
| 
 | 
   | 
130
 | 
+    line-height: 22px;
 | 
| 
 | 
   | 
131
 | 
+    padding: 5px 10px;
 | 
| 
 | 
   | 
132
 | 
+    cursor: pointer;
 | 
| 
74
 | 
 }
 | 
133
 | 
 }
 | 
| 
75
 | 
-.submit{
 | 
 | 
   | 
| 
76
 | 
-  position: fixed;
 | 
 | 
   | 
| 
77
 | 
-  top: 2px;
 | 
 | 
   | 
| 
78
 | 
-  left: calc(50% - 82px);
 | 
 | 
   | 
| 
79
 | 
-  z-index: 9999;
 | 
 | 
   | 
| 
80
 | 
-  width: 80px;
 | 
134
 | 
+.item.active{
 | 
| 
 | 
   | 
135
 | 
+    background-color: #fff;
 | 
| 
 | 
   | 
136
 | 
+}
 | 
| 
 | 
   | 
137
 | 
+</style>
 | 
| 
 | 
   | 
138
 | 
+<style>
 | 
| 
 | 
   | 
139
 | 
+.el-popper.el-tooltip.el-popover{
 | 
| 
 | 
   | 
140
 | 
+    width: auto !important;
 | 
| 
81
 | 
 }
 | 
141
 | 
 }
 | 
| 
82
 | 
 </style> | 
142
 | 
 </style> |