article-note.vue
5.38 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
<template>
<div class="article-detail-notes">
<ArticleItemHeader v-if="share" :share="share" :data="authorData" :lazy="lazy" :more="false" @on-follow="onFollowAuthor"></ArticleItemHeader>
<LayoutHeader v-else ref="header" style="visibility: hidden;"></LayoutHeader>
<div v-if="data.empty" class="article-empty">
{{data.emptyTip || '文章不存在或文章被删除'}}
</div>
<div v-else class="article-context">
<VideoPlayer v-if="+data.sort === 4" :source="data.videoUrl" :cover="data.coverUrl"></VideoPlayer>
<ArticleItemSlide v-else :thumb="thumb" :share="share" :data="slideData" :slide-index="slideIndex" :lazy="lazy" @on-praise="onPraise" @change="onChangeSlide"></ArticleItemSlide>
<ProductGroup :article-id="data.articleId" :pos-id="0" :index="0" :thumb="thumb" v-if="productListData.length" :share="share" :data="productListData" :lazy="lazy"></ProductGroup>
<ArticleDetailIntro :data="introData"></ArticleDetailIntro>
<ArticleItemTopics :data="topicsData" :share="share"></ArticleItemTopics>
<div class="publish-time">
<span>{{publishTime}}</span>
<div v-if="data.articleId && !share" class="more-wrap">
<i class="iconfont icon-more1" @click="onMore"></i>
</div>
</div>
<ArticleDetailCommentList ref="commentList" v-if="data.articleId" :article-id="data.articleId" :share="share" :comment-count="articleState.commentCount" :has-comment="data.hasComment"></ArticleDetailCommentList>
</div>
<div v-if="listTitle" class="rec-article-title">
<LayoutTitle>{{listTitle}}</LayoutTitle>
</div>
</div>
</template>
<script>
import {get} from 'lodash';
import ArticleDetailCommentList from './comment-list';
import ArticleItemHeader from '../article/article-item-header';
import ArticleItemSlide from '../article/article-item-slide';
import ArticleItemTopics from '../article/article-item-topics';
import ArticleDetailIntro from './article-intro';
import dayjs from 'utils/day';
import {createNamespacedHelpers} from 'vuex';
const {mapState} = createNamespacedHelpers('article');
export default {
name: 'ArticleDetailNote',
props: {
data: {
type: Object,
default() {
return {};
}
},
listTitle: String,
scrollTop: Number,
scrollTo: Function,
share: Boolean,
posId: Number,
},
data() {
return {
slideIndex: 1,
commentList: [],
commentPage: 1,
commentFetching: false,
showCommentMore: false
};
},
computed: {
...mapState(['articleStates', 'authorStates']),
articleState() {
const articleState = this.articleStates[this.data.articleId] || this.data;
const authorState = this.authorStates[`${this.data.authorUid}-${this.data.authorType}`] || this.data;
return Object.assign({...articleState}, {hasAttention: authorState.hasAttention});
},
thumb() {
return !!this.data.thumb;
},
authorData() {
return {
authorName: this.data.authorName,
authorUid: this.data.authorUid,
authorType: this.data.authorType,
authorHeadIco: this.data.authorHeadIco,
authGroupId: this.data.authGroupId,
hasAttention: this.articleState.hasAttention,
isAuthor: this.data.isAuthor
};
},
slideData() {
return {
blockList: get(this.data, 'blockList', []).filter(block => block.templateKey === 'image'),
articleId: this.data.articleId,
};
},
productListData() {
return this.data.productList || [];
},
introData() {
let intro;
if (this.data.sort === 4) {
intro = this.data.content;
} else {
intro = get(get(this.data, 'blockList', []).filter(block => block.templateKey === 'text'), '[0].contentData', '');
}
return {
intro,
maxLines: 10
};
},
topicsData() {
return {
topicList: this.data.topicList,
articleType: this.data.articleType
};
},
publishTime() {
return this.data.publishTime ? dayjs(this.data.publishTime).fromNow() : '';
},
lazy() {
return this.data.lazy;
}
},
methods: {
onFollowAuthor(follow) {
this.$emit('on-follow', this.data, follow);
},
onPraise() {
this.$emit('on-praise');
},
onChangeSlide({index}) {
this.slideIndex = index;
},
onComment({comment}) {
this.$refs.commentList && this.$refs.commentList.addComment(comment);
},
toCommentList() {
if (this.$refs.commentList && this.scrollTo) {
this.scrollTo({scrollTop: this.$refs.commentList.$el.offsetTop - get(this.$refs, 'header.$el.offsetHeight', 0)});
}
},
onMore() {
this.$emit('on-show-more');
}
},
components: {
ArticleItemHeader,
ArticleItemSlide,
ArticleItemTopics,
ArticleDetailIntro,
ArticleDetailCommentList,
}
};
</script>
<style lang="scss" scoped>
.article-empty {
height: 900px;
color: #ccc;
font-size: 28px;
background-color: #f0f0f0;
display: flex;
justify-content: center;
align-items: center;
}
.publish-time {
font-size: 24px;
color: #b0b0b0;
padding: 20px 30px;
display: flex;
align-items: center;
justify-content: space-between;
.more-wrap {
display: flex;
align-items: center;
color: #444;
.iconfont {
font-size: 44px;
}
}
}
.rec-article-title {
padding: 14px 0 4px;
border-top: 1px solid #f0f0f0;
}
</style>