2021-02-14 14:52:14 +08:00
|
|
|
<template>
|
2021-04-05 15:16:32 +08:00
|
|
|
<n-layout has-sider position="absolute">
|
|
|
|
<n-layout-sider
|
|
|
|
:native-scrollbar="false"
|
|
|
|
bordered
|
|
|
|
show-trigger="bar"
|
|
|
|
v-if="showSider"
|
|
|
|
>
|
|
|
|
<n-menu
|
|
|
|
:value="menuValue"
|
|
|
|
:options="options"
|
|
|
|
@update:value="handleMenuUpdateValue"
|
|
|
|
/>
|
|
|
|
</n-layout-sider>
|
|
|
|
<n-layout ref="layoutInstRef" :native-scrollbar="false">
|
|
|
|
<router-view />
|
|
|
|
</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-04-05 15:16:32 +08:00
|
|
|
import { useRoute, useRouter } from 'vue-router'
|
2021-04-05 17:59:04 +08:00
|
|
|
import { findMenuValue } from '../utils/route'
|
2021-02-14 14:52:14 +08:00
|
|
|
import { useDocOptions, useComponentOptions } from '../store'
|
2021-04-05 15:16:32 +08:00
|
|
|
import { useBreakpoint, useMemo } from 'vooks'
|
2021-02-14 14:52:14 +08:00
|
|
|
|
|
|
|
export default {
|
|
|
|
setup () {
|
|
|
|
const route = useRoute()
|
2021-04-05 15:16:32 +08:00
|
|
|
const router = useRouter()
|
2021-02-14 14:52:14 +08:00
|
|
|
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-04-05 15:16:32 +08:00
|
|
|
const breakpointRef = useBreakpoint()
|
2021-02-14 14:52:14 +08:00
|
|
|
return {
|
2021-04-05 15:16:32 +08:00
|
|
|
showSider: useMemo(() => {
|
|
|
|
return breakpointRef.value !== 'xs'
|
|
|
|
}),
|
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,
|
|
|
|
handleMenuUpdateValue: (_, option) => {
|
|
|
|
router.push(option.path)
|
2021-02-14 14:52:14 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
</script>
|