naive-ui/demo/entry.vue

132 lines
2.6 KiB
Vue
Raw Normal View History

<template>
2020-03-19 18:26:48 +08:00
<n-config-provider
class="demo"
namespace="naive-ui-doc"
:theme="theme"
:language="lang"
>
<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"
/>
<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>
</n-config-provider>
</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'
2019-09-17 19:28:28 +08:00
export default {
2019-09-17 19:28:28 +08:00
components: {
DocHeader
},
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()
},
data () {
return {
2020-03-16 17:38:06 +08:00
state: state
}
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-03-04 14:42:58 +08:00
return menuOptions(this.lang, this)
2019-09-24 16:59:07 +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) {
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) {
this.$router.push(changeThemeInPath(this.$route.fullPath, theme))
2019-09-24 16:59:07 +08:00
}
}
},
methods: {
handleLangChange (lang) {
this.lang = lang
}
}
}
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)
}
</script>
<style lang="scss" scoped>
.demo {
2020-03-11 21:06:19 +08:00
z-index: auto;
position: absolute;
left: 0;
right: 0;
top: 0;
bottom: 0;
2019-06-27 16:26:23 +08:00
min-width: 1080px;
}
</style>
2019-06-18 16:53:16 +08:00
2019-06-24 01:16:38 +08:00
<style lang="scss">
body {
-webkit-text-size-adjust: 100%;
}
.root-layout.n-layout.n-light-theme {
background-color: white;
2020-02-27 18:09:23 +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>