articleDetail.vue
4.75 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
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
<template>
<LayoutApp :show-back="true" title="社区详情">
<div class="detail-container">
<div class="author-container">
<ArticleAuthor />
</div>
<div class="source-container">
<ArticleVideo v-if="isVideo" :videoUrl="detailInfo.videoUrl" :coverUrl="detailInfo.coverUrl"></ArticleVideo>
<ArticleImage v-else :imageList="imageList"></ArticleImage>
</div>
<div class="slide-container">
<associated-item :items="detailInfo.productList"></associated-item>
</div>
<div class="note-container">
<div v-if="content" class="note-content" v-html="content"></div>
<div class="note-date">{{detailInfo.publishTimeStr.split(' ')[0]}}</div>
<div class="praise-wrapper" @click="onPraise(detailInfo)">
<div class="praise-border"></div>
<div class="praise-div">
<div :class="detailInfo.hasPraise === 'Y' ? 'praise-icon praised-icon' : 'praise-icon'"></div>
<div class="praise-num">{{detailInfo.praiseCount}}</div>
</div>
</div>
</div>
<div class="recommend-container">
<div class="recommend-text">推荐阅读</div>
<div class="recommend-list">list</div>
</div>
</div>
</LayoutApp>
</template>
<script>
import { createNamespacedHelpers } from 'vuex';
import ArticleAuthor from './components/article-author';
import ArticleVideo from './components/article-video';
import ArticleImage from './components/article-image';
import AssociatedItem from './components/associated-item';
const { mapState, mapActions } = createNamespacedHelpers('article/articleDetail');
export default {
name: 'articleDetail',
components: {
ArticleAuthor,
ArticleVideo,
ArticleImage,
AssociatedItem
},
props: {
articleId: {
required: true
}
},
computed: {
...mapState(['detailInfo']),
isVideo({detailInfo: {sort}}) {
return +sort === 4;
},
imageList({detailInfo: {blockList = []}}) {
return blockList.filter(content => content.templateKey === 'image').map(content => ({image_url: content.contentData}));
},
content({detailInfo: {blockList = [], atUserInfo = {}}}) {
const contentBlock = blockList.find(block => block.templateKey === 'text');
if (!contentBlock) {
return '';
}
const content = contentBlock.contentData || '';
return content.replace(/@(\d*)#|(\r\n|\n)/gm, (match, p1, p2)=> {
if (p2) {
return '<br/>';
}
return `<span style="color:#1890ff" id='${p1}'>@${atUserInfo[p1]}</span>`;
});
}
},
asyncData({store, router}) {
const articleId = router.params.articleId;
return store.dispatch('article/articleDetail/fetchDetailInfo', {articleId});
},
activated() {
},
methods: {
...mapActions(['updatePraiseStatus']),
async onPraise({articleId, hasPraise}) {
const user = await this.$sdk.getUser(true);
if (user && user.uid) {
this.updatePraiseStatus({
articleId,
status: hasPraise === 'Y' ? 1 : 0
});
} else {
this.$yoho.auth();
}
}
}
};
</script>
<style lang="scss" scoped>
.detail-container {
background: #fff;
}
.author-container {
width: 100%;
height: 100px;
}
.source-container {
width: 100%;
height: 750px;
}
.slide-container {
padding: 40px 0 36px 24px;
}
.note-container {
padding: 0 24px 100px;
background: #fff;
}
.note-header {
font-size: 36px;
color: #222;
letter-spacing: 0.34px;
line-height: 56px;
font-weight: bold;
}
.note-content {
font-size: 30px;
color: #000;
letter-spacing: 0.28px;
line-height: 50px;
}
.note-date {
margin-top: 20px;
font-size: 30px;
color: #999;
letter-spacing: 0.28px;
}
.praise-wrapper {
margin-top: 60px;
width: 100%;
height: 160px;
display: flex;
align-items: center;
justify-content: center;
position: relative;
}
.praise-border {
width: 160px;
height: 160px;
border-radius: 50%;
border: 2px solid #EEEEEE;
position: absolute;
top: 0;
left: calc((100%-160px)/2);
}
.praise-div {
display: flex;
flex-direction: column;
align-items: center;
.praise-icon {
width: 64px;
height: 64px;
background-image: url(~statics/image/article/praise@3x.png);
background-size: contain;
background-repeat: no-repeat;
background-position: center;
}
.praised-icon {
background-image: url(~statics/image/article/praised@3x.png);
}
.praise-num {
margin-top: 8px;
font-size: 22px;
color: #002B47;
letter-spacing: 0.21px;
}
}
.recommend-container {
background: #F2F2F2;
padding: 36px 24px 0;
}
.recommend-text {
font-size: 32px;
color: #222222;
font-weight: bold;
text-align: left;
}
.recommend-list {
margin-top: 30px;
}
</style>