2021-02-14 14:52:14 +08:00
|
|
|
<template>
|
2021-05-26 14:39:33 +08:00
|
|
|
<n-layout
|
2021-05-27 12:43:12 +08:00
|
|
|
id="doc-layout"
|
2021-05-26 14:39:33 +08:00
|
|
|
:has-sider="showSider"
|
2021-06-05 12:05:41 +08:00
|
|
|
:position="isMobile ? 'static' : 'absolute'"
|
|
|
|
:style="{
|
|
|
|
top: isMobile ? '' : 'var(--header-height)'
|
|
|
|
}"
|
2021-05-26 14:39:33 +08:00
|
|
|
>
|
2021-04-05 15:16:32 +08:00
|
|
|
<n-layout-sider
|
|
|
|
:native-scrollbar="false"
|
2021-04-06 01:31:09 +08:00
|
|
|
:collapsed-width="0"
|
2021-05-19 14:55:54 +08:00
|
|
|
collapse-mode="transform"
|
2021-04-05 15:16:32 +08:00
|
|
|
bordered
|
|
|
|
show-trigger="bar"
|
2021-06-02 16:17:13 +08:00
|
|
|
trigger-style="top: calc(50% - var(--header-height));"
|
2021-04-05 15:16:32 +08:00
|
|
|
v-if="showSider"
|
|
|
|
>
|
|
|
|
<n-menu
|
|
|
|
:value="menuValue"
|
|
|
|
:options="options"
|
2021-06-21 09:39:54 +08:00
|
|
|
:render-label="renderMenuLabel"
|
2021-04-05 15:16:32 +08:00
|
|
|
/>
|
|
|
|
</n-layout-sider>
|
2021-06-02 16:17:13 +08:00
|
|
|
<n-layout
|
|
|
|
ref="layoutInstRef"
|
|
|
|
:native-scrollbar="false"
|
2021-06-05 12:05:41 +08:00
|
|
|
:position="isMobile || showSider ? 'static' : 'absolute'"
|
2021-06-02 16:17:13 +08:00
|
|
|
content-style="min-height: calc(100vh - var(--header-height)); display: flex; flex-direction: column;"
|
|
|
|
>
|
2021-04-05 15:16:32 +08:00
|
|
|
<router-view />
|
2021-05-04 02:27:16 +08:00
|
|
|
<site-footer />
|
2021-04-05 15:16:32 +08:00
|
|
|
</n-layout>
|
|
|
|
</n-layout>
|
2021-02-14 14:52:14 +08:00
|
|
|
</template>
|
|
|
|
|
|
|
|
<script>
|
|
|
|
// Frame component for components & docs page
|
|
|
|
import { computed, watch, toRef, ref } from 'vue'
|
2021-06-21 09:39:54 +08:00
|
|
|
import { useRoute } from 'vue-router'
|
2021-04-05 17:59:04 +08:00
|
|
|
import { findMenuValue } from '../utils/route'
|
2021-06-05 12:05:41 +08:00
|
|
|
import { useIsMobile, useIsTablet } from '../utils/composables'
|
2021-05-04 02:27:16 +08:00
|
|
|
import SiteFooter from './home/Footer.vue'
|
2021-02-14 14:52:14 +08:00
|
|
|
import { useDocOptions, useComponentOptions } from '../store'
|
2021-06-21 09:39:54 +08:00
|
|
|
import { renderMenuLabel } from '../store/menu-options'
|
2021-04-24 01:04:18 +08:00
|
|
|
import { useMemo } from 'vooks'
|
2021-02-14 14:52:14 +08:00
|
|
|
|
|
|
|
export default {
|
2021-05-04 02:27:16 +08:00
|
|
|
components: {
|
|
|
|
SiteFooter
|
|
|
|
},
|
2021-02-14 14:52:14 +08:00
|
|
|
setup () {
|
|
|
|
const route = useRoute()
|
|
|
|
const layoutInstRef = ref(null)
|
|
|
|
const docOptionsRef = useDocOptions()
|
|
|
|
const componentOptionsRef = useComponentOptions()
|
|
|
|
const optionsRef = computed(() =>
|
|
|
|
route.path.includes('/docs/')
|
|
|
|
? docOptionsRef.value
|
|
|
|
: componentOptionsRef.value
|
|
|
|
)
|
2021-04-05 17:59:04 +08:00
|
|
|
|
2021-04-05 15:16:32 +08:00
|
|
|
const menuValueRef = computed(() => {
|
|
|
|
return findMenuValue(optionsRef.value, route.path)
|
|
|
|
})
|
2021-02-14 14:52:14 +08:00
|
|
|
watch(toRef(route, 'path'), (value, oldValue) => {
|
2021-02-18 22:30:41 +08:00
|
|
|
const langAndThemeReg = /\/(zh-CN|en-US)\/(light|dark|os-theme)/g
|
|
|
|
// only theme & lang change do not restore the scroll status
|
|
|
|
if (
|
|
|
|
value.replace(langAndThemeReg, '') !==
|
|
|
|
oldValue.replace(langAndThemeReg, '')
|
|
|
|
) {
|
2021-02-14 14:52:14 +08:00
|
|
|
layoutInstRef.value.scrollTo(0, 0)
|
|
|
|
}
|
|
|
|
})
|
2021-06-05 12:05:41 +08:00
|
|
|
const isMobileRef = useIsMobile()
|
|
|
|
const isTabletRef = useIsTablet()
|
2021-06-21 09:39:54 +08:00
|
|
|
|
2021-02-14 14:52:14 +08:00
|
|
|
return {
|
2021-06-21 09:39:54 +08:00
|
|
|
renderMenuLabel,
|
2021-04-05 15:16:32 +08:00
|
|
|
showSider: useMemo(() => {
|
2021-06-05 12:05:41 +08:00
|
|
|
return !isMobileRef.value && !isTabletRef.value
|
2021-04-05 15:16:32 +08:00
|
|
|
}),
|
2021-02-14 14:52:14 +08:00
|
|
|
layoutInstRef,
|
2021-02-18 22:30:41 +08:00
|
|
|
options: optionsRef,
|
2021-04-05 15:16:32 +08:00
|
|
|
menuValue: menuValueRef,
|
2021-06-21 09:39:54 +08:00
|
|
|
isMobile: isMobileRef
|
2021-02-14 14:52:14 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
</script>
|