article-header.vue 2.32 KB
<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>