2019-09-23 11:32:50 +08:00
|
|
|
<i18n>
|
|
|
|
{
|
2019-12-23 16:31:26 +08:00
|
|
|
"zh-CN": {
|
2019-09-23 11:32:50 +08:00
|
|
|
"dark": "深色",
|
2020-02-05 13:46:57 +08:00
|
|
|
"light": "浅色",
|
2020-02-27 18:09:23 +08:00
|
|
|
"searchPlaceholder": "搜索组件",
|
|
|
|
"home": "首页",
|
2020-03-04 03:01:15 +08:00
|
|
|
"doc": "文档",
|
|
|
|
"common": "常规",
|
|
|
|
"debug": "调试"
|
2019-09-23 11:32:50 +08:00
|
|
|
},
|
2019-12-23 16:31:26 +08:00
|
|
|
"en-US": {
|
2019-09-23 11:32:50 +08:00
|
|
|
"dark": "Dark",
|
2020-02-05 13:46:57 +08:00
|
|
|
"light": "Light",
|
2020-02-27 18:09:23 +08:00
|
|
|
"searchPlaceholder": "Search Components",
|
|
|
|
"home": "Home",
|
2020-03-04 03:01:15 +08:00
|
|
|
"doc": "Documentation",
|
|
|
|
"common": "Common",
|
|
|
|
"debug": "Debug"
|
2019-09-23 11:32:50 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
</i18n>
|
|
|
|
|
2019-09-17 19:28:28 +08:00
|
|
|
<template>
|
|
|
|
<div class="nav">
|
2020-02-27 23:03:15 +08:00
|
|
|
<div class="ui-logo" @click="handleLogoClick">
|
2019-10-28 12:39:56 +08:00
|
|
|
<img src="./assets/images/naivelogo.svg">
|
2019-10-10 22:38:29 +08:00
|
|
|
Naive UI ({{ version }})
|
2019-09-17 19:28:28 +08:00
|
|
|
</div>
|
2020-02-27 18:09:23 +08:00
|
|
|
<div style=" margin-left: 56px; display: flex; align-items: center;">
|
2019-12-04 17:59:38 +08:00
|
|
|
<n-auto-complete
|
|
|
|
v-model="searchInputValue"
|
2020-02-27 18:09:23 +08:00
|
|
|
style="width: 216px;"
|
2020-02-25 14:29:36 +08:00
|
|
|
:z-index="3001"
|
2020-02-05 13:46:57 +08:00
|
|
|
:placeholder="$t('searchPlaceholder')"
|
2019-12-04 17:59:38 +08:00
|
|
|
:options="searchOptions"
|
|
|
|
clear-after-select
|
|
|
|
blur-after-select
|
|
|
|
@select="handleSelect"
|
|
|
|
/>
|
2020-02-27 18:09:23 +08:00
|
|
|
<div class="nav-menu">
|
|
|
|
<n-menu mode="horizontal" :value="menuValue" @select="handleMenuSelect">
|
|
|
|
<n-menu-item :title="$t('home')" name="home" />
|
|
|
|
<n-menu-item :title="$t('doc')" name="doc" />
|
|
|
|
</n-menu>
|
|
|
|
</div>
|
2019-11-22 18:49:53 +08:00
|
|
|
</div>
|
2019-09-17 19:28:28 +08:00
|
|
|
<div class="theme-picker">
|
|
|
|
<n-select
|
2019-11-28 16:17:21 +08:00
|
|
|
v-model="NConfigProvider.$parent.theme"
|
2020-02-25 14:29:36 +08:00
|
|
|
:z-index="3001"
|
2019-09-17 19:28:28 +08:00
|
|
|
size="small"
|
|
|
|
:options="options"
|
|
|
|
/>
|
|
|
|
</div>
|
2019-09-21 17:03:37 +08:00
|
|
|
<div class="lang-picker">
|
|
|
|
<n-select
|
2020-02-25 14:29:36 +08:00
|
|
|
:z-index="3001"
|
2019-09-24 16:59:07 +08:00
|
|
|
:value="lang"
|
2019-09-21 17:03:37 +08:00
|
|
|
size="small"
|
|
|
|
:options="langOptions"
|
2020-01-29 20:51:51 +08:00
|
|
|
@change="handleLanguageChange"
|
2019-09-21 17:03:37 +08:00
|
|
|
/>
|
|
|
|
</div>
|
2020-03-04 03:01:15 +08:00
|
|
|
<div v-if="env==='development'" class="mode-picker">
|
|
|
|
<n-select
|
|
|
|
:z-index="3001"
|
|
|
|
:value="mode"
|
|
|
|
size="small"
|
|
|
|
:options="modeOptions"
|
|
|
|
@change="handleModeChange"
|
|
|
|
/>
|
|
|
|
</div>
|
2019-09-17 19:28:28 +08:00
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<script>
|
2019-09-20 00:22:55 +08:00
|
|
|
import { version } from '../package.json'
|
2020-02-12 13:44:53 +08:00
|
|
|
import withapp from '../src/_mixins/withapp'
|
2019-09-17 19:28:28 +08:00
|
|
|
|
2020-02-26 17:21:03 +08:00
|
|
|
function match (pattern, string) {
|
|
|
|
if (!pattern.length) return true
|
|
|
|
if (!string.length) return false
|
|
|
|
if (pattern[0] === string[0]) return match(pattern.slice(1), string.slice(1))
|
|
|
|
return match(pattern, string.slice(1))
|
|
|
|
}
|
|
|
|
|
2019-09-17 19:28:28 +08:00
|
|
|
export default {
|
|
|
|
mixins: [withapp],
|
2019-09-24 16:59:07 +08:00
|
|
|
props: {
|
|
|
|
lang: {
|
|
|
|
type: String,
|
|
|
|
required: true
|
2019-11-22 18:49:53 +08:00
|
|
|
},
|
|
|
|
items: {
|
|
|
|
type: Array,
|
|
|
|
default: () => []
|
2020-03-04 03:01:15 +08:00
|
|
|
},
|
|
|
|
env: {
|
|
|
|
type: String,
|
|
|
|
default: null
|
2019-09-24 16:59:07 +08:00
|
|
|
}
|
|
|
|
},
|
2019-09-17 19:28:28 +08:00
|
|
|
data () {
|
|
|
|
return {
|
2019-11-22 18:49:53 +08:00
|
|
|
searchInputValue: '',
|
2019-09-20 00:22:55 +08:00
|
|
|
version,
|
2019-09-24 16:59:07 +08:00
|
|
|
theme: 'dark',
|
2020-03-04 03:01:15 +08:00
|
|
|
mode: 'debug',
|
2019-09-21 17:03:37 +08:00
|
|
|
langOptions: [
|
|
|
|
{
|
|
|
|
label: '中文',
|
2019-12-23 16:31:26 +08:00
|
|
|
value: 'zh-CN'
|
2019-09-21 17:03:37 +08:00
|
|
|
},
|
|
|
|
{
|
|
|
|
label: 'English',
|
2019-12-23 16:31:26 +08:00
|
|
|
value: 'en-US'
|
2019-09-21 17:03:37 +08:00
|
|
|
}
|
2019-09-17 19:28:28 +08:00
|
|
|
]
|
|
|
|
}
|
|
|
|
},
|
2019-09-23 11:32:50 +08:00
|
|
|
computed: {
|
2020-03-04 03:01:15 +08:00
|
|
|
showDebug () {
|
|
|
|
return this.mode === 'development'
|
|
|
|
},
|
2020-02-27 18:09:23 +08:00
|
|
|
menuValue () {
|
|
|
|
if (/^(\/[^/]+){2}\/doc/.test(this.$route.path)) return 'doc'
|
|
|
|
else if (this.$route.name === 'home') return 'home'
|
|
|
|
return null
|
|
|
|
},
|
2019-11-22 18:49:53 +08:00
|
|
|
searchOptions () {
|
2020-02-11 18:10:49 +08:00
|
|
|
function getLabel (item) {
|
|
|
|
if (item.title) return item.title + (item.titleExtra ? (' ' + item.titleExtra) : '')
|
|
|
|
return item.name
|
|
|
|
}
|
2019-11-22 18:49:53 +08:00
|
|
|
if (!this.searchInputValue) return []
|
2020-02-11 18:10:49 +08:00
|
|
|
const replaceRegex = / |-/g
|
2019-11-22 18:49:53 +08:00
|
|
|
return this.items.filter(item => {
|
2020-02-11 18:10:49 +08:00
|
|
|
const pattern = this.searchInputValue.toLowerCase().replace(replaceRegex, '').slice(0, 20)
|
|
|
|
const label = getLabel(item).toLowerCase().replace(replaceRegex, '')
|
2020-02-26 17:21:03 +08:00
|
|
|
return match(pattern, label)
|
2019-12-28 00:27:26 +08:00
|
|
|
}).map(item => ({
|
2020-02-11 18:10:49 +08:00
|
|
|
label: getLabel(item),
|
2019-11-22 18:49:53 +08:00
|
|
|
value: item.path
|
|
|
|
}))
|
|
|
|
},
|
2019-09-23 11:32:50 +08:00
|
|
|
options: function () {
|
|
|
|
return [
|
|
|
|
{
|
|
|
|
label: this.$t('dark'),
|
2019-09-24 16:59:07 +08:00
|
|
|
value: 'dark'
|
2019-09-23 11:32:50 +08:00
|
|
|
},
|
|
|
|
{
|
|
|
|
label: this.$t('light'),
|
|
|
|
value: 'light'
|
|
|
|
}
|
|
|
|
]
|
2020-03-04 03:01:15 +08:00
|
|
|
},
|
|
|
|
modeOptions: function () {
|
|
|
|
return [
|
|
|
|
{
|
|
|
|
label: this.$t('common'),
|
|
|
|
value: 'common'
|
|
|
|
},
|
|
|
|
{
|
|
|
|
label: this.$t('debug'),
|
|
|
|
value: 'debug'
|
|
|
|
}
|
|
|
|
]
|
2019-09-23 11:32:50 +08:00
|
|
|
}
|
|
|
|
},
|
2019-09-17 19:28:28 +08:00
|
|
|
methods: {
|
2020-02-27 23:03:15 +08:00
|
|
|
handleLogoClick () {
|
|
|
|
this.$router.push(
|
2020-03-04 03:01:15 +08:00
|
|
|
/^(\/[^/]+){3}/.exec(this.$route.path)[0]
|
2020-02-27 23:03:15 +08:00
|
|
|
)
|
|
|
|
},
|
2019-11-22 18:49:53 +08:00
|
|
|
handleSelect (value) {
|
|
|
|
this.$router.push(value)
|
2020-02-27 18:09:23 +08:00
|
|
|
},
|
|
|
|
handleMenuSelect (value) {
|
|
|
|
if (value === 'home') {
|
|
|
|
this.$router.push(
|
2020-03-04 03:01:15 +08:00
|
|
|
/^(\/[^/]+){3}/.exec(this.$route.path)[0]
|
2020-02-27 18:09:23 +08:00
|
|
|
)
|
|
|
|
} if (value === 'doc') {
|
2020-03-04 03:01:15 +08:00
|
|
|
if (/^(\/[^/]+){3}\/doc/.test(this.$route.path)) {
|
2020-02-27 18:09:23 +08:00
|
|
|
|
|
|
|
} else {
|
|
|
|
this.$router.push(
|
2020-03-04 03:01:15 +08:00
|
|
|
/^(\/[^/]+){3}/.exec(this.$route.path)[0] + '/doc/start'
|
2020-02-27 18:09:23 +08:00
|
|
|
)
|
|
|
|
}
|
|
|
|
}
|
2019-11-22 18:49:53 +08:00
|
|
|
},
|
2019-09-27 22:28:25 +08:00
|
|
|
handleThemeChange (theme) {
|
2019-11-28 16:17:21 +08:00
|
|
|
this.NConfigProvider.$parent.theme = theme
|
2019-09-27 22:28:25 +08:00
|
|
|
},
|
2020-01-29 20:51:51 +08:00
|
|
|
handleLanguageChange (lang) {
|
2019-09-24 16:59:07 +08:00
|
|
|
this.$emit('lang-change', lang)
|
2020-03-04 03:01:15 +08:00
|
|
|
},
|
|
|
|
handleModeChange (mode) {
|
|
|
|
this.mode = mode
|
|
|
|
this.$emit('mode-change', mode)
|
2019-09-17 19:28:28 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
</script>
|
|
|
|
|
|
|
|
<style lang="scss" scoped>
|
|
|
|
.nav {
|
|
|
|
display: grid;
|
2020-03-04 03:01:15 +08:00
|
|
|
grid-template-columns: 288px 1fr auto 140px 200px;
|
2020-02-27 18:09:23 +08:00
|
|
|
grid-template-rows: 63px;
|
2019-09-17 19:28:28 +08:00
|
|
|
align-items: center;
|
|
|
|
}
|
|
|
|
.ui-logo {
|
2020-02-27 23:03:15 +08:00
|
|
|
cursor: pointer;
|
2019-10-20 00:18:55 +08:00
|
|
|
display: flex;
|
|
|
|
align-items: center;
|
2020-02-22 20:25:10 +08:00
|
|
|
padding-left: 36px;
|
2019-10-20 00:18:55 +08:00
|
|
|
font-size: 18px;
|
|
|
|
}
|
|
|
|
.ui-logo > img {
|
|
|
|
margin-right: 12px;
|
|
|
|
height: 32px;
|
|
|
|
width: 32px;
|
2019-09-17 19:28:28 +08:00
|
|
|
}
|
2020-02-27 18:09:23 +08:00
|
|
|
.nav-menu {
|
|
|
|
padding-left: 32px;
|
|
|
|
}
|
|
|
|
.nav-menu .n-menu-item {
|
|
|
|
height: 63px !important;
|
|
|
|
}
|
2019-09-17 19:28:28 +08:00
|
|
|
.theme-picker {
|
2019-09-21 17:03:37 +08:00
|
|
|
padding-right: 16px;
|
|
|
|
}
|
|
|
|
.lang-picker {
|
2020-03-04 03:01:15 +08:00
|
|
|
padding-right: 16px;
|
|
|
|
}
|
|
|
|
.mode-picker {
|
2019-09-17 19:28:28 +08:00
|
|
|
padding-right: 48px;
|
|
|
|
}
|
|
|
|
</style>
|