app.vue 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244
  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. @media (max-width: 1140px) {
  105. .container,
  106. .page-container {
  107. width: 100%;
  108. }
  109. }
  110. @media (max-width: 768px) {
  111. .container,
  112. .page-container {
  113. padding: 0 20px;
  114. }
  115. }
  116. </style>
  117. <template>
  118. <div id="app">
  119. <main-header v-if="lang !== 'play'"></main-header>
  120. <div class="main-cnt">
  121. <router-view></router-view>
  122. </div>
  123. <main-footer v-if="lang !== 'play'"></main-footer>
  124. </div>
  125. </template>
  126. <script>
  127. import { use } from 'main/locale';
  128. import zhLocale from 'main/locale/lang/zh-CN';
  129. import enLocale from 'main/locale/lang/en';
  130. use(location.href.indexOf('zh-CN') > -1 ? zhLocale : enLocale);
  131. export default {
  132. name: 'app',
  133. computed: {
  134. lang() {
  135. return this.$route.path.split('/')[1] || 'zh-CN';
  136. }
  137. },
  138. watch: {
  139. lang() {
  140. this.localize();
  141. }
  142. },
  143. methods: {
  144. localize() {
  145. use(this.lang === 'zh-CN' ? zhLocale : enLocale);
  146. },
  147. renderAnchorHref() {
  148. if (/changelog/g.test(location.href)) return;
  149. const anchors = document.querySelectorAll('h2 a,h3 a');
  150. const basePath = location.href.split('#').splice(0, 2).join('#');
  151. [].slice.call(anchors).forEach(a => {
  152. const href = a.getAttribute('href');
  153. a.href = basePath + href;
  154. });
  155. },
  156. goAnchor() {
  157. if (location.href.match(/#/g).length > 1) {
  158. const anchor = location.href.match(/#[^#]+$/g);
  159. if (!anchor) return;
  160. const elm = document.querySelector(anchor[0]);
  161. if (!elm) return;
  162. setTimeout(_ => {
  163. document.documentElement.scrollTop = document.body.scrollTop = elm.offsetTop + 120;
  164. }, 50);
  165. }
  166. }
  167. },
  168. mounted() {
  169. this.localize();
  170. this.renderAnchorHref();
  171. this.goAnchor();
  172. setTimeout(() => {
  173. const notified = localStorage.getItem('ALPHA_NOTIFIED');
  174. if (!notified) {
  175. const h = this.$createElement;
  176. const title = this.lang === 'zh-CN'
  177. ? '2.0.0-alpha.1 发布'
  178. : '2.0.0-alpha.1 released';
  179. const messages = this.lang === 'zh-CN'
  180. ? ['点击', '这里', '查看详情']
  181. : ['Click ', 'here', ' to learn more'];
  182. this.$notify.success({
  183. title,
  184. duration: 0,
  185. message: h('span', [
  186. messages[0],
  187. h('a', {
  188. attrs: {
  189. target: '_blank',
  190. href: `https://github.com/ElemeFE/element/issues/${ this.lang === 'zh-CN' ? '7304' : '7305' }`
  191. }
  192. }, messages[1]),
  193. messages[2]
  194. ]),
  195. onClose() {
  196. localStorage.setItem('ALPHA_NOTIFIED', 1);
  197. }
  198. });
  199. }
  200. }, 3500);
  201. },
  202. created() {
  203. window.addEventListener('hashchange', () => {
  204. if (location.href.match(/#/g).length < 2) {
  205. document.documentElement.scrollTop = document.body.scrollTop = 0;
  206. this.renderAnchorHref();
  207. } else {
  208. this.goAnchor();
  209. }
  210. });
  211. }
  212. };
  213. </script>