app.vue 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266
  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: 1000;
  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: #f9fafc;
  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-top: 20px;
  110. code {
  111. background-color: rgba(255, 255, 255, .7);
  112. color: #445368;
  113. }
  114. }
  115. .warning {
  116. border-bottom-right-radius: 4px;
  117. border-left: 4px solid #f66;
  118. border-top-right-radius: 4px;
  119. padding: 12px 24px 12px 30px;
  120. position: relative;
  121. background-color: #f8f8f8;
  122. margin-top: 20px;
  123. &::before {
  124. background-color: #f66;
  125. border-radius: 100%;
  126. color: #fff;
  127. content: "!";
  128. font-family: Dosis,Source Sans Pro,Helvetica Neue,Arial,sans-serif;
  129. font-size: 14px;
  130. font-weight: 700;
  131. left: -12px;
  132. line-height: 20px;
  133. position: absolute;
  134. width: 20px;
  135. height: 20px;
  136. text-align: center;
  137. top: 50%;
  138. transform: translateY(-50%);
  139. }
  140. code {
  141. background-color: rgba(255, 255, 255, .7);
  142. color: #445368;
  143. }
  144. }
  145. }
  146. .demo {
  147. margin: 20px 0;
  148. }
  149. @media (max-width: 1140px) {
  150. .container,
  151. .page-container {
  152. width: 100%;
  153. }
  154. }
  155. @media (max-width: 768px) {
  156. .container,
  157. .page-container {
  158. padding: 0 20px;
  159. }
  160. }
  161. </style>
  162. <template>
  163. <div id="app" :class="{ 'is-component': isComponent }">
  164. <main-header v-if="lang !== 'play'"></main-header>
  165. <div class="main-cnt">
  166. <router-view></router-view>
  167. </div>
  168. <main-footer v-if="lang !== 'play' && !isComponent"></main-footer>
  169. </div>
  170. </template>
  171. <script>
  172. import { use } from 'main/locale';
  173. import zhLocale from 'main/locale/lang/zh-CN';
  174. import enLocale from 'main/locale/lang/en';
  175. use(location.href.indexOf('zh-CN') > -1 ? zhLocale : enLocale);
  176. export default {
  177. name: 'app',
  178. computed: {
  179. lang() {
  180. return this.$route.path.split('/')[1] || 'zh-CN';
  181. },
  182. isComponent() {
  183. return /^component-/.test(this.$route.name || '');
  184. }
  185. },
  186. watch: {
  187. lang() {
  188. this.localize();
  189. }
  190. },
  191. methods: {
  192. localize() {
  193. use(this.lang === 'zh-CN' ? zhLocale : enLocale);
  194. },
  195. renderAnchorHref() {
  196. if (/changelog/g.test(location.href)) return;
  197. const anchors = document.querySelectorAll('h2 a,h3 a');
  198. const basePath = location.href.split('#').splice(0, 2).join('#');
  199. [].slice.call(anchors).forEach(a => {
  200. const href = a.getAttribute('href');
  201. a.href = basePath + href;
  202. });
  203. },
  204. goAnchor() {
  205. if (location.href.match(/#/g).length > 1) {
  206. const anchor = location.href.match(/#[^#]+$/g);
  207. if (!anchor) return;
  208. const elm = document.querySelector(anchor[0]);
  209. if (!elm) return;
  210. setTimeout(_ => {
  211. document.documentElement.scrollTop = document.body.scrollTop = elm.offsetTop + 120;
  212. }, 50);
  213. }
  214. }
  215. },
  216. mounted() {
  217. this.localize();
  218. this.renderAnchorHref();
  219. this.goAnchor();
  220. },
  221. created() {
  222. window.addEventListener('hashchange', () => {
  223. if (location.href.match(/#/g).length < 2) {
  224. document.documentElement.scrollTop = document.body.scrollTop = 0;
  225. this.renderAnchorHref();
  226. } else {
  227. this.goAnchor();
  228. }
  229. });
  230. }
  231. };
  232. </script>