app.vue 3.8 KB

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