app.vue 7.9 KB

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