app.vue 4.2 KB

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