app.vue 4.9 KB

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