component.tpl 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224
  1. <style>
  2. .page-component__scroll {
  3. height: calc(100% - 80px);
  4. margin-top: 80px;
  5. .el-scrollbar__wrap {
  6. overflow-x: auto;
  7. }
  8. }
  9. .page-component {
  10. box-sizing: border-box;
  11. height: 100%;
  12. &.page-container {
  13. padding: 0;
  14. }
  15. .page-component__nav {
  16. width: 240px;
  17. position: fixed;
  18. top: 0;
  19. bottom: 0;
  20. margin-top: 80px;
  21. transition: padding-top .3s;
  22. .el-scrollbar__wrap {
  23. height: 100%;
  24. }
  25. &.is-extended {
  26. padding-top: 0;
  27. }
  28. }
  29. .side-nav {
  30. height: 100%;
  31. padding-top: 50px;
  32. padding-bottom: 50px;
  33. padding-right: 0;
  34. & > ul {
  35. padding-bottom: 50px;
  36. }
  37. }
  38. .page-component__content {
  39. padding-left: 270px;
  40. padding-bottom: 100px;
  41. box-sizing: border-box;
  42. }
  43. .content {
  44. padding-top: 50px;
  45. > {
  46. h3 {
  47. margin: 55px 0 20px;
  48. }
  49. table {
  50. border-collapse: collapse;
  51. width: 100%;
  52. background-color: #fff;
  53. font-size: 14px;
  54. margin-bottom: 45px;
  55. line-height: 1.5em;
  56. strong {
  57. font-weight: normal;
  58. }
  59. td, th {
  60. border-bottom: 1px solid #d8d8d8;
  61. padding: 15px;
  62. max-width: 250px;
  63. }
  64. th {
  65. text-align: left;
  66. white-space: nowrap;
  67. color: #666;
  68. font-weight: normal;
  69. }
  70. td {
  71. color: #333;
  72. }
  73. th:first-child, td:first-child {
  74. padding-left: 10px;
  75. }
  76. }
  77. ul:not(.timeline) {
  78. margin: 10px 0;
  79. padding: 0 0 0 20px;
  80. font-size: 14px;
  81. color: #5e6d82;
  82. line-height: 2em;
  83. }
  84. }
  85. }
  86. .page-component-up {
  87. background-color: #fff;
  88. position: fixed;
  89. right: 100px;
  90. bottom: 150px;
  91. size: 40px;
  92. border-radius: 20px;
  93. cursor: pointer;
  94. transition: .3s;
  95. box-shadow: 0 0 6px rgba(0,0,0, .12);
  96. i {
  97. color: #409EFF;
  98. display: block;
  99. line-height: 40px;
  100. text-align: center;
  101. font-size: 12px;
  102. }
  103. &.hover {
  104. opacity: 1;
  105. }
  106. }
  107. .back-top-fade-enter,
  108. .back-top-fade-leave-active {
  109. transform: translateY(-30px);
  110. opacity: 0;
  111. }
  112. }
  113. </style>
  114. <template>
  115. <el-scrollbar class="page-component__scroll" ref="componentScrollBar">
  116. <div class="page-container page-component">
  117. <el-scrollbar class="page-component__nav">
  118. <side-nav :data="navsData[lang]" :base="`/${ lang }/component`"></side-nav>
  119. </el-scrollbar>
  120. <div class="page-component__content">
  121. <router-view class="content"></router-view>
  122. <footer-nav></footer-nav>
  123. </div>
  124. <transition name="back-top-fade">
  125. <div
  126. class="page-component-up"
  127. :class="{ 'hover': hover }"
  128. v-show="showBackToTop"
  129. @mouseenter="hover = true"
  130. @mouseleave="hover = false"
  131. @click="toTop">
  132. <i class="el-icon-caret-top"></i>
  133. </div>
  134. </transition>
  135. </div>
  136. </el-scrollbar>
  137. </template>
  138. <script>
  139. import bus from '../../bus';
  140. import navsData from '../../nav.config.json';
  141. import throttle from 'throttle-debounce/throttle';
  142. export default {
  143. data() {
  144. return {
  145. lang: this.$route.meta.lang,
  146. navsData,
  147. hover: false,
  148. showBackToTop: false,
  149. scrollTop: 0,
  150. showHeader: true,
  151. componentScrollBar: null,
  152. componentScrollBoxElement: null
  153. };
  154. },
  155. watch: {
  156. '$route.path'() {
  157. // 触发伪滚动条更新
  158. this.componentScrollBox.scrollTop = 0;
  159. this.$nextTick(() => {
  160. this.componentScrollBar.update();
  161. });
  162. }
  163. },
  164. methods: {
  165. toTop() {
  166. this.hover = false;
  167. this.showBackToTop = false;
  168. this.componentScrollBox.scrollTop = 0;
  169. },
  170. handleScroll() {
  171. const scrollTop = this.componentScrollBox.scrollTop;
  172. this.showBackToTop = scrollTop >= 0.5 * document.body.clientHeight;
  173. if (this.showHeader !== this.scrollTop > scrollTop) {
  174. this.showHeader = this.scrollTop > scrollTop;
  175. bus.$emit('toggleHeader', this.showHeader);
  176. }
  177. if (scrollTop === 0) {
  178. this.showHeader = true;
  179. bus.$emit('toggleHeader', this.showHeader);
  180. }
  181. if (!this.navFaded) {
  182. bus.$emit('fadeNav');
  183. }
  184. this.scrollTop = scrollTop;
  185. }
  186. },
  187. created() {
  188. bus.$on('navFade', val => {
  189. this.navFaded = val;
  190. });
  191. },
  192. mounted() {
  193. this.componentScrollBar = this.$refs.componentScrollBar;
  194. this.componentScrollBox = this.componentScrollBar.$el.querySelector('.el-scrollbar__wrap');
  195. this.throttledScrollHandler = throttle(300, this.handleScroll);
  196. this.componentScrollBox.addEventListener('scroll', this.throttledScrollHandler);
  197. },
  198. beforeDestroy() {
  199. this.componentScrollBox.removeEventListener('scroll', this.throttledScrollHandler);
  200. }
  201. };
  202. </script>