element/examples/app.vue

89 lines
2.2 KiB
Vue
Raw Normal View History

2016-07-27 06:15:02 +00:00
<template>
<div id="app" :class="{ 'is-component': isComponent }">
2016-11-12 18:34:39 +00:00
<main-header v-if="lang !== 'play'"></main-header>
2016-08-23 11:15:15 +00:00
<div class="main-cnt">
<router-view></router-view>
</div>
<main-footer v-if="lang !== 'play' && !isComponent"></main-footer>
2016-07-27 09:05:28 +00:00
</div>
2016-07-27 06:15:02 +00:00
</template>
<script>
import { use } from 'main/locale';
import zhLocale from 'main/locale/lang/zh-CN';
import enLocale from 'main/locale/lang/en';
2017-11-06 11:22:02 +00:00
import esLocale from 'main/locale/lang/es';
const lang = location.hash.replace('#', '').split('/')[1] || 'zh-CN';
const localize = lang => {
switch (lang) {
case 'zh-CN':
use(zhLocale);
break;
case 'es':
use(esLocale);
break;
default:
use(enLocale);
}
};
localize(lang);
2016-07-27 06:15:02 +00:00
export default {
2016-09-08 10:11:18 +00:00
name: 'app',
computed: {
lang() {
return this.$route.path.split('/')[1] || 'zh-CN';
},
isComponent() {
return /^component-/.test(this.$route.name || '');
}
},
watch: {
2017-10-28 07:54:12 +00:00
lang(val) {
if (val === 'zh-CN') {
this.suggestJump();
}
2017-11-06 11:22:02 +00:00
localize(val);
}
},
2016-11-04 08:59:59 +00:00
methods: {
2017-10-28 07:54:12 +00:00
suggestJump() {
if (process.env.NODE_ENV !== 'production') return;
2017-10-28 07:54:12 +00:00
const href = location.href;
const preferGithub = localStorage.getItem('PREFER_GITHUB');
if (href.indexOf('element-cn') > -1 || href.indexOf('element.faas') > -1 || preferGithub) return;
2017-10-28 07:54:12 +00:00
setTimeout(() => {
2017-11-09 07:12:55 +00:00
if (this.lang !== 'zh-CN') return;
2017-10-28 07:54:12 +00:00
this.$confirm('建议大陆用户访问部署在国内的站点,是否跳转?', '提示')
.then(() => {
2018-03-26 09:38:17 +00:00
location.href = location.href
.replace('https:', 'http:')
.replace('element.', 'element-cn.');
2017-10-28 07:54:12 +00:00
})
.catch(() => {
localStorage.setItem('PREFER_GITHUB', 'true');
2017-10-28 07:54:12 +00:00
});
}, 1000);
2016-11-04 08:59:59 +00:00
}
},
mounted() {
2017-11-06 11:22:02 +00:00
localize(this.lang);
2017-10-28 07:54:12 +00:00
if (this.lang === 'zh-CN') {
this.suggestJump();
}
2016-09-08 10:11:18 +00:00
}
2016-07-27 06:15:02 +00:00
};
</script>
<style>
@import 'highlight.js/styles/color-brewer.css';
@import 'assets/styles/common.css';
@import 'assets/styles/fonts/style.css';
</style>