docs_vue2/components/OneMenu.vue

206 lines
4.0 KiB
Vue
Raw Normal View History

2020-08-13 11:47:56 +08:00
<template>
<aside class="one-nav">
<veui-menu
class="one-menu"
:items="menuItems"
:expanded.sync="expanded"
>
<template #before>
<h2>VEUI</h2>
<section class="desc">
<a href="https://github.com/ecomfe/veui">
<img
alt="VEUI on GitHub"
src="https://badgen.net/badge/-/GitHub?icon=github&label"
width="69.2"
height="20"
2020-08-13 11:47:56 +08:00
>
</a>
<nuxt-link
:class="{
'locale-swith': true,
disabled: altLocale.disabled,
}"
:to="altLocale.disabled ? '' : altLocale.to"
>
{{ altLocale.label }}
</nuxt-link>
</section>
<section class="filter">
<one-search/>
</section>
</template>
<template #item-label="{ label, sub }">
{{ label }}<small>{{ sub }}</small>
</template>
</veui-menu>
2020-08-13 11:47:56 +08:00
</aside>
</template>
<script>
import i18n from '../common/i18n'
import OneSearch from './OneSearch'
import { Menu } from 'veui'
2020-08-13 11:47:56 +08:00
export default {
name: 'one-menu',
components: {
'one-search': OneSearch,
'veui-menu': Menu
},
2020-08-13 11:47:56 +08:00
mixins: [i18n],
props: {
nav: {
type: Array,
default () {
return []
}
}
},
data () {
return {
expanded: []
}
},
2020-08-13 11:47:56 +08:00
computed: {
altLocale () {
let { canonicalPath, locale, getLocalePath, isPathDisabled } = this
let altLocale = locale === 'zh-Hans' ? 'en-US' : 'zh-Hans'
let label = locale === 'zh-Hans' ? 'English' : '中文'
let disabled = isPathDisabled(canonicalPath, altLocale)
return {
to: disabled ? '' : getLocalePath(canonicalPath, altLocale),
disabled,
label
}
},
menuItems () {
return this.nav.map(item => this.normalizeItem(item))
2020-08-13 11:47:56 +08:00
}
},
created () {
this.expanded = this.menuItems.map(({ name }) => name)
2020-08-13 11:47:56 +08:00
},
methods: {
getTitleDetail (title) {
2020-08-13 11:47:56 +08:00
let [main, sub] = title.split(' - ')
return [main, sub]
2020-08-13 11:47:56 +08:00
},
isActive (path) {
let { route = {} } = this.$router.resolve(path) || {}
return route.name === this.$route.name
},
normalizeItem ({ title, children, slug, link, disabled }, base = '') {
const fullSlug = `${base}/${slug}`
const localePath = this.getLocalePath(fullSlug)
const to = (link !== false && fullSlug) ? localePath : null
const [main, sub] = this.getTitleDetail(title)
2020-08-13 11:47:56 +08:00
return {
label: main,
sub,
to,
name: fullSlug,
disabled,
children: children ? children.map(child => this.normalizeItem(child, fullSlug)) : []
}
2020-08-13 11:47:56 +08:00
}
}
}
</script>
<style lang="stylus" scoped>
.one-nav
position fixed
top 0
2020-08-13 11:47:56 +08:00
bottom 0
left 0
width 280px
2020-08-13 11:47:56 +08:00
z-index 1
.one-menu
width 100%
2020-08-13 11:47:56 +08:00
height 100%
2021-07-19 20:12:14 +08:00
& >>> .veui-menu-tree-wrapper
display flex
flex-direction column
flex-grow 1
height 100%
overflow visible
.veui-menu-tree
overflow auto
2020-08-13 11:47:56 +08:00
2021-07-19 20:12:14 +08:00
& >>> .DocSearch
2021-07-19 17:29:41 +08:00
margin 0
border-radius 6px
font inherit
2020-08-13 11:47:56 +08:00
h2
display flex
align-items center
margin 30px 0 0 20px
2020-08-13 11:47:56 +08:00
font-size 20px
font-weight 500
a
display block
& + .desc
display flex
align-items center
margin-top 15px
margin-left 20px
img
display block
small
margin-left 8px
opacity 0.7
2020-08-13 11:47:56 +08:00
.locale-swith
display block
margin-left 12px
padding 0 6px
border 1px solid #dbdbdb
border-radius 3px
line-height 18px
font-size 12px
text-align center
text-decoration none
transition all 0.2s
&:hover
border-color #999
.filter
margin 20px 0 20px 20px
2021-07-19 20:12:14 +08:00
height 36px
2020-08-13 11:47:56 +08:00
.search
display block
width 180px
height 32px
padding 0 7px
border 1px solid #dbdbdb
border-radius 4px
outline none
font-size 13px
transition all 0.2s
&.focus-visible
border-color #999
box-shadow 0 0 0 2px rgba(0, 0, 0, 0.15)
.toggle
margin-right 15px
font-size 13px
vertical-align middle
.disabled
opacity 0.3
pointer-events none
</style>