app.vue 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184
  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. 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. </style>
  92. <template>
  93. <div id="app">
  94. <main-header></main-header>
  95. <div class="main-cnt">
  96. <router-view></router-view>
  97. </div>
  98. <main-footer></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 auchor = location.href.match(/#[^#]+$/g);
  134. if (!auchor || auchor.length !== 1) return;
  135. const elm = document.querySelector(auchor[0]);
  136. if (!elm) return;
  137. setTimeout(_ => {
  138. document.documentElement.scrollTop = document.body.scrollTop = elm.offsetTop;
  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>