article-header.vue
3.11 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
<template>
<div class="fixed-header">
<LayoutHeader ref="header" :title="data.authorName" theme="transparent" :style="headerStyle">
<template>
<div ref="titleBlock" class="title-block" :class="titleClass" :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 {keys} from 'lodash';
import ArticleItemHeader from '../article/article-item-header';
import {getDetailShareData} from 'utils/share-handler';
import {mapState} from 'vuex';
import Button from 'cube-ui/src/components/button/button';
export default {
name: 'ArticleDetailHeader',
data() {
return {
shareOption: {
color: '#fff',
iconBold: true
}
};
},
props: [
'data',
'step',
'titleStep',
'share',
],
computed: {
...mapState(['yoho']),
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) + '%';
},
titleClass() {
if (this.yoho.context.env.isChat) {
return {
'no-padding-left': true,
'no-padding-right': true,
};
}
}
},
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() {
const share = getDetailShareData(this.data);
keys(this.data.atUserInfo).forEach(k => {
share.desc = share.desc.replace(new RegExp(`@${k}#`, 'gm'), `${this.data.atUserInfo[k]}`);
});
this.$yoho.share(share);
},
onFollow() {
return parseInt(this.step, 10) / 100;
},
onBack() {
this.$refs.header.onBack();
}
},
components: {
Button,
ArticleItemHeader,
}
};
</script>
<style scoped lang="scss">
.fixed-header {
position: absolute;
width: 100%;
z-index: 10;
transition: all 100ms;
box-sizing: border-box;
/deep/ .title {
overflow: visible !important;
}
.title-block {
height: 100%;
position: absolute;
top: 100%;
left: -60px;
right: -60px;
&.no-padding-left {
left: -130px;
}
&.no-padding-right {
right: -140px;
}
}
.article-share {
margin-right: 26px;
}
}
</style>