Skip to content

Commit

Permalink
menuStore.menus 转为内部使用,外部统一使用 menuStore.allMenus
Browse files Browse the repository at this point in the history
  • Loading branch information
hooray committed Mar 28, 2024
1 parent 5b85bdd commit e983de6
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 39 deletions.
44 changes: 6 additions & 38 deletions src/layouts/components/Search/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,11 @@ import type { OverlayScrollbarsComponentRef } from 'overlayscrollbars-vue'
import { OverlayScrollbarsComponent } from 'overlayscrollbars-vue'
import { cloneDeep } from 'lodash-es'
import hotkeys from 'hotkeys-js'
import type { RouteRecordRaw } from 'vue-router'
import Breadcrumb from '../Breadcrumb/index.vue'
import BreadcrumbItem from '../Breadcrumb/item.vue'
import { resolveRoutePath } from '@/utils'
import eventBus from '@/utils/eventBus'
import useSettingsStore from '@/store/modules/settings'
import useRouteStore from '@/store/modules/route'
import useMenuStore from '@/store/modules/menu'
import type { Menu } from '@/types/global'
Expand Down Expand Up @@ -40,7 +38,6 @@ const transitionClass = computed(() => {
const router = useRouter()
const settingsStore = useSettingsStore()
const routeStore = useRouteStore()
const menuStore = useMenuStore()
interface listTypes {
Expand Down Expand Up @@ -149,34 +146,27 @@ onMounted(() => {
function initSourceList() {
sourceList.value = []
if (settingsStore.settings.app.routeBaseOn !== 'filesystem') {
routeStore.routes.forEach((item) => {
item.children && getSourceList(item.children as RouteRecordRaw[])
})
}
else {
menuStore.menus.forEach((item) => {
getSourceListByMenus(item.children)
})
}
menuStore.allMenus.forEach((item) => {
getSourceListByMenus(item.children)
})
}
function hasChildren(item: RouteRecordRaw) {
function hasChildren(item: Menu.recordRaw) {
let flag = true
if (item.children?.every(i => i.meta?.menu === false)) {
flag = false
}
return flag
}
function getSourceList(arr: RouteRecordRaw[], basePath?: string, icon?: string, breadcrumb?: { title?: string | (() => string) }[]) {
function getSourceListByMenus(arr: Menu.recordRaw[], basePath?: string, icon?: string, breadcrumb?: { title?: string | (() => string) }[]) {
arr.forEach((item) => {
if (item.meta?.menu !== false) {
const breadcrumbTemp = cloneDeep(breadcrumb) || []
if (item.children && hasChildren(item)) {
breadcrumbTemp.push({
title: item.meta?.title,
})
getSourceList(item.children, resolveRoutePath(basePath, item.path), item.meta?.icon ?? icon, breadcrumbTemp)
getSourceListByMenus(item.children, resolveRoutePath(basePath, item.path), item.meta?.icon ?? icon, breadcrumbTemp)
}
else {
breadcrumbTemp.push({
Expand All @@ -193,28 +183,6 @@ function getSourceList(arr: RouteRecordRaw[], basePath?: string, icon?: string,
}
})
}
function getSourceListByMenus(arr: Menu.recordRaw[], icon?: string, breadcrumb?: { title?: string | (() => string) }[]) {
arr.forEach((item) => {
const breadcrumbTemp = cloneDeep(breadcrumb) || []
if (item.children && item.children.length > 0) {
breadcrumbTemp.push({
title: item.meta?.title,
})
getSourceListByMenus(item.children, item.meta?.icon ?? icon, breadcrumbTemp)
}
else {
breadcrumbTemp.push({
title: item.meta?.title,
})
sourceList.value.push({
icon: item.meta?.icon ?? icon,
title: item.meta?.title,
path: item.path as string,
breadcrumb: breadcrumbTemp,
})
}
})
}
function keyUp() {
if (resultList.value.length) {
Expand Down
1 change: 0 additions & 1 deletion src/store/modules/menu.ts
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,6 @@ const useMenuStore = defineStore(
}

return {
menus,
actived,
allMenus,
sidebarMenus,
Expand Down

0 comments on commit e983de6

Please sign in to comment.