element/examples/pages/template/component.tpl

225 lines
5.0 KiB
Smarty
Raw Normal View History

2016-11-09 11:15:25 +00:00
<style>
.page-component__scroll {
height: calc(100% - 80px);
margin-top: 80px;
.el-scrollbar__wrap {
overflow-x: auto;
}
}
2016-11-09 11:15:25 +00:00
.page-component {
2016-11-18 08:49:07 +00:00
box-sizing: border-box;
height: 100%;
&.page-container {
padding: 0;
}
.page-component__nav {
width: 240px;
position: fixed;
top: 0;
bottom: 0;
margin-top: 80px;
transition: padding-top .3s;
.el-scrollbar__wrap {
height: 100%;
}
&.is-extended {
padding-top: 0;
}
}
.side-nav {
height: 100%;
padding-top: 50px;
padding-bottom: 50px;
padding-right: 0;
& > ul {
padding-bottom: 50px;
}
}
.page-component__content {
padding-left: 270px;
padding-bottom: 100px;
box-sizing: border-box;
}
.content {
padding-top: 50px;
2016-11-09 11:15:25 +00:00
> {
h3 {
2017-09-29 07:37:50 +00:00
margin: 55px 0 20px;
2016-11-09 11:15:25 +00:00
}
2017-09-28 12:15:00 +00:00
2016-11-09 11:15:25 +00:00
table {
border-collapse: collapse;
width: 100%;
background-color: #fff;
font-size: 14px;
margin-bottom: 45px;
line-height: 1.5em;
2016-11-09 11:15:25 +00:00
strong {
font-weight: normal;
}
2017-09-28 12:15:00 +00:00
td, th {
border-bottom: 1px solid #eaeefb;
padding: 15px;
max-width: 250px;
}
2016-11-09 11:15:25 +00:00
th {
text-align: left;
2016-12-13 14:52:29 +00:00
white-space: nowrap;
2017-09-28 12:15:00 +00:00
color: #666;
font-weight: normal;
2016-11-09 11:15:25 +00:00
}
2017-09-28 12:15:00 +00:00
td {
color: #333;
2016-11-09 11:15:25 +00:00
}
2017-09-28 12:15:00 +00:00
2016-11-09 11:15:25 +00:00
th:first-child, td:first-child {
padding-left: 10px;
}
}
2017-09-28 12:15:00 +00:00
ul:not(.timeline) {
margin: 10px 0;
padding: 0 0 0 20px;
font-size: 14px;
color: #5e6d82;
line-height: 2em;
}
2016-11-09 11:15:25 +00:00
}
}
.page-component-up {
background-color: #fff;
position: fixed;
right: 100px;
bottom: 150px;
size: 40px;
border-radius: 20px;
cursor: pointer;
transition: .3s;
box-shadow: 0 0 6px rgba(0,0,0, .12);
i {
color: #409EFF;
display: block;
line-height: 40px;
text-align: center;
font-size: 12px;
}
&.hover {
opacity: 1;
}
}
.back-top-fade-enter,
.back-top-fade-leave-active {
transform: translateY(-30px);
opacity: 0;
}
2016-11-09 11:15:25 +00:00
}
</style>
<template>
<el-scrollbar class="page-component__scroll" ref="componentScrollBar">
2016-11-09 11:15:25 +00:00
<div class="page-container page-component">
<el-scrollbar class="page-component__nav">
<side-nav :data="navsData[lang]" :base="`/${ lang }/component`"></side-nav>
</el-scrollbar>
<div class="page-component__content">
<router-view class="content"></router-view>
<footer-nav></footer-nav>
</div>
<transition name="back-top-fade">
<div
class="page-component-up"
:class="{ 'hover': hover }"
v-show="showBackToTop"
@mouseenter="hover = true"
@mouseleave="hover = false"
@click="toTop">
<i class="el-icon-caret-top"></i>
</div>
</transition>
2016-11-09 11:15:25 +00:00
</div>
</el-scrollbar>
2016-11-09 11:15:25 +00:00
</template>
<script>
import bus from '../../bus';
2016-11-09 11:15:25 +00:00
import navsData from '../../nav.config.json';
import throttle from 'throttle-debounce/throttle';
2017-09-28 12:15:00 +00:00
2016-11-09 11:15:25 +00:00
export default {
data() {
return {
lang: this.$route.meta.lang,
navsData,
hover: false,
showBackToTop: false,
scrollTop: 0,
showHeader: true,
componentScrollBar: null,
componentScrollBoxElement: null
2016-11-09 11:15:25 +00:00
};
},
watch: {
'$route.path'() {
// 触发伪滚动条更新
this.componentScrollBox.scrollTop = 0;
this.$nextTick(() => {
this.componentScrollBar.update();
});
}
},
methods: {
toTop() {
this.hover = false;
this.showBackToTop = false;
2017-09-30 10:13:26 +00:00
this.componentScrollBox.scrollTop = 0;
},
handleScroll() {
2017-09-30 10:13:26 +00:00
const scrollTop = this.componentScrollBox.scrollTop;
this.showBackToTop = scrollTop >= 0.5 * document.body.clientHeight;
if (this.showHeader !== this.scrollTop > scrollTop) {
this.showHeader = this.scrollTop > scrollTop;
bus.$emit('toggleHeader', this.showHeader);
}
if (scrollTop === 0) {
this.showHeader = true;
bus.$emit('toggleHeader', this.showHeader);
}
2017-09-29 07:37:50 +00:00
if (!this.navFaded) {
bus.$emit('fadeNav');
}
this.scrollTop = scrollTop;
}
},
2017-09-29 07:37:50 +00:00
created() {
bus.$on('navFade', val => {
this.navFaded = val;
});
},
mounted() {
this.componentScrollBar = this.$refs.componentScrollBar;
this.componentScrollBox = this.componentScrollBar.$el.querySelector('.el-scrollbar__wrap');
this.throttledScrollHandler = throttle(300, this.handleScroll);
this.componentScrollBox.addEventListener('scroll', this.throttledScrollHandler);
},
beforeDestroy() {
this.componentScrollBox.removeEventListener('scroll', this.throttledScrollHandler);
2016-11-09 11:15:25 +00:00
}
};
</script>