Browse Source

feat: 菜单搜索功能

Howie 1 year ago
parent
commit
da8fe04282
3 changed files with 44 additions and 3 deletions
  1. 30 2
      src/layout/components/Navbar.vue
  2. 11 0
      src/permission.js
  3. 3 1
      src/settings.js

+ 30 - 2
src/layout/components/Navbar.vue

@@ -16,6 +16,14 @@
           ></i>
         </el-tooltip>
       </div> -->
+      <div >
+          <el-autocomplete
+            v-model="pathurl"
+            :fetch-suggestions="querySearchAsync"
+            placeholder="搜索菜单"
+            @select="handleSelect"
+          ></el-autocomplete>
+        </div>
       <div v-if="isHongGe" class="right-menu-item" style="display: flex">
         <el-select v-model="changeNum" filterable :disabled="!isHongGe" @change="handleChangeArea">
           <el-option v-for="item in areaOpti" :key="item.value" :label="item.label" :value="item.value" />
@@ -33,10 +41,10 @@
         </el-badge>
         <span style="font-size: 16px; margin-left: 15px">物流到货通知</span>
       </div>
-      <!-- <div class="right-menu-item hover-effect" @click="toEngine">
+      <div class="right-menu-item hover-effect" @click="toEngine">
         <i class="el-icon-s-platform" style="font-size: 18px" />
         <span style="font-size: 16px; margin-left: 6px">家用工程机登录</span>
-      </div> -->
+      </div>
 
       <el-badge :value="noticeCount" :max="10" :hidden="!noticeVisible" class="right-menu-item hover-effect">
         <el-tooltip effect="dark" content="系统消息" placement="bottom">
@@ -138,6 +146,7 @@ import { getNoticeListCount } from '@/api/notice'
 import { getNoticeList } from '@/api/stock'
 import { getListOrderTrack } from '@/api/supply/pickup'
 import { getListInvoiceOrder } from '@/api/dashboard'
+import { pages } from '@/settings'
 
 import { bindEngineAccount, checkEngineAccount, setUserChanging } from '@/api/setting'
 import mixin from '@/mixin'
@@ -153,6 +162,7 @@ export default {
   mixins: [mixin],
   data() {
     return {
+      pathurl: '',
       noticeType: 1,
       intivalId: '',
       timer: '',
@@ -257,6 +267,24 @@ export default {
     getList() {
       // this.getNoticeList()
     },
+
+    querySearchAsync(queryString, cb) {
+      var data = pages.filter(item => ~item.meta.title.indexOf(queryString))
+      cb(
+        data.map(item => ({
+          value: item.meta.title,
+          path: item.path
+        }))
+      )
+    },
+    handleSelect(item) {
+      if (item.path) {
+        this.$router.push({
+          path: item.path
+        })
+      }
+      this.pathurl = ''
+    },
     handleChangeNotice(e) {
       if (e === 2) {
         this.currentPage2 = 1

+ 11 - 0
src/permission.js

@@ -17,6 +17,8 @@ const lay = {
   component: Layout,
   children: []
 }
+import { pages } from './settings'
+
 // 递归找最后一级页面
 function getc(obj) {
   if (!obj.children || !obj.children.length) {
@@ -105,6 +107,9 @@ function buildRoute(route, parentUrl = '') {
         roles.push(role.code)
       }
       item.meta.roles = roles
+      if (!pages.find(ite => ite.path === item.path)) {
+        pages.push(item)
+      }
     } else if (type == 1) {
       item.component = RouterView
       item.children = route.children.filter(item => item.type !== 3).map(child => buildRoute(child, item.path))
@@ -112,9 +117,15 @@ function buildRoute(route, parentUrl = '') {
   } else {
     if (type == 4) {
       item.component = IframeView
+      if (!pages.find(ite => ite.path === item.path)) {
+        pages.push(item)
+      }
     } else if (type == 2) {
       try {
         item.component = _import(`${fullUrl}`)
+        if (!pages.find(ite => ite.path === item.path)) {
+          pages.push(item)
+        }
       } catch (e) {
         console.log(e)
       }

+ 3 - 1
src/settings.js

@@ -23,5 +23,7 @@ module.exports = {
    * @type {boolean} true | false
    * @description Whether show breadcrumb
    */
-  breadcrumb: false
+  breadcrumb: false,
+
+  pages: []
 }