DataListItem.vue 2.59 KB
<template>
  <section class="data-list-item" @click="$emit('click')">
    <div class="item-title">
      <div class="title-tag">
        <slot name="tag"></slot>
      </div>
      <span class="title-content" v-indent="10">{{data.title}}</span>
    </div>
    <div class="item-bottom">
      <div class="bottom-content">
        <slot v-bind:value="data" name="bottomLeft" />
        <template v-if="!$slots.bottomLeft">
          <img class="bottom-icon" src="@/assets/icon/icon_clock.png">
          <span class="bottom-text">{{dateText}}{{data.date}}</span>
        </template>
      </div>
      <div class="bottom-content">
        <slot v-bind:value="data" name="bottomRight" />
        <template v-if="!$slots.bottomRight">
          <img class="bottom-icon" src="@/assets/icon/icon_classify.png">
          <span>{{data.dataType}}</span>
        </template>
      </div>
    </div>
  </section>
</template>

<script>
export default {
  name: 'DataListItem',
  props: {
    data: {
      type: Object,
      default: () => { return {} }
    },
    dateText: {
      type: String
    },
    tag: {
      type: String
    }
  },
  data () {
    return {}
  },
  methods: {

  },
  directives: {
    indent: {
      inserted (el, binding) {
        setTimeout(() => {
          const nodes = el.previousElementSibling.childNodes
          const data = { width: 0 }

          for (const node of nodes) {
            data.width = data.width + node.offsetWidth
          }
          if (!data.width) return
          const indentSize = data.width + (binding.value || 0)
          console.log(indentSize);
          el.style.textIndent = `${indentSize}px`
        }, 0);
      }
    }
  }
}
</script>

<style lang="less" scoped>
@import '~@/assets/css/mixins.less';
@PaddingSize: 11px;
.data-list-item {
  padding: @PaddingSize 0;
  border-bottom: 1px solid rgba(0, 0, 0, 0.1);

  .item-title {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    line-height: 25px;
    position: relative;

    .title-tag {
      position: absolute;
      left: 0;
      top: 0;
      bottom: 0;
        
      //   margin-right: 10px;
    }
    .title-content {
      font-size: 16px;
      color: #222222;
      line-height: 25px;
      .line-clamp(2);
    }
  }
  .item-bottom {
    padding-top: 10px;
    display: flex;
    justify-content: space-between;

    .bottom-content {
      display: flex;
      align-items: center;
      color: #999999;
      line-height: 16px;
      font-size: 12px;

      @IconSize: 15px;
      .bottom-icon {
        width: @IconSize;
        height: @IconSize;
        margin-right: 7px;
      }
    }
  }
}
</style>