app.vue 3.5 KB

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