Explorar el Código

优化菜单搜索查询页

RuoYi hace 1 año
padre
commit
60e2d55a23
Se han modificado 1 ficheros con 89 adiciones y 54 borrados
  1. 89 54
      ruoyi-ui/src/components/HeaderSearch/index.vue

+ 89 - 54
ruoyi-ui/src/components/HeaderSearch/index.vue

@@ -1,25 +1,44 @@
1 1
 <template>
2
-  <div :class="{'show':show}" class="header-search">
2
+  <div class="header-search">
3 3
     <svg-icon class-name="search-icon" icon-class="search" @click.stop="click" />
4
-    <el-select
5
-      ref="headerSearchSelect"
6
-      v-model="search"
7
-      :remote-method="querySearch"
8
-      filterable
9
-      default-first-option
10
-      remote
11
-      placeholder="Search"
12
-      class="header-search-select"
13
-      @change="change"
4
+    <el-dialog
5
+      :visible.sync="show"
6
+      width="600px"
7
+      @close="close"
8
+      :show-close="false"
9
+      append-to-body
14 10
     >
15
-      <el-option v-for="option in options" :key="option.item.path" :value="option.item" :label="option.item.title.join(' > ')" />
16
-    </el-select>
11
+      <el-input
12
+        v-model="search"
13
+        ref="headerSearchSelectRef"
14
+        size="large"
15
+        @input="querySearch"
16
+        prefix-icon="Search"
17
+        placeholder="菜单搜索,支持标题、URL模糊查询"
18
+      >
19
+      </el-input>
20
+      <el-scrollbar wrap-class="right-scrollbar-wrapper">
21
+        <div class="result-wrap">
22
+          <div class="search-item" v-for="item in options" :key="item.path">
23
+            <div class="left">
24
+              <svg-icon class="menu-icon" :icon-class="item.icon" />
25
+            </div>
26
+            <div class="search-info" @click="change(item)">
27
+              <div class="menu-title">
28
+                {{ item.title.join(" / ") }}
29
+              </div>
30
+              <div class="menu-path">
31
+                {{ item.path }}
32
+              </div>
33
+            </div>
34
+          </div>
35
+       </div>
36
+      </el-scrollbar>
37
+    </el-dialog>
17 38
   </div>
18 39
 </template>
19 40
 
20 41
 <script>
21
-// fuse is a lightweight fuzzy-search module
22
-// make search results more in line with expectations
23 42
 import Fuse from 'fuse.js/dist/fuse.min.js'
24 43
 import path from 'path'
25 44
 import { isHttp } from '@/utils/validate'
@@ -46,13 +65,6 @@ export default {
46 65
     },
47 66
     searchPool(list) {
48 67
       this.initFuse(list)
49
-    },
50
-    show(value) {
51
-      if (value) {
52
-        document.body.addEventListener('click', this.close)
53
-      } else {
54
-        document.body.removeEventListener('click', this.close)
55
-      }
56 68
     }
57 69
   },
58 70
   mounted() {
@@ -63,23 +75,25 @@ export default {
63 75
       this.show = !this.show
64 76
       if (this.show) {
65 77
         this.$refs.headerSearchSelect && this.$refs.headerSearchSelect.focus()
78
+        this.options = this.searchPool
66 79
       }
67 80
     },
68 81
     close() {
69 82
       this.$refs.headerSearchSelect && this.$refs.headerSearchSelect.blur()
83
+      this.search = ''
70 84
       this.options = []
71 85
       this.show = false
72 86
     },
73 87
     change(val) {
74
-      const path = val.path;
75
-      const query = val.query;
88
+      const path = val.path
89
+      const query = val.query
76 90
       if(isHttp(val.path)) {
77 91
         // http(s):// 路径新窗口打开
78 92
         const pindex = path.indexOf("http");
79
-        window.open(path.substr(pindex, path.length), "_blank");
93
+        window.open(path.substr(pindex, path.length), "_blank")
80 94
       } else {
81 95
         if (query) {
82
-          this.$router.push({ path: path, query: JSON.parse(query) });
96
+          this.$router.push({ path: path, query: JSON.parse(query) })
83 97
         } else {
84 98
           this.$router.push(path)
85 99
         }
@@ -117,11 +131,13 @@ export default {
117 131
 
118 132
         const data = {
119 133
           path: !isHttp(router.path) ? path.resolve(basePath, router.path) : router.path,
120
-          title: [...prefixTitle]
134
+          title: [...prefixTitle],
135
+          icon: ''
121 136
         }
122 137
 
123 138
         if (router.meta && router.meta.title) {
124 139
           data.title = [...data.title, router.meta.title]
140
+          data.icon = router.meta.icon
125 141
 
126 142
           if (router.redirect !== 'noRedirect') {
127 143
             // only push the routes with title
@@ -146,51 +162,70 @@ export default {
146 162
     },
147 163
     querySearch(query) {
148 164
       if (query !== '') {
149
-        this.options = this.fuse.search(query)
165
+        this.options = this.fuse.search(query).map((item) => item.item) ?? this.searchPool
150 166
       } else {
151
-        this.options = []
167
+        this.options = this.searchPool
152 168
       }
153 169
     }
154 170
   }
155 171
 }
156 172
 </script>
157 173
 
158
-<style lang="scss" scoped>
159
-.header-search {
160
-  font-size: 0 !important;
174
+<style lang='scss' scoped>
175
+::v-deep {
176
+  .el-dialog__header {
177
+    padding: 0 !important;
178
+  }
179
+}
161 180
 
181
+.header-search {
162 182
   .search-icon {
163 183
     cursor: pointer;
164 184
     font-size: 18px;
165 185
     vertical-align: middle;
166 186
   }
187
+}
167 188
 
168
-  .header-search-select {
169
-    font-size: 18px;
170
-    transition: width 0.2s;
171
-    width: 0;
172
-    overflow: hidden;
173
-    background: transparent;
174
-    border-radius: 0;
175
-    display: inline-block;
176
-    vertical-align: middle;
189
+.result-wrap {
190
+  height: 280px;
191
+  margin: 12px 0;
177 192
 
178
-    ::v-deep .el-input__inner {
179
-      border-radius: 0;
180
-      border: 0;
181
-      padding-left: 0;
182
-      padding-right: 0;
183
-      box-shadow: none !important;
184
-      border-bottom: 1px solid #d9d9d9;
185
-      vertical-align: middle;
193
+  .search-item {
194
+    display: flex;
195
+    height: 48px;
196
+
197
+    .left {
198
+      width: 60px;
199
+      text-align: center;
200
+
201
+      .menu-icon {
202
+        width: 18px;
203
+        height: 18px;
204
+        margin-top: 5px;
205
+      }
186 206
     }
187
-  }
188 207
 
189
-  &.show {
190
-    .header-search-select {
191
-      width: 210px;
192
-      margin-left: 10px;
208
+    .search-info {
209
+      padding-left: 5px;
210
+      width: 100%;
211
+      display: flex;
212
+      flex-direction: column;
213
+      justify-content: flex-start;
214
+
215
+      .menu-title,
216
+      .menu-path {
217
+        height: 20px;
218
+      }
219
+      .menu-path {
220
+        color: #ccc;
221
+        font-size: 10px;
222
+      }
193 223
     }
194 224
   }
225
+
226
+  .search-item:hover {
227
+    cursor: pointer;
228
+  }
195 229
 }
196 230
 </style>
231
+