app.vue 4.9 KB

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