app.vue 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389
  1. <style lang="css">
  2. @import '../node_modules/purecss/build/grids-core.css';
  3. @import '../node_modules/purecss/build/grids-units.css';
  4. @import '../node_modules/purecss/build/menus.css';
  5. @import '../node_modules/highlight.js/styles/color-brewer.css';
  6. @import 'assets/styles/common.css';
  7. html, body {
  8. margin: 0;
  9. padding: 0;
  10. }
  11. body {
  12. font-family: FreeSans, Arimo, "Droid Sans", Helvetica, Arial, sans-serif;
  13. overflow: auto;
  14. }
  15. .pure-g [class *= "pure-u"] {
  16. font-family: 'Helvetica Neue',Helvetica,'PingFang SC','Hiragino Sans GB','Microsoft YaHei',SimSun,sans-serif;
  17. }
  18. .app__sidebar {
  19. width: 230px;
  20. display: block;
  21. }
  22. .app__content {
  23. margin-left: 230px;
  24. display: block;
  25. }
  26. .app__menu {
  27. bottom: 0;
  28. position: fixed;
  29. top: 0;
  30. z-index: 10;
  31. background-color: #f8f8f9;
  32. color: #20293b;
  33. .app__brand {
  34. color: #20293b;
  35. font-size: 24px;
  36. margin: 10px 0 40px;
  37. text-align: center;
  38. .app__eleme {
  39. font-weight: 900;
  40. }
  41. }
  42. .app__menu__label {
  43. color: #20293b;
  44. font-weight: bold;
  45. font-size: 14px;
  46. padding: 10px 0 10px 36px;
  47. position: relative;
  48. &::after {
  49. border-color: transparent transparent transparent rgba(170, 170, 170, .5);
  50. border-style: solid;
  51. border-width: 5px 0 5px 7px;
  52. content: " ";
  53. display: block;
  54. height: 0;
  55. position: absolute;
  56. right: 22px;
  57. top: 14px;
  58. transition-delay: .1s;
  59. transition: transform .3s;
  60. width: 0;
  61. }
  62. &.unfold::after {
  63. transform: rotate(90deg);
  64. }
  65. }
  66. .app__menu__link {
  67. padding: 12px 0 12px 50px;
  68. font-size: 14px;
  69. color: #20293b;
  70. transition: color, background-color .3s;
  71. &:focus {
  72. background-color: transparent;
  73. }
  74. &.active {
  75. border-left: 3px solid #2675c3;
  76. color: #2675c3;
  77. padding-left: 47px;
  78. }
  79. }
  80. }
  81. .app__main {
  82. .app__description {
  83. font-size: 14px;
  84. margin: 0;
  85. color: #666;
  86. padding-bottom: 36px;
  87. margin-bottom: 36px;
  88. border-bottom: 1px solid #e4e4e4;
  89. &:empty {
  90. display: none;
  91. }
  92. }
  93. a {
  94. color: #216fc1;
  95. }
  96. h2 {
  97. color: #333;
  98. font-size: 20px;
  99. font-weight: bold;
  100. margin: 60px 0 16px;
  101. line-height: 1;
  102. &:first-of-type {
  103. margin-top: 36px;
  104. }
  105. }
  106. h3 {
  107. color: #333;
  108. font-size: 16px;
  109. font-weight: normal;
  110. line-height: 1;
  111. margin: 36px 0 16px;
  112. }
  113. p, h2, h3 {
  114. +div, +span {
  115. margin: 10px 0 24px;
  116. }
  117. +span {
  118. margin-right: 8px;
  119. }
  120. }
  121. p {
  122. color: #666;
  123. font-size: 14px;
  124. margin: 0 0 16px;
  125. line-height: 1.5;
  126. }
  127. section > table {
  128. border-collapse: collapse;
  129. border-style: hidden;
  130. box-shadow: 0 0 0 1px #e1e1e1;
  131. border-radius: 5px;
  132. overflow: hidden;
  133. width: 100%;
  134. thead {
  135. background-color: #f8f8f8;
  136. font-size: 14px;
  137. th {
  138. color: #666;
  139. }
  140. }
  141. th, td {
  142. border: 1px solid #e1e1e1;
  143. padding: 10px 16px;
  144. text-align: left;
  145. font-size: 14px;
  146. color: #999;
  147. }
  148. }
  149. .hljs {
  150. border-radius: 5px;
  151. border: 1px solid #e1e1e1;
  152. font-size: 14px;
  153. max-height: 90px;
  154. overflow-y: hidden;
  155. position: relative;
  156. margin-bottom: 40px;
  157. margin-top: 0;
  158. &::before {
  159. background: linear-gradient(0deg, #fff 0, rgba(255, 255, 255, 0) 80%);
  160. bottom: 0;
  161. left: 0;
  162. position: absolute;
  163. right: 0;
  164. top: 0;
  165. content: "";
  166. }
  167. &.open {
  168. max-height: 100%;
  169. &::before {
  170. content: none;
  171. }
  172. .hljs__button::before {
  173. margin-bottom: 0;
  174. margin-top: 9px;
  175. transform: rotate(45deg);
  176. }
  177. }
  178. }
  179. .hljs__button {
  180. background-color: #fff;
  181. border-radius: 4px;
  182. border: 1px solid #ccc;
  183. outline: 0;
  184. position: absolute;
  185. right: 10px;
  186. top: 10px;
  187. height: 28px;
  188. width: 28px;
  189. &::before {
  190. margin-bottom: 2px;
  191. margin-top: 0;
  192. transform: rotate(-135deg);
  193. border-left: 1px solid #ccc;
  194. border-top: 1px solid #ccc;
  195. content: "";
  196. display: inline-block;
  197. height: 10px;
  198. width: 10px;
  199. }
  200. }
  201. }
  202. .app__header {
  203. background-color: #2c7dc7;
  204. color: #fff;
  205. padding: 42px;
  206. height: 120px;
  207. box-sizing: border-box;
  208. .app__headline {
  209. font-size: 36px;
  210. font-weight: normal;
  211. line-height: 1;
  212. margin: 0 0 10px 0;
  213. }
  214. }
  215. .slidedown-transition {
  216. transition: all .3s ease-in-out;
  217. overflow: hidden;
  218. }
  219. .slidedown-enter, .slidedown-leave {
  220. max-height: 0 !important;
  221. }
  222. .demo {
  223. margin: 20px 0;
  224. }
  225. </style>
  226. <template>
  227. <div id="app">
  228. <div class="pure-g">
  229. <div class="pure-u-1-6 app__sidebar pure-menu pure-menu-scrollable app__menu">
  230. <router-link class="pure-menu-heading app__brand" to="/">
  231. <span class="app__eleme">ELEME</span>NT
  232. </router-link>
  233. <template v-for="(nav, key) in navs">
  234. <a
  235. href="#"
  236. @click.prevent="navState.$set(key, !navState[key] || false)"
  237. class="pure-menu-heading app__menu__label"
  238. :class="{ 'unfold': !navState[key] }"
  239. v-text="nav.group"></a>
  240. <ul
  241. class="pure-menu-list"
  242. transition="slidedown"
  243. v-show="!navState[key]"
  244. :style="{
  245. maxHeight: nav.list.length * 44 + 'px'
  246. }">
  247. <li
  248. class="pure-menu-item app__menu__item"
  249. v-for="item in nav.list"
  250. v-if="!item.disabled">
  251. <router-link
  252. class="pure-menu-link app__menu__link"
  253. :to="{ path: item.path, activeClass: 'active' }"
  254. v-text="item.name"></router-link>
  255. </li>
  256. </ul>
  257. </template>
  258. </div>
  259. <div class="pure-u-5-6 app__content">
  260. <header class="app__header">
  261. <h1 class="app__headline">{{ $route.meta.title || 'element 后台组件' }}</h1>
  262. </header>
  263. <section class="app__main" ref="main">
  264. <p class="app__description">{{ $route.meta.description }}</p>
  265. <router-view></router-view>
  266. </section>
  267. <toc main=".app__main"></toc>
  268. </div>
  269. </div>
  270. <button class="hljs__button" ref="button"></button>
  271. </div>
  272. </template>
  273. <script>
  274. import { navs } from './route.config';
  275. import toc from './components/toc';
  276. import E from 'oui-dom-events';
  277. import { toggleClass, addClass, removeClass } from './dom/class';
  278. export default {
  279. name: 'app',
  280. components: {
  281. toc
  282. },
  283. data() {
  284. return {
  285. highlights: [],
  286. navState: []
  287. };
  288. },
  289. methods: {
  290. findAllHighlight() {
  291. return Array.prototype.slice.call(document.querySelectorAll('.hljs'));
  292. }
  293. },
  294. created() {
  295. this.navs = navs;
  296. },
  297. mounted() {
  298. this.mainContent = document.querySelector('.app__content');
  299. E.delegate(this.$refs.main, '.hljs__button', 'click.highlight', e => {
  300. const parent = e.target.parentNode;
  301. toggleClass(parent, 'open');
  302. });
  303. },
  304. beforeDestroy() {
  305. E.undelegate(this.$refs.main, '.hljs', 'click.highlight');
  306. },
  307. watch: {
  308. highlights(list) {
  309. list.map(item => {
  310. if (item.offsetHeight <= 100) {
  311. toggleClass(item, 'open');
  312. } else {
  313. item.appendChild(this.$els.button.cloneNode(true));
  314. }
  315. });
  316. }
  317. },
  318. events: {
  319. ['element.example.reload']() {
  320. this.$nextTick(() => {
  321. if (this.mainContent.querySelector('.no-toc')) {
  322. addClass(this.mainContent, 'no-toc');
  323. } else {
  324. removeClass(this.mainContent, 'no-toc');
  325. }
  326. this.highlights = this.findAllHighlight();
  327. });
  328. this.mainContent.scrollTop = 0;
  329. return true;
  330. }
  331. }
  332. };
  333. </script>