app.vue 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. <template>
  2. <div id="app" :class="{ 'is-component': isComponent }">
  3. <main-header v-if="lang !== 'play'"></main-header>
  4. <div class="main-cnt">
  5. <router-view></router-view>
  6. </div>
  7. <main-footer v-if="lang !== 'play' && !isComponent"></main-footer>
  8. </div>
  9. </template>
  10. <script>
  11. import { use } from 'main/locale';
  12. import zhLocale from 'main/locale/lang/zh-CN';
  13. import enLocale from 'main/locale/lang/en';
  14. import esLocale from 'main/locale/lang/es';
  15. const lang = location.hash.replace('#', '').split('/')[1] || 'zh-CN';
  16. const localize = lang => {
  17. switch (lang) {
  18. case 'zh-CN':
  19. use(zhLocale);
  20. break;
  21. case 'es':
  22. use(esLocale);
  23. break;
  24. default:
  25. use(enLocale);
  26. }
  27. };
  28. localize(lang);
  29. export default {
  30. name: 'app',
  31. computed: {
  32. lang() {
  33. return this.$route.path.split('/')[1] || 'zh-CN';
  34. },
  35. isComponent() {
  36. return /^component-/.test(this.$route.name || '');
  37. }
  38. },
  39. watch: {
  40. lang(val) {
  41. if (val === 'zh-CN') {
  42. this.suggestJump();
  43. }
  44. localize(val);
  45. }
  46. },
  47. methods: {
  48. suggestJump() {
  49. if (process.env.NODE_ENV !== 'production') return;
  50. const href = location.href;
  51. const preferGithub = localStorage.getItem('PREFER_GITHUB');
  52. if (href.indexOf('element-cn') > -1 || href.indexOf('element.faas') > -1 || preferGithub) return;
  53. setTimeout(() => {
  54. if (this.lang !== 'zh-CN') return;
  55. this.$confirm('建议大陆用户访问部署在国内的站点,是否跳转?', '提示')
  56. .then(() => {
  57. location.href = location.href
  58. .replace('https:', 'http:')
  59. .replace('element.', 'element-cn.');
  60. })
  61. .catch(() => {
  62. localStorage.setItem('PREFER_GITHUB', 'true');
  63. });
  64. }, 1000);
  65. }
  66. },
  67. mounted() {
  68. localize(this.lang);
  69. if (this.lang === 'zh-CN') {
  70. this.suggestJump();
  71. }
  72. }
  73. };
  74. </script>
  75. <style>
  76. @import 'highlight.js/styles/color-brewer.css';
  77. @import 'assets/styles/common.css';
  78. @import 'assets/styles/fonts/style.css';
  79. </style>