app.vue 7.9 KB

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