article-header.vue
2.32 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
<template>
<div class="fixed-header" :style="headerStyle">
<LayoutHeader theme="transparent">
<template>
<div ref="titleBlock" class="title-block" :style="`transform: translate3d(0, ${blockTranslateY}, 0)`">
<slot></slot>
</div>
</template>
<template v-slot:opts>
<WidgetShare v-if="!share" class="article-share" :option="shareOption" @click.native="onShare"></WidgetShare>
</template>
</LayoutHeader>
</div>
</template>
<script>
import {get} from 'lodash';
import ArticleItemHeader from '../article/article-item-header';
export default {
name: 'ArticleDetailHeader',
data() {
return {
shareOption: {
color: '#fff',
iconBold: true
}
}
},
props: [
'data',
'step',
'titleStep',
'share'
],
computed: {
stepPercent() {
return parseInt(this.step, 10) / 100;
},
headerStyle() {
const color = Math.floor((255 - 68) * (1 - this.stepPercent) + 68);
if (this.$el) {
if (!this.icons) {
this.icons = [...this.$el.querySelectorAll('.back .iconfont'), ...this.$el.querySelectorAll('.opts .iconfont')];
}
if (this.icons && this.icons.length) {
this.icons.forEach(dom => {
dom.style.color = `rgb(${color},${color},${color})`;
});
}
}
return {
background: `rgba(255,255,255,${this.stepPercent})`
}
},
blockTranslateY() {
return '-' + parseInt(`0${this.titleStep}`, 10) + '%';
}
},
watch: {
},
methods: {
onShare() {
this.$yoho.share({
title: this.data.topicName,
imgUrl: this.data.topicImageUrl,
link: `${location.origin}/grass/topic/share/${this.data.topicId}`,
desc: '我在有货的社区发现一个热门话题。' + this.data.topicDesc,
hideType: ['7', '8', '9']
});
},
onFollow() {
return parseInt(this.step, 10) / 100;
}
},
components: {
ArticleItemHeader,
}
};
</script>
<style scoped>
.fixed-header {
position: fixed;
width: 100%;
z-index: 10;
transition: all 100ms;
/deep/ .title {
overflow: visible!important;
}
.title-block {
height: 100%;
position: absolute;
top: 100%;
left: -60px;
right: -60px;
}
.article-share {
margin-right: 26px;
}
}
</style>