This commit is contained in:
syuilo 2018-06-06 01:54:24 +09:00
parent 64519a9fd4
commit 062fbd7d27
2 changed files with 49 additions and 41 deletions

View file

@ -1,6 +1,6 @@
<template> <template>
<div class="dnpfarvgbnfmyzbdquhhzyxcmstpdqzs"> <div class="dnpfarvgbnfmyzbdquhhzyxcmstpdqzs">
<header> <header :class="{ indicate }">
<slot name="header"></slot> <slot name="header"></slot>
</header> </header>
<div ref="body"> <div ref="body">
@ -11,30 +11,44 @@
<script lang="ts"> <script lang="ts">
import Vue from 'vue'; import Vue from 'vue';
import XTl from './deck.tl.vue';
export default Vue.extend({ export default Vue.extend({
components: { data() {
XTl
},
provide() {
return { return {
getColumn() { indicate: false
return this;
},
getScrollContainer() {
return this.$refs.body;
}
}; };
}, },
mounted() {
this.$nextTick(() => {
this.$emit('mounted');
setInterval(() => { provide() {
this.$emit('mounted'); return {
}, 100); column: this,
}); isScrollTop: this.isScrollTop,
indicate: v => this.indicate = v
};
},
mounted() {
this.$refs.body.addEventListener('scroll', this.onScroll);
},
beforeDestroy() {
this.$refs.body.removeEventListener('scroll', this.onScroll);
},
methods: {
isScrollTop() {
return this.$refs.body.scrollTop == 0;
},
onScroll() {
if (this.isScrollTop()) {
this.$emit('top');
}
if (this.$store.state.settings.fetchOnScroll !== false) {
const current = this.$refs.body.scrollTop + this.$refs.body.clientHeight;
if (current > this.$refs.body.scrollHeight - 1) this.$emit('bottom');
}
}
} }
}); });
</script> </script>
@ -61,6 +75,9 @@ root(isDark)
background isDark ? #313543 : #fff background isDark ? #313543 : #fff
box-shadow 0 1px rgba(#000, 0.15) box-shadow 0 1px rgba(#000, 0.15)
&.indicate
box-shadow 0 3px 0 0 $theme-color
> div > div
height calc(100% - 42px) height calc(100% - 42px)
overflow auto overflow auto

View file

@ -1,7 +1,5 @@
<template> <template>
<div class="eamppglmnmimdhrlzhplwpvyeaqmmhxu"> <div class="eamppglmnmimdhrlzhplwpvyeaqmmhxu">
<div class="newer-indicator" v-show="queue.length > 0"></div>
<slot name="empty" v-if="notes.length == 0 && !fetching && requestInitPromise == null"></slot> <slot name="empty" v-if="notes.length == 0 && !fetching && requestInitPromise == null"></slot>
<div v-if="!fetching && requestInitPromise != null"> <div v-if="!fetching && requestInitPromise != null">
@ -42,6 +40,8 @@ export default Vue.extend({
XNote XNote
}, },
inject: ['column', 'isScrollTop', 'indicate'],
props: { props: {
more: { more: {
type: Function, type: Function,
@ -73,25 +73,17 @@ export default Vue.extend({
} }
}, },
inject: ['getColumn', 'getScrollContainer'],
created() { created() {
this.getColumn().$once('mounted', () => { this.column.$on('top', this.onTop);
this.rootEl = this.getScrollContainer(); this.column.$on('bottom', this.onBottom);
this.rootEl.addEventListener('scroll', this.onScroll);
})
}, },
beforeDestroy() { beforeDestroy() {
this.rootEl.removeEventListener('scroll', this.onScroll); this.column.$off('top', this.onTop);
this.column.$off('bottom', this.onBottom);
}, },
methods: { methods: {
isScrollTop() {
if (this.rootEl == null) return true;
return this.rootEl.scrollTop <= 8;
},
focus() { focus() {
(this.$el as any).children[0].focus(); (this.$el as any).children[0].focus();
}, },
@ -149,6 +141,7 @@ export default Vue.extend({
} }
} else { } else {
this.queue.push(note); this.queue.push(note);
this.indicate(true);
} }
}, },
@ -163,6 +156,7 @@ export default Vue.extend({
releaseQueue() { releaseQueue() {
this.queue.forEach(n => this.prepend(n, true)); this.queue.forEach(n => this.prepend(n, true));
this.queue = []; this.queue = [];
this.indicate(false);
}, },
async loadMore() { async loadMore() {
@ -174,15 +168,12 @@ export default Vue.extend({
this.moreFetching = false; this.moreFetching = false;
}, },
onScroll() { onTop() {
if (this.isScrollTop()) {
this.releaseQueue(); this.releaseQueue();
} },
if (this.rootEl && this.$store.state.settings.fetchOnScroll !== false) { onBottom() {
const current = this.rootEl.scrollTop + this.rootEl.clientHeight; this.loadMore();
if (current > this.rootEl.scrollHeight - 8) this.loadMore();
}
} }
} }
}); });