2019-05-24 20:09:35 +08:00
|
|
|
<template>
|
2020-03-19 18:26:48 +08:00
|
|
|
<n-config-provider
|
|
|
|
class="demo"
|
|
|
|
namespace="naive-ui-doc"
|
|
|
|
:theme="theme"
|
|
|
|
:language="lang"
|
|
|
|
>
|
2020-03-08 00:06:05 +08:00
|
|
|
<n-layout position="absolute" class="root-layout">
|
2020-03-03 19:25:25 +08:00
|
|
|
<doc-header
|
|
|
|
:lang="lang"
|
|
|
|
:items="flattenedItems"
|
2020-03-05 09:57:29 +08:00
|
|
|
:env="env"
|
2020-03-03 19:25:25 +08:00
|
|
|
@lang-change="handleLangChange"
|
|
|
|
/>
|
2020-03-08 00:06:05 +08:00
|
|
|
<n-layout class="home-layout" style="top: 64px; overflow: hidden;" position="absolute">
|
2020-02-27 18:09:23 +08:00
|
|
|
<router-view />
|
|
|
|
</n-layout>
|
|
|
|
</n-layout>
|
2019-11-09 22:45:07 +08:00
|
|
|
</n-config-provider>
|
2019-05-24 20:09:35 +08:00
|
|
|
</template>
|
|
|
|
|
|
|
|
<script>
|
2019-09-17 19:28:28 +08:00
|
|
|
import DocHeader from './header.vue'
|
2020-02-04 23:13:53 +08:00
|
|
|
import menuOptions from './menuOptions'
|
2020-03-19 18:26:48 +08:00
|
|
|
import { i18n } from './init'
|
2020-03-17 16:48:36 +08:00
|
|
|
import { state } from './store'
|
2020-05-18 20:03:44 +08:00
|
|
|
import staputed from '../src/_mixins/staputed'
|
2019-09-17 19:28:28 +08:00
|
|
|
|
2019-05-24 20:09:35 +08:00
|
|
|
export default {
|
2019-09-17 19:28:28 +08:00
|
|
|
components: {
|
|
|
|
DocHeader
|
|
|
|
},
|
2020-05-18 20:03:44 +08:00
|
|
|
mixins: [
|
|
|
|
staputed({
|
|
|
|
menuGenerationOptions: {
|
|
|
|
get () {
|
|
|
|
return {
|
|
|
|
theme: this.theme,
|
|
|
|
lang: this.lang,
|
|
|
|
mode: this.mode
|
|
|
|
}
|
|
|
|
},
|
|
|
|
deps: ['theme', 'lang', 'mode'],
|
|
|
|
default: null
|
|
|
|
}
|
|
|
|
})
|
|
|
|
],
|
2020-02-01 16:45:37 +08:00
|
|
|
provide () {
|
|
|
|
return {
|
2020-02-27 18:09:23 +08:00
|
|
|
NEntry: this
|
2020-02-01 16:45:37 +08:00
|
|
|
}
|
|
|
|
},
|
2019-09-24 16:59:07 +08:00
|
|
|
beforeRouteEnter (to, from, next) {
|
|
|
|
i18n.locale = to.params.lang
|
|
|
|
next()
|
|
|
|
},
|
|
|
|
beforeRouteUpdate (to, from, next) {
|
|
|
|
this.$i18n.locale = to.params.lang
|
|
|
|
next()
|
2020-03-04 18:22:25 +08:00
|
|
|
},
|
|
|
|
data () {
|
|
|
|
return {
|
2020-03-16 17:38:06 +08:00
|
|
|
state: state
|
2020-03-04 18:22:25 +08:00
|
|
|
}
|
2019-09-24 16:59:07 +08:00
|
|
|
},
|
|
|
|
computed: {
|
2020-03-16 17:38:06 +08:00
|
|
|
mode () {
|
2020-03-17 18:54:21 +08:00
|
|
|
return this.state.mode
|
2020-03-16 17:38:06 +08:00
|
|
|
},
|
2020-03-04 03:01:15 +08:00
|
|
|
env () {
|
|
|
|
return process.env.NODE_ENV
|
|
|
|
},
|
2019-09-24 16:59:07 +08:00
|
|
|
items () {
|
2020-05-18 20:03:44 +08:00
|
|
|
return menuOptions(this.menuGenerationOptions)
|
2019-09-24 16:59:07 +08:00
|
|
|
},
|
2019-11-22 18:49:53 +08:00
|
|
|
flattenedItems () {
|
|
|
|
const flattenedItems = []
|
|
|
|
const traverse = items => {
|
|
|
|
if (items) {
|
|
|
|
items.forEach(item => {
|
|
|
|
if (item.childItems) traverse(item.childItems)
|
|
|
|
else flattenedItems.push(item)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
traverse(this.items)
|
|
|
|
return flattenedItems
|
|
|
|
},
|
2019-09-24 16:59:07 +08:00
|
|
|
lang: {
|
|
|
|
get () {
|
2019-12-23 16:31:26 +08:00
|
|
|
return this.$route.params.lang || 'en-US'
|
2019-09-24 16:59:07 +08:00
|
|
|
},
|
|
|
|
set (lang) {
|
2019-12-10 18:49:06 +08:00
|
|
|
this.$router.push(changeLangInPath(this.$route.fullPath, lang))
|
2019-09-24 16:59:07 +08:00
|
|
|
}
|
|
|
|
},
|
|
|
|
theme: {
|
|
|
|
get () {
|
2019-09-27 15:56:01 +08:00
|
|
|
return this.$route.params.theme === 'light' ? 'light' : 'dark'
|
2019-09-24 16:59:07 +08:00
|
|
|
},
|
|
|
|
set (theme) {
|
2019-12-10 18:49:06 +08:00
|
|
|
this.$router.push(changeThemeInPath(this.$route.fullPath, theme))
|
2019-09-24 16:59:07 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
methods: {
|
|
|
|
handleLangChange (lang) {
|
|
|
|
this.lang = lang
|
2019-06-23 18:00:21 +08:00
|
|
|
}
|
|
|
|
}
|
2019-05-24 20:09:35 +08:00
|
|
|
}
|
2019-09-24 16:59:07 +08:00
|
|
|
|
|
|
|
function changeLangInPath (path, lang) {
|
2019-12-23 16:31:26 +08:00
|
|
|
const langReg = /^\/(zh-CN|en-US)\//
|
2019-09-24 16:59:07 +08:00
|
|
|
return path.replace(langReg, `/${lang}/`)
|
|
|
|
}
|
2019-09-27 15:56:01 +08:00
|
|
|
|
|
|
|
function changeThemeInPath (path, theme) {
|
|
|
|
const themeReg = /(^\/[^/]+\/)([^/]+)/
|
|
|
|
return path.replace(themeReg, '$1' + theme)
|
|
|
|
}
|
2019-05-24 20:09:35 +08:00
|
|
|
</script>
|
|
|
|
|
|
|
|
<style lang="scss" scoped>
|
|
|
|
.demo {
|
2020-03-11 21:06:19 +08:00
|
|
|
z-index: auto;
|
2019-06-23 18:00:21 +08:00
|
|
|
position: absolute;
|
|
|
|
left: 0;
|
|
|
|
right: 0;
|
|
|
|
top: 0;
|
|
|
|
bottom: 0;
|
2019-06-27 16:26:23 +08:00
|
|
|
min-width: 1080px;
|
2019-05-24 20:09:35 +08:00
|
|
|
}
|
|
|
|
</style>
|
2019-06-18 16:53:16 +08:00
|
|
|
|
2019-06-24 01:16:38 +08:00
|
|
|
<style lang="scss">
|
2019-06-27 18:17:07 +08:00
|
|
|
body {
|
|
|
|
-webkit-text-size-adjust: 100%;
|
|
|
|
}
|
|
|
|
|
2020-02-28 16:42:51 +08:00
|
|
|
.root-layout.n-layout.n-light-theme {
|
|
|
|
background-color: white;
|
2020-02-27 18:09:23 +08:00
|
|
|
}
|
2020-02-28 16:42:51 +08:00
|
|
|
.home-layout.n-layout.n-light-theme {
|
|
|
|
background-color: white;
|
2019-06-24 01:16:38 +08:00
|
|
|
}
|
2019-06-18 16:53:16 +08:00
|
|
|
</style>
|