wip
This commit is contained in:
parent
b8f7eb9b58
commit
b427807bf6
@ -1,5 +1,5 @@
|
|||||||
<template>
|
<template>
|
||||||
<div class="mk-timeline">
|
<div class="mk-timeline" ref="root">
|
||||||
<template each={ post, i in posts }>
|
<template each={ post, i in posts }>
|
||||||
<mk-timeline-post post={ post }/>
|
<mk-timeline-post post={ post }/>
|
||||||
<p class="date" v-if="i != posts.length - 1 && post._date != posts[i + 1]._date"><span>%fa:angle-up%{ post._datetext }</span><span>%fa:angle-down%{ posts[i + 1]._datetext }</span></p>
|
<p class="date" v-if="i != posts.length - 1 && post._date != posts[i + 1]._date"><span>%fa:angle-up%{ post._datetext }</span><span>%fa:angle-down%{ posts[i + 1]._datetext }</span></p>
|
||||||
@ -10,49 +10,31 @@
|
|||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script lang="typescript">
|
<script lang="ts">
|
||||||
this.posts = [];
|
import Vue from 'vue';
|
||||||
|
|
||||||
this.on('update', () => {
|
export default Vue.extend({
|
||||||
this.posts.forEach(post => {
|
props: ['posts'],
|
||||||
|
computed: {
|
||||||
|
_posts(): any {
|
||||||
|
return this.posts.map(post => {
|
||||||
const date = new Date(post.created_at).getDate();
|
const date = new Date(post.created_at).getDate();
|
||||||
const month = new Date(post.created_at).getMonth() + 1;
|
const month = new Date(post.created_at).getMonth() + 1;
|
||||||
post._date = date;
|
post._date = date;
|
||||||
post._datetext = `${month}月 ${date}日`;
|
post._datetext = `${month}月 ${date}日`;
|
||||||
|
return post;
|
||||||
});
|
});
|
||||||
});
|
},
|
||||||
|
tail(): any {
|
||||||
this.setPosts = posts => {
|
|
||||||
this.update({
|
|
||||||
posts: posts
|
|
||||||
});
|
|
||||||
};
|
|
||||||
|
|
||||||
this.prependPosts = posts => {
|
|
||||||
posts.forEach(post => {
|
|
||||||
this.posts.push(post);
|
|
||||||
this.update();
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
this.addPost = post => {
|
|
||||||
this.posts.unshift(post);
|
|
||||||
this.update();
|
|
||||||
};
|
|
||||||
|
|
||||||
this.tail = () => {
|
|
||||||
return this.posts[this.posts.length - 1];
|
return this.posts[this.posts.length - 1];
|
||||||
};
|
}
|
||||||
|
},
|
||||||
this.clear = () => {
|
methods: {
|
||||||
this.posts = [];
|
focus() {
|
||||||
this.update();
|
this.$refs.root.children[0].focus();
|
||||||
};
|
}
|
||||||
|
}
|
||||||
this.focus = () => {
|
});
|
||||||
this.root.children[0].focus();
|
|
||||||
};
|
|
||||||
|
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<style lang="stylus" scoped>
|
<style lang="stylus" scoped>
|
||||||
|
Loading…
Reference in New Issue
Block a user