app.vue 4.8 KB

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