banner.vue 2.89 KB
<template>
  <div class="topic-head" :style="headStyle">
    <div class="center">
      <p class="desc">{{data.topicDesc}}</p>
      <div v-if="showAttAmount" class="att-amount">
        <label>{{data.attAmount}}人已关注</label>
      </div>
      <div v-if="+data.allowAttention" class="att-topic-btn" :class="attClass">
        <WidgetFollow class="att-click-wrap" :topic-id="data.topicId" :follow="data.hasAttention" @on-follow="onFollow"></WidgetFollow>
        <template v-if="data.hasAttention">
          已关注
        </template>
        <template v-else>
          <span class="iconfont icon-plus"></span>
          关注话题
        </template>
      </div>
    </div>
  </div>
</template>

<script>
export default {
  props: ['data'],
  computed: {
    headStyle() {
      if (!this.data.topicImageUrl) {
        return {};
      }

      return {
        'background-image': `url(//${this.data.topicImageUrl.split('//')[1]})`
      };
    },
    showAttAmount() {
      return this.data && +this.data.showAttAmount > 0;
    },
    attClass() {
      return {
        active: this.data.hasAttention
      };
    }
  },
  methods: {
    onFollow(follow) {
      this.$emit('on-follow', follow);
    },
  }
};
</script>

<style scoped>
.topic-head {
  min-height: 360px;
  background-size: 100%;
  background-image: linear-gradient(140deg, #7A88FF, #7AFFAF);
  padding-top: 44PX;
  box-sizing: border-box;
  position: relative;
  background-size: cover;
  display: flex;
  align-items: center;

  &:before {
    content: "";
    background: rgba(0, 0, 0, 0.5);
    position: absolute;
    left: 0;
    right: 0;
    top: 0;
    bottom: 0;
    z-index: 1;
  }

  .center {
    width: 100%;
    position: relative;
    z-index: 2;
    text-align: center;
    padding: 40px 100px;
    box-sizing: border-box;
  }

  .desc {
    font-size: 24px;
    color: #fff;
    line-height: 1.42;
    word-break: break-all;
  }

  $attColor: #b0b0b0;

  .att-amount {
    margin-top: 20px;
    color: $attColor;
    display: flex;
    justify-content: center;

    label {
      display: inline-block;
      position: relative;
      line-height: 1;

      &:before,
      &:after {
        content: "";
        width: 60px;
        height: 2px;
        background-color: $attColor;
        display: block;
        position: absolute;
        top: 50%;
        margin-top: -1px;
      }

      &:before {
        right: calc(100% + 20px);
      }

      &:after {
        left: calc(100% + 20px);
      }
    }
  }

  .att-topic-btn {
    width: 200px;
    height: 50px;
    font-size: 26px;
    border-radius: 28px;
    line-height: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    background-color: #d90025;
    color: #fff;
    margin: 36px auto 0;
    position: relative;

    .iconfont {
      font-weight: bold;
      margin-right: 10px;
    }

    &.active {
      background-color: #e48a8a;
    }
  }
}
</style>