naive-ui/demo/Entry.vue

156 lines
3.2 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-message-provider>
2020-09-14 17:38:11 +08:00
<n-notification-provider>
<n-layout position="absolute" class="root-layout">
<doc-header
:lang="lang"
:items="flattenedItems"
:env="env"
@lang-change="handleLangChange"
/>
<n-layout class="home-layout" style="top: 64px; overflow: hidden;" position="absolute">
<router-view />
</n-layout>
</n-layout>
2020-09-14 17:38:11 +08:00
</n-notification-provider>
</n-message-provider>
</n-config-provider>
</template>
<script>
2020-09-03 17:02:31 +08:00
import DocHeader from './Header.vue'
import menuOptions from './menu-options'
2020-03-19 18:26:48 +08:00
import { i18n } from './init'
2020-09-03 17:02:31 +08:00
import { modeRef } from './use-dev-mode'
import simulatedComputed from '../src/_mixins/simulatedComputed'
2019-09-17 19:28:28 +08:00
export default {
2019-09-17 19:28:28 +08:00
components: {
DocHeader
},
mixins: [
simulatedComputed({
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) {
2020-09-17 10:43:29 +08:00
// this.$i18n.locale = to.params.lang
2019-09-24 16:59:07 +08:00
next()
},
data () {
return {
2020-09-03 17:02:31 +08:00
modeRef
}
2019-09-24 16:59:07 +08:00
},
computed: {
2020-03-16 17:38:06 +08:00
mode () {
2020-09-03 17:02:31 +08:00
return this.modeRef.value
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 () {
return menuOptions(this.menuGenerationOptions)
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 () {
switch (this.$route.params.theme) {
case 'os-theme': return this.$NOs.theme
case 'dark': return 'dark'
default: return 'light'
}
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: #FFF;
2020-02-27 18:09:23 +08:00
}
.home-layout.n-layout.n-light-theme {
background-color: #FFF;
2019-06-24 01:16:38 +08:00
}
2019-06-18 16:53:16 +08:00
</style>