Blame view

app/pages/index.html 1.97 KB
7820380e   “wangming”   1
1
2
3
4
5
6
7
8
9
  <!DOCTYPE html>
  <html lang="en">
  <head>
      <meta charset="UTF-8">
      <meta name="viewport" content="width=device-width, initial-scale=1.0">
      <title>Document</title>
      <script src="../../../node_modules/jquery/dist/jquery.js"></script>
  </head>
  <body>
b605c21b   周超   feat: 重构多语言重定向逻辑以...
10
  
7820380e   “wangming”   1
11
12
  </body>
  <script>
b605c21b   周超   feat: 重构多语言重定向逻辑以...
13
14
15
      function getLanguageFolder(code) {
          if (code === 'ru') {
              return 'Russian';
7820380e   “wangming”   1
16
          }
b605c21b   周超   feat: 重构多语言重定向逻辑以...
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
          if (code === 'es') {
              return 'Spain';
          }
          if (code === 'cn') {
              return 'Chinese';
          }
          return 'English';
      }
  
      function getRedirectUrl(languageFolder) {
          var currentUrl = new URL(window.location.href);
          var pathname = currentUrl.pathname || '/';
          var pagesMarker = '/app/pages/';
          var targetPath = '';
  
          if (pathname.indexOf(pagesMarker) > -1) {
              targetPath = pathname.replace(
                  /\/app\/pages(?:\/index\.html|\/)?$/i,
                  '/app/pages/' + languageFolder + '/index.html'
              );
  
              if (targetPath === pathname) {
                  targetPath = pathname.split(pagesMarker)[0] + pagesMarker + languageFolder + '/index.html';
              }
          } else {
              var basePath = pathname.replace(/\/?index\.html$/i, '').replace(/\/$/, '');
  
              if (!basePath || basePath === '/') {
                  basePath = '/pc';
              }
  
              targetPath = basePath + '/app/pages/' + languageFolder + '/index.html';
          }
  
          currentUrl.pathname = targetPath.replace(/\/{2,}/g, '/');
          return currentUrl.toString();
      }
  
      function redirectToLanguage(code) {
          var targetUrl = getRedirectUrl(getLanguageFolder(code));
  
          if (targetUrl !== window.location.href) {
              window.location.replace(targetUrl);
          }
      }
  
      $.get('http://www.ccdcdf.com:6080/api/index/index', function(res) {
          redirectToLanguage(res && res.data ? res.data.code : '');
      }).fail(function() {
          redirectToLanguage('');
      });
7820380e   “wangming”   1
68
69
  </script>
  </html>