app.vue 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267
  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: #4078c0;
  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(#fff, .7);
  97. color: #445368;
  98. }
  99. }
  100. }
  101. .demo {
  102. margin: 20px 0;
  103. }
  104. .carbon-teaser {
  105. border-radius: 0;
  106. .el-dialog__header {
  107. display: none;
  108. }
  109. .el-dialog__body {
  110. padding: 0;
  111. position: relative;
  112. }
  113. .carbon-teaser__main {
  114. width: 100%;
  115. }
  116. .carbon-teaser__close {
  117. position: absolute;
  118. width: 50px;
  119. top: -25px;
  120. right: -25px;
  121. cursor: pointer;
  122. }
  123. }
  124. @media (max-width: 1140px) {
  125. .container,
  126. .page-container {
  127. width: 100%;
  128. }
  129. }
  130. @media (max-width: 768px) {
  131. .container,
  132. .page-container {
  133. padding: 0 20px;
  134. }
  135. }
  136. </style>
  137. <template>
  138. <div id="app">
  139. <main-header v-if="lang !== 'play'"></main-header>
  140. <div class="main-cnt">
  141. <router-view></router-view>
  142. </div>
  143. <main-footer v-if="lang !== 'play'"></main-footer>
  144. <el-dialog
  145. :visible.sync="dialogVisible"
  146. custom-class="carbon-teaser"
  147. @close="handleDialogClose"
  148. :close-on-press-escape="false"
  149. :close-on-click-modal="false">
  150. <img
  151. src="~examples/assets/images/carbon-teaser.png"
  152. class="carbon-teaser__main">
  153. <img
  154. @click="dialogVisible = false"
  155. src="~examples/assets/images/dialog-close.png"
  156. class="carbon-teaser__close">
  157. </el-dialog>
  158. </div>
  159. </template>
  160. <script>
  161. import { use } from 'main/locale';
  162. import zhLocale from 'main/locale/lang/zh-CN';
  163. import enLocale from 'main/locale/lang/en';
  164. use(location.href.indexOf('zh-CN') > -1 ? zhLocale : enLocale);
  165. export default {
  166. name: 'app',
  167. data() {
  168. return {
  169. dialogVisible: false
  170. };
  171. },
  172. computed: {
  173. lang() {
  174. return this.$route.path.split('/')[1] || 'zh-CN';
  175. }
  176. },
  177. watch: {
  178. lang() {
  179. this.localize();
  180. }
  181. },
  182. methods: {
  183. localize() {
  184. use(this.lang === 'zh-CN' ? zhLocale : enLocale);
  185. },
  186. renderAnchorHref() {
  187. if (/changelog/g.test(location.href)) return;
  188. const anchors = document.querySelectorAll('h2 a,h3 a');
  189. const basePath = location.href.split('#').splice(0, 2).join('#');
  190. [].slice.call(anchors).forEach(a => {
  191. const href = a.getAttribute('href');
  192. a.href = basePath + href;
  193. });
  194. },
  195. goAnchor() {
  196. if (location.href.match(/#/g).length > 1) {
  197. const anchor = location.href.match(/#[^#]+$/g);
  198. if (!anchor) return;
  199. const elm = document.querySelector(anchor[0]);
  200. if (!elm) return;
  201. setTimeout(_ => {
  202. document.documentElement.scrollTop = document.body.scrollTop = elm.offsetTop + 120;
  203. }, 50);
  204. }
  205. },
  206. handleDialogClose() {
  207. localStorage.setItem('CARBON_TEASER', 1);
  208. }
  209. },
  210. mounted() {
  211. this.localize();
  212. this.renderAnchorHref();
  213. this.goAnchor();
  214. const intrigued = localStorage.getItem('CARBON_TEASER');
  215. if (!intrigued) {
  216. setTimeout(() => {
  217. this.dialogVisible = true;
  218. }, 2000);
  219. }
  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>