article-header.vue
2.42 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
<template>
<div class="fixed-header" :style="headerStyle">
<LayoutHeader ref="header" 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 ArticleItemHeader from '../article/article-item-header';
import {getDetailShareData} from 'utils/share-handler';
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() {
let style = {};
this.setIconColor(Math.floor((255 - 68) * (1 - this.stepPercent) + 68));
style.background = `rgba(255,255,255,${this.stepPercent})`;
if (this.stepPercent > 0.98) {
style.borderBottom = '1px solid #efefef';
}
return style;
},
blockTranslateY() {
return '-' + parseInt(`0${this.titleStep}`, 10) + '%';
}
},
mounted() {
this._iconColor && this.setIconColor(this._iconColor);
},
methods: {
setIconColor(color) {
if (!this.$el) {
this._iconColor = color;
return;
}
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})`;
});
}
},
onShare() {
this.$yoho.share(getDetailShareData(this.data));
},
onFollow() {
return parseInt(this.step, 10) / 100;
},
onBack() {
this.$refs.header.onBack();
}
},
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>