app.vue 5.0 KB

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