2021-09-18 00:34:56 +08:00
|
|
|
<script setup lang="ts">
|
|
|
|
import { onMounted } from 'vue'
|
|
|
|
import nprogress from 'nprogress'
|
2021-09-17 00:18:50 +08:00
|
|
|
import VPOverlay from './vp-overlay.vue'
|
|
|
|
import VPNav from './vp-nav.vue'
|
|
|
|
import VPSubNav from './vp-subnav.vue'
|
|
|
|
import VPSidebar from './vp-sidebar.vue'
|
|
|
|
import VPContent from './vp-content.vue'
|
|
|
|
import VPSponsors from './vp-sponsors.vue'
|
|
|
|
import { useToggle } from '../composables/toggle'
|
|
|
|
import { useSidebar } from '../composables/sidebar'
|
|
|
|
import { useToggleWidgets } from '../composables/toggle-widgets'
|
|
|
|
import { breakpoints } from '../constant'
|
|
|
|
|
|
|
|
const [isSidebarOpen, toggleSidebar] = useToggle(false)
|
|
|
|
const { hasSidebar } = useSidebar()
|
|
|
|
|
|
|
|
useToggleWidgets(isSidebarOpen, () => {
|
|
|
|
if (window.outerWidth >= breakpoints.lg) {
|
|
|
|
toggleSidebar(false)
|
|
|
|
}
|
|
|
|
})
|
2021-09-18 00:34:56 +08:00
|
|
|
|
|
|
|
onMounted(() => {
|
|
|
|
window.addEventListener(
|
|
|
|
'click',
|
|
|
|
(e) => {
|
|
|
|
const link = e.target.closest('a')
|
|
|
|
if (!link) return
|
|
|
|
|
|
|
|
const { href, protocol, hostname, pathname, hash, target } = link
|
|
|
|
const currentUrl = window.location
|
|
|
|
const extMatch = pathname.match(/\.\w+$/)
|
|
|
|
// only intercept inbound links
|
|
|
|
if (
|
|
|
|
!e.ctrlKey &&
|
|
|
|
!e.shiftKey &&
|
|
|
|
!e.altKey &&
|
|
|
|
!e.metaKey &&
|
|
|
|
target !== `_blank` &&
|
|
|
|
protocol === currentUrl.protocol &&
|
|
|
|
hostname === currentUrl.hostname &&
|
|
|
|
!(extMatch && extMatch[0] !== '.html')
|
|
|
|
) {
|
|
|
|
e.preventDefault()
|
|
|
|
if (pathname !== currentUrl.pathname) {
|
|
|
|
nprogress.start()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
{ capture: true }
|
|
|
|
)
|
|
|
|
})
|
2021-09-17 00:18:50 +08:00
|
|
|
</script>
|
|
|
|
|
|
|
|
<template>
|
|
|
|
<div class="App">
|
|
|
|
<VPOverlay
|
|
|
|
class="overlay"
|
|
|
|
:show="isSidebarOpen"
|
|
|
|
@click="toggleSidebar(false)"
|
|
|
|
/>
|
|
|
|
<VPNav />
|
|
|
|
<VPSubNav v-if="hasSidebar" @open-menu="toggleSidebar(true)" />
|
|
|
|
<VPSidebar :open="isSidebarOpen" @close="toggleSidebar(false)">
|
|
|
|
<template #top>
|
|
|
|
<VPSponsors />
|
|
|
|
</template>
|
|
|
|
<template #bottom>
|
|
|
|
<slot name="sidebar-bottom" />
|
|
|
|
</template>
|
|
|
|
</VPSidebar>
|
2021-09-18 00:34:56 +08:00
|
|
|
<VPContent :is-sidebar-open="isSidebarOpen">
|
2021-09-17 00:18:50 +08:00
|
|
|
<template #content-top>
|
|
|
|
<slot name="content-top" />
|
|
|
|
</template>
|
|
|
|
<template #content-bottom>
|
|
|
|
<slot name="content-bottom" />
|
|
|
|
</template>
|
|
|
|
<template #aside-top>
|
|
|
|
<slot name="aside-top" />
|
|
|
|
</template>
|
|
|
|
<template #aside-mid>
|
|
|
|
<slot name="aside-mid" />
|
|
|
|
</template>
|
|
|
|
<template #aside-bottom>
|
|
|
|
<slot name="aside-bottom" />
|
|
|
|
</template>
|
|
|
|
</VPContent>
|
|
|
|
<Debug />
|
|
|
|
</div>
|
|
|
|
</template>
|