deemix-webui/src/components/TheContent.vue

98 lines
2.0 KiB
Vue
Raw Normal View History

2020-06-29 16:49:33 +00:00
<template>
<main
id="content"
@scroll="$route.name === 'Search' ? handleContentScroll($event) : null"
ref="content"
aria-label="main content"
>
2020-06-29 16:49:33 +00:00
<div id="container">
<BaseLoadingPlaceholder id="search_placeholder" text="Searching..." :hidden="!loading" />
<keep-alive>
<router-view
v-if="!$route.meta.notKeepAlive"
v-show="!loading"
:key="$route.fullPath"
:perform-scrolled-search="performScrolledSearch"
exclude=""
></router-view>
</keep-alive>
<router-view
v-if="$route.meta.notKeepAlive"
v-show="!loading"
:key="$route.fullPath"
:perform-scrolled-search="performScrolledSearch"
exclude=""
></router-view>
2020-06-29 16:49:33 +00:00
</div>
</main>
2020-06-29 16:49:33 +00:00
</template>
<style lang="scss">
#container {
margin: 0 auto;
max-width: 1280px;
width: var(--container-width);
}
main {
background-color: var(--main-background);
padding-right: 5px;
width: 100%;
height: calc(100vh - 93px);
overflow-y: scroll;
overflow-x: hidden;
&::-webkit-scrollbar {
width: 10px;
}
&::-webkit-scrollbar-track {
background: var(--main-background);
}
2020-06-29 16:49:33 +00:00
&::-webkit-scrollbar-thumb {
background: var(--main-scroll);
border-radius: 4px;
width: 6px;
padding: 0px 2px;
}
}
</style>
2020-06-29 16:49:33 +00:00
<script>
import { debounce } from '@/utils/utils'
import BaseLoadingPlaceholder from '@components/BaseLoadingPlaceholder.vue'
2020-06-29 16:49:33 +00:00
export default {
components: {
BaseLoadingPlaceholder
},
data: () => ({
2020-09-17 16:31:07 +00:00
performScrolledSearch: false,
loading: false
}),
mounted() {
this.$root.$on('updateSearchLoadingState', loading => {
this.loading = loading
})
this.$router.beforeEach((to, from, next) => {
this.$refs.content.scrollTo(0, 0)
next()
})
2020-09-17 16:31:07 +00:00
},
methods: {
handleContentScroll: debounce(async function () {
if (this.$refs.content.scrollTop + this.$refs.content.clientHeight < this.$refs.content.scrollHeight) return
this.performScrolledSearch = true
2020-09-17 16:31:07 +00:00
await this.$nextTick()
2020-09-17 16:31:07 +00:00
this.performScrolledSearch = false
}, 100)
}
2020-06-29 16:49:33 +00:00
}
</script>