init
This commit is contained in:
19
pc/composables/useLockFn.ts
Normal file
19
pc/composables/useLockFn.ts
Normal file
@ -0,0 +1,19 @@
|
||||
export function useLockFn(fn: (...args: any[]) => Promise<any>) {
|
||||
const isLock = ref(false)
|
||||
const lockFn = async (...args: any[]) => {
|
||||
if (isLock.value) return
|
||||
isLock.value = true
|
||||
try {
|
||||
const res = await fn(...args)
|
||||
isLock.value = false
|
||||
return res
|
||||
} catch (e) {
|
||||
isLock.value = false
|
||||
throw e
|
||||
}
|
||||
}
|
||||
return {
|
||||
isLock,
|
||||
lockFn
|
||||
}
|
||||
}
|
26
pc/composables/useMenu.ts
Normal file
26
pc/composables/useMenu.ts
Normal file
@ -0,0 +1,26 @@
|
||||
import { NAVBAR, SIDEBAR } from '@/constants/menu'
|
||||
export default function useMenu() {
|
||||
const menu = useState(() => NAVBAR)
|
||||
const route = useRoute()
|
||||
const sidebar = computed(() => getSidebar(route.meta.module))
|
||||
const hasSidebar = computed(() => sidebar.value.length)
|
||||
return {
|
||||
menu,
|
||||
sidebar,
|
||||
hasSidebar
|
||||
}
|
||||
}
|
||||
|
||||
function getSidebar(module?: string): any[] {
|
||||
const queue: any[] = []
|
||||
SIDEBAR.forEach((item) => queue.push(item))
|
||||
while (queue.length) {
|
||||
const item = queue.shift()
|
||||
if (item.module && item.module == module) {
|
||||
return item.children
|
||||
}
|
||||
item.children &&
|
||||
item.children.forEach((child: any) => queue.push(child))
|
||||
}
|
||||
return []
|
||||
}
|
Reference in New Issue
Block a user