2020-08-13 11:47:56 +08:00
|
|
|
<template>
|
|
|
|
<aside class="one-nav">
|
2021-07-19 16:27:38 +08:00
|
|
|
<veui-menu
|
|
|
|
class="one-menu"
|
|
|
|
:items="menuItems"
|
|
|
|
:expanded.sync="expanded"
|
|
|
|
>
|
|
|
|
<template #before>
|
2021-08-23 19:37:43 +08:00
|
|
|
<header>
|
|
|
|
<h2>VEUI</h2>
|
|
|
|
<section class="desc">
|
|
|
|
<a href="https://github.com/ecomfe/veui">
|
|
|
|
<img
|
|
|
|
alt="VEUI on GitHub"
|
2021-08-30 15:51:56 +08:00
|
|
|
src="https://img.shields.io/github/stars/ecomfe/veui?label=stars&logo=github"
|
2021-08-23 19:37:43 +08:00
|
|
|
height="20"
|
|
|
|
>
|
|
|
|
</a>
|
|
|
|
<nuxt-link
|
|
|
|
:class="{
|
|
|
|
'locale-swith': true,
|
|
|
|
disabled: altLocale.disabled,
|
|
|
|
}"
|
|
|
|
:to="altLocale.disabled ? '' : altLocale.to"
|
2020-08-13 11:47:56 +08:00
|
|
|
>
|
2021-08-23 19:37:43 +08:00
|
|
|
{{ altLocale.label }}
|
|
|
|
</nuxt-link>
|
|
|
|
</section>
|
|
|
|
<section class="search">
|
|
|
|
<one-search/>
|
|
|
|
</section>
|
|
|
|
</header>
|
2021-07-19 16:27:38 +08:00
|
|
|
</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'
|
2021-07-19 16:27:38 +08:00
|
|
|
import OneSearch from './OneSearch'
|
|
|
|
import { Menu } from 'veui'
|
2020-08-13 11:47:56 +08:00
|
|
|
|
|
|
|
export default {
|
|
|
|
name: 'one-menu',
|
2021-07-19 16:27:38 +08:00
|
|
|
components: {
|
|
|
|
'one-search': OneSearch,
|
|
|
|
'veui-menu': Menu
|
|
|
|
},
|
2020-08-13 11:47:56 +08:00
|
|
|
mixins: [i18n],
|
|
|
|
props: {
|
|
|
|
nav: {
|
|
|
|
type: Array,
|
|
|
|
default () {
|
|
|
|
return []
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
2021-07-19 16:27:38 +08:00
|
|
|
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
|
|
|
|
}
|
2021-07-19 16:27:38 +08:00
|
|
|
},
|
|
|
|
menuItems () {
|
|
|
|
return this.nav.map(item => this.normalizeItem(item))
|
2020-08-13 11:47:56 +08:00
|
|
|
}
|
|
|
|
},
|
2021-07-19 16:27:38 +08:00
|
|
|
created () {
|
|
|
|
this.expanded = this.menuItems.map(({ name }) => name)
|
2020-08-13 11:47:56 +08:00
|
|
|
},
|
|
|
|
methods: {
|
2021-07-19 16:27:38 +08:00
|
|
|
getTitleDetail (title) {
|
2020-08-13 11:47:56 +08:00
|
|
|
let [main, sub] = title.split(' - ')
|
2021-07-19 16:27:38 +08:00
|
|
|
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
|
|
|
|
},
|
2021-07-19 16:27:38 +08:00
|
|
|
normalizeItem ({ title, children, slug, link, disabled }, base = '') {
|
|
|
|
const fullSlug = `${base}/${slug}`
|
|
|
|
const localePath = this.getLocalePath(fullSlug)
|
2021-08-23 19:37:43 +08:00
|
|
|
const to = (link !== false && fullSlug && !disabled) ? localePath : null
|
2021-07-19 16:27:38 +08:00
|
|
|
const [main, sub] = this.getTitleDetail(title)
|
2020-08-13 11:47:56 +08:00
|
|
|
|
2021-07-19 16:27:38 +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
|
2021-07-19 16:27:38 +08:00
|
|
|
top 0
|
2020-08-13 11:47:56 +08:00
|
|
|
bottom 0
|
|
|
|
left 0
|
2021-07-19 16:27:38 +08:00
|
|
|
width 280px
|
2020-08-13 11:47:56 +08:00
|
|
|
z-index 1
|
|
|
|
|
2021-07-19 16:27:38 +08:00
|
|
|
.one-menu
|
|
|
|
width 100%
|
2020-08-13 11:47:56 +08:00
|
|
|
height 100%
|
2021-07-19 16:27:38 +08:00
|
|
|
|
2021-07-19 20:12:14 +08:00
|
|
|
& >>> .veui-menu-tree-wrapper
|
2021-07-19 16:27:38 +08:00
|
|
|
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
|
|
|
|
|
2021-08-23 19:37:43 +08:00
|
|
|
header
|
|
|
|
padding 32px 20px 20px
|
|
|
|
|
2020-08-13 11:47:56 +08:00
|
|
|
h2
|
|
|
|
display flex
|
|
|
|
align-items center
|
2021-08-23 19:37:43 +08:00
|
|
|
margin 0 0 16px
|
2020-08-13 11:47:56 +08:00
|
|
|
font-size 20px
|
|
|
|
font-weight 500
|
|
|
|
|
|
|
|
a
|
|
|
|
display block
|
|
|
|
|
|
|
|
& + .desc
|
|
|
|
display flex
|
|
|
|
align-items center
|
2021-08-23 19:37:43 +08:00
|
|
|
margin-bottom 20px
|
2020-08-13 11:47:56 +08:00
|
|
|
|
|
|
|
img
|
|
|
|
display block
|
|
|
|
|
2021-07-19 16:27:38 +08:00
|
|
|
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
|
|
|
|
|
|
|
|
.search
|
2021-08-23 19:37:43 +08:00
|
|
|
margin-top 16px
|
|
|
|
margin-right 12px
|
|
|
|
flex-shrink 0
|
2020-08-13 11:47:56 +08:00
|
|
|
|
|
|
|
.toggle
|
2021-08-23 19:37:43 +08:00
|
|
|
margin-right 16px
|
2020-08-13 11:47:56 +08:00
|
|
|
font-size 13px
|
|
|
|
vertical-align middle
|
|
|
|
|
|
|
|
.disabled
|
|
|
|
opacity 0.3
|
|
|
|
pointer-events none
|
|
|
|
</style>
|