Blame view

apps/pages/article/components/detail/article-header.vue 2.83 KB
yyq authored
1
<template>
yyq authored
2
  <div class="fixed-header">
陈峰 authored
3
    <LayoutHeader ref="header" :title="data.authorName" theme="transparent" :style="headerStyle">
yyq authored
4
      <template>
陈峰 authored
5
        <div ref="titleBlock" class="title-block" :class="titleClass" :style="`transform: translate3d(0, ${blockTranslateY}, 0)`">
yyq authored
6 7 8 9 10 11 12 13 14 15 16 17
          <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';
yyq authored
18
import {getDetailShareData} from 'utils/share-handler';
陈峰 authored
19
import {mapState} from 'vuex';
yyq authored
20
yyq authored
21 22 23 24 25 26 27 28
export default {
  name: 'ArticleDetailHeader',
  data() {
    return {
      shareOption: {
        color: '#fff',
        iconBold: true
      }
yyq authored
29
    };
yyq authored
30 31 32 33 34
  },
  props: [
    'data',
    'step',
    'titleStep',
陈峰 authored
35
    'share',
yyq authored
36 37
  ],
  computed: {
陈峰 authored
38
    ...mapState(['yoho']),
yyq authored
39 40 41 42
    stepPercent() {
      return parseInt(this.step, 10) / 100;
    },
    headerStyle() {
yyq authored
43 44
      let style = {};
yyq authored
45
      this.setIconColor(Math.floor((255 - 68) * (1 - this.stepPercent) + 68));
yyq authored
46 47 48 49 50
      style.background = `rgba(255,255,255,${this.stepPercent})`;

      if (this.stepPercent > 0.98) {
        style.borderBottom = '1px solid #efefef';
      }
yyq authored
51
yyq authored
52
      return style;
yyq authored
53 54
    },
    blockTranslateY() {
yyq authored
55
      return '-' + parseInt(`0${this.titleStep}`, 10) + '%';
陈峰 authored
56 57
    },
    titleClass() {
陈峰 authored
58
      if (this.yoho.context.env.isChat) {
陈峰 authored
59 60 61 62 63
        return {
          'no-padding-left': true,
          'no-padding-right': true,
        };
      }
yyq authored
64 65
    }
  },
yyq authored
66 67 68
  mounted() {
    this._iconColor && this.setIconColor(this._iconColor);
  },
yyq authored
69
  methods: {
yyq authored
70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85
    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})`;
        });
      }
    },
yyq authored
86
    onShare() {
yyq authored
87
      this.$yoho.share(getDetailShareData(this.data));
yyq authored
88 89 90
    },
    onFollow() {
      return parseInt(this.step, 10) / 100;
yyq authored
91 92 93
    },
    onBack() {
      this.$refs.header.onBack();
yyq authored
94 95 96 97 98 99 100 101
    }
  },
  components: {
    ArticleItemHeader,
  }
};
</script>
陈峰 authored
102
<style scoped lang="scss">
yyq authored
103
.fixed-header {
yyq authored
104
  position: absolute;
yyq authored
105 106 107
  width: 100%;
  z-index: 10;
  transition: all 100ms;
yyq authored
108
  box-sizing: border-box;
yyq authored
109 110

  /deep/ .title {
陈峰 authored
111
    overflow: visible !important;
yyq authored
112 113 114 115 116 117 118 119
  }

  .title-block {
    height: 100%;
    position: absolute;
    top: 100%;
    left: -60px;
    right: -60px;
陈峰 authored
120 121 122 123 124 125 126 127

    &.no-padding-left {
      left: -130px;
    }

    &.no-padding-right {
      right: -140px;
    }
yyq authored
128 129 130 131 132 133 134
  }

  .article-share {
    margin-right: 26px;
  }
}
</style>