index.vue 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184
  1. <template>
  2. <el-container style="height: calc(100vh - 50px);">
  3. <el-header style="line-height: 60px;display:none;">
  4. <el-input placeholder="请输入关键字" v-model="search.term"
  5. clearable
  6. @clear="onClear">
  7. <el-button slot="append" icon="el-icon-search" @click="onSearch" :loading="search.loading"></el-button>
  8. </el-input>
  9. </el-header>
  10. <el-main style="overflow: hidden;height: 100%;padding:0px;" v-if="search.result && search.result.all.length>0">
  11. <div style="width:98%;padding:10px;background:#f2f2f2;display:flex;flex-wrap:wrap;align-items:flex-start;">
  12. <el-button type="text" class="el-icon-s-data"> 结果</el-button>
  13. <template v-for="(v,k) in search.result">
  14. <el-button type="default"
  15. :key="k"
  16. @click="onScrollTo(k)"
  17. v-if="pickIfShow(v)">
  18. {{v.title}}: {{ rowsCount(v.rows) }}
  19. </el-button>
  20. </template>
  21. </div>
  22. <el-container style="height: calc(100vh - 125px);width:100%;">
  23. <el-main style="padding:0px 0px 0px 0px;height:100%;overflow:auto;" ref="container">
  24. <!-- <el-tabs value="view">
  25. <el-tab-pane name="view" key="view">
  26. <span slot="label">按分类</span>
  27. <template v-for="(v,k) in search.result">
  28. <component
  29. :ref="k"
  30. :id="'el-'+k"
  31. v-bind:is="k" :global="global" :dt="v"
  32. :key="k" v-if="v.title && v.rows.length>0"></component>
  33. </template>
  34. </el-tab-pane>
  35. <el-tab-pane name="timeline" key="timeline">
  36. <template slot="label">时间线</template>
  37. <timeline :model="search.result" :global="global"></timeline>
  38. </el-tab-pane>
  39. </el-tabs> -->
  40. <template v-for="(v,k) in search.result">
  41. <component
  42. :ref="k"
  43. v-bind:is="k" :global="global" :dt="v"
  44. :key="k" v-if="v.title && v.show"></component>
  45. </template>
  46. </el-main>
  47. </el-container>
  48. </el-main>
  49. <el-main style="background:#ffffff;text-align:center;" v-else>
  50. </el-main>
  51. </el-container>
  52. </template>
  53. <script>
  54. import _isEmpty from 'lodash/isEmpty';
  55. import _map from 'lodash/map';
  56. import _filter from 'lodash/filter';
  57. import { scrollTo } from 'scroll-js';
  58. export default {
  59. name: "IndexView",
  60. components:{
  61. event: resolve => {require(['./event.vue'], resolve)},
  62. entity: resolve => {require(['./entity.vue'], resolve)},
  63. change: resolve => {require(['./change.vue'], resolve)},
  64. file: resolve => {require(['./file.vue'], resolve)},
  65. perf: resolve => {require(['./perf.vue'], resolve)},
  66. logs: resolve => {require(['./logs.vue'], resolve)},
  67. timeline: resolve => {require(['./timeline.vue'], resolve)}
  68. },
  69. props:{
  70. global: Object
  71. },
  72. data(){
  73. return {
  74. search:{
  75. term: "",
  76. class: {
  77. value: "/m3event/devops/alert_status"
  78. },
  79. result: null,
  80. loading: false
  81. }
  82. }
  83. },
  84. watch:{
  85. "search.term"(val){
  86. if(!val){
  87. this.onClear();
  88. }
  89. },
  90. "search.result"(val){
  91. if(val){
  92. this.$emit("open-right");
  93. }
  94. }
  95. },
  96. created(){
  97. // 初始化preset
  98. /* try{
  99. let preset = decodeURIComponent(window.atob(this.getQueryVariable('preset')));
  100. _.extend(this.options,_.attempt(JSON.parse.bind(null, preset)));
  101. } catch(err){
  102. console.error(err);
  103. } */
  104. /* document.onkeydown = ()=> {
  105. let key = window.event.keyCode;
  106. if (key == 13) {
  107. this.onSearch();
  108. }
  109. } */
  110. },
  111. methods: {
  112. pickIfShow(v){
  113. return v.title && v.show;
  114. },
  115. rowsCount(rows){
  116. return rows.length;
  117. },
  118. onScrollTo(name){
  119. let el = this.$refs[name][0].$el.offsetTop;
  120. let container = this.$refs['container'].$el;
  121. scrollTo(container, { top: el });
  122. },
  123. onClear(){
  124. this.search.result = null;
  125. },
  126. onSearch(){
  127. if(_isEmpty(this.search.term)){
  128. this.$message.info("请输入搜索关键字");
  129. return false;
  130. }
  131. this.search.result = [];
  132. this.search.loading = true;
  133. let param = encodeURIComponent( JSON.stringify( {term:this.search.term, preset:null} ) );
  134. this.m3.callFS("/matrix/m3graph/search/searchByTerm.js", param).then(res=>{
  135. this.search.result = res.message;
  136. console.log(111,this.search.result)
  137. this.search.loading = false;
  138. }).catch(err=>{
  139. this.search.loading = false;
  140. })
  141. },
  142. getQueryVariable(variable){
  143. var query = window.location.search.substring(1);
  144. var vars = query.split("&");
  145. for (var i=0;i<vars.length;i++) {
  146. var pair = vars[i].split("=");
  147. if(pair[0] == variable){return pair[1];}
  148. }
  149. return(false);
  150. },
  151. weclome(){
  152. this.m3.callFS("/matrix/m3graph/search/weclome.js",null).then( (rtn)=>{
  153. let message = rtn.message;
  154. this.$notify({
  155. title: '欢迎使用一键搜索',
  156. type: 'success',
  157. dangerouslyUseHTMLString: true,
  158. message: message
  159. });
  160. } );
  161. }
  162. }
  163. }
  164. </script>
  165. <style scoped>
  166. </style>