app.vue 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191
  1. <style lang="css">
  2. @import 'highlight.js/styles/color-brewer.css';
  3. @import 'assets/styles/common.css';
  4. html, body {
  5. margin: 0;
  6. padding: 0;
  7. height: 100%;
  8. }
  9. #app {
  10. height: 100%;
  11. }
  12. body {
  13. font-family: 'Helvetica Neue',Helvetica,'PingFang SC','Hiragino Sans GB','Microsoft YaHei',SimSun,sans-serif;
  14. overflow: auto;
  15. font-weight: 400;
  16. -webkit-font-smoothing: antialiased;
  17. }
  18. a {
  19. color: #4078c0;
  20. text-decoration: none;
  21. }
  22. button, input, select, textarea {
  23. font-family: inherit;
  24. font-size: inherit;
  25. line-height: inherit;
  26. color: inherit;
  27. }
  28. .hljs {
  29. line-height: 1.8;
  30. font-family: Menlo, Monaco, Consolas, Courier, monospace;
  31. font-size: 12px;
  32. padding: 18px 24px;
  33. background-color: #f9fafc;
  34. border: solid 1px #eaeefb;
  35. margin-bottom: 25px;
  36. border-radius: 4px;
  37. -webkit-font-smoothing: auto;
  38. }
  39. .main-cnt {
  40. margin-top: -80px;
  41. padding: 80px 0 120px;
  42. box-sizing: border-box;
  43. min-height: 100%;
  44. }
  45. .container,
  46. .page-container {
  47. width: 1140px;
  48. padding: 0 30px;
  49. margin: 0 auto;
  50. }
  51. .page-container {
  52. padding-top: 55px;
  53. h2 {
  54. font-size: 28px;
  55. color: #1f2d3d;
  56. margin: 0;
  57. }
  58. h3 {
  59. font-size: 22px;
  60. }
  61. h2, h3, h4, h5 {
  62. font-weight: normal;
  63. color: #1f2f3d;
  64. &:hover a {
  65. opacity: .4;
  66. }
  67. a {
  68. float: left;
  69. margin-left: -20px;
  70. opacity: 0;
  71. cursor: pointer;
  72. &:hover {
  73. opacity: .4;
  74. }
  75. }
  76. }
  77. p {
  78. font-size: 14px;
  79. color: #5e6d82;
  80. }
  81. }
  82. .demo {
  83. margin: 20px 0;
  84. }
  85. @media (max-width: 1140px) {
  86. .container,
  87. .page-container {
  88. width: 100%;
  89. }
  90. }
  91. @media (max-width: 768px) {
  92. .container,
  93. .page-container {
  94. padding: 0 20px;
  95. }
  96. }
  97. </style>
  98. <template>
  99. <div id="app">
  100. <main-header v-if="lang !== 'play'"></main-header>
  101. <div class="main-cnt">
  102. <router-view></router-view>
  103. </div>
  104. <main-footer v-if="lang !== 'play'"></main-footer>
  105. </div>
  106. </template>
  107. <script>
  108. import { use } from 'main/locale';
  109. import zhLocale from 'main/locale/lang/zh-CN';
  110. import enLocale from 'main/locale/lang/en';
  111. use(location.href.indexOf('zh-CN') > -1 ? zhLocale : enLocale);
  112. export default {
  113. name: 'app',
  114. computed: {
  115. lang() {
  116. return this.$route.path.split('/')[1] || 'zh-CN';
  117. }
  118. },
  119. watch: {
  120. lang() {
  121. this.localize();
  122. }
  123. },
  124. methods: {
  125. localize() {
  126. use(this.lang === 'zh-CN' ? zhLocale : enLocale);
  127. },
  128. renderAnchorHref() {
  129. if (/changelog/g.test(location.href)) return;
  130. const anchors = document.querySelectorAll('h2 a,h3 a');
  131. const basePath = location.href.split('#').splice(0, 2).join('#');
  132. [].slice.call(anchors).forEach(a => {
  133. const href = a.getAttribute('href');
  134. a.href = basePath + href;
  135. });
  136. },
  137. goAnchor() {
  138. if (location.href.match(/#/g).length > 1) {
  139. const anchor = location.href.match(/#[^#]+$/g);
  140. if (!anchor) return;
  141. const elm = document.querySelector(anchor[0]);
  142. if (!elm) return;
  143. setTimeout(_ => {
  144. document.documentElement.scrollTop = document.body.scrollTop = elm.offsetTop + 120;
  145. }, 50);
  146. }
  147. }
  148. },
  149. mounted() {
  150. this.localize();
  151. this.renderAnchorHref();
  152. this.goAnchor();
  153. },
  154. created() {
  155. window.addEventListener('hashchange', () => {
  156. if (location.href.match(/#/g).length < 2) {
  157. document.documentElement.scrollTop = document.body.scrollTop = 0;
  158. this.renderAnchorHref();
  159. } else {
  160. this.goAnchor();
  161. }
  162. });
  163. }
  164. };
  165. </script>