app.vue 8.1 KB

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