app.vue 2.3 KB

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