app.vue 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  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. const cnHref = href.indexOf('eleme.cn') > -1 || href.indexOf('element-cn') > -1 || href.indexOf('element.faas') > -1;
  57. if (cnHref || preferGithub) return;
  58. setTimeout(() => {
  59. if (this.lang !== 'zh-CN') return;
  60. this.$confirm('建议大陆用户访问部署在国内的站点,是否跳转?', '提示')
  61. .then(() => {
  62. location.replace('https://element.eleme.cn');
  63. })
  64. .catch(() => {
  65. localStorage.setItem('PREFER_GITHUB', 'true');
  66. });
  67. }, 1000);
  68. }
  69. },
  70. mounted() {
  71. localize(this.lang);
  72. if (this.lang === 'zh-CN') {
  73. this.suggestJump();
  74. }
  75. }
  76. };
  77. </script>