app.vue 5.0 KB

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