index.vue 3.9 KB
<template>
  <div class="content-wrap">
    <!-- <el-date-picker class="rqxzDatePicker" v-model="dwqdDate" type="date" @change="changeDwqdTime" value-format="yyyy-MM-dd" placeholder="选择日期" :picker-options="pickerDwqdOptions"></el-date-picker> -->
    <el-date-picker v-model="timeData" type="daterange" size="mini" range-separator="至" start-placeholder="开始日期" end-placeholder="结束日期" value-format="yyyy-MM-dd" class="data-pick" unlink-panels></el-date-picker>

    <div :class="['content', expande ? 'expande' : 'close']" ref="content">思路:1、判断当前内容是否超过三行。此处可以给每行设置一个行高line-height,渲染完后超过三倍的行高即认为是内容超过了三行。2、展示/收起状态的切换可以通过data中的参数来绑定。3、在底部使用position:absolute来绝对定位展开该在的位置。4、根据业务需求来设定好展开和收起按钮需要呆的地方。</div>
    <div class="expande-button-wrap" v-if="needShowExpande">
      <div class="expande-button" @click="expandeClick" v-if="!expande">
        <span style="color: black">...</span>
        展开
      </div>
      <div class="expande-button" @click="expandeClick" v-else>收起</div>
    </div>
  </div>
</template>

<script>
export default {
  name: 'App',
  data() {
    return {
      expande: false,
      needShowExpande: true,
      timeData: []
    }
  },
  created() {
    // let date = new Date()
    // let y = date.getFullYear()
    // let m = date.getMonth() + 1
    // m = m < 10 ? '0' + m : m
    // let d = date.getDate()
    // d = d < 10 ? '0' + d : d
    // const time = y + '-' + m + '-' + d
    // this.dwqdDate = time
  },
  methods: {
    expandeClick() {
      
      this.expande = !this.expande
    },

    /* 获取过去时间,并传值给现在时间 */
    getPassYearFormatDate() {
      var nowDate = new Date()
      var date = new Date(nowDate)
      date.setDate(date.getDate() - 30)
      var seperator1 = '-'
      var year = date.getFullYear()
      var month = date.getMonth() + 1
      var strDate = date.getDate()
      if (month >= 1 && month <= 9) {
        month = '0' + month
      }
      if (strDate >= 0 && strDate <= 9) {
        strDate = '0' + strDate
      }
      var formatDate = year + seperator1 + month + seperator1 + strDate
      this.getNowFormatDate(formatDate)
    },
    /* 获取现在时间,并接受过去时间的值 */
    getNowFormatDate(formatDate) {
      var date = new Date()
      var seperator1 = '-'
      var year = date.getFullYear()
      var month = date.getMonth() + 1
      var strDate = date.getDate()
      if (month >= 1 && month <= 9) {
        month = '0' + month
      }
      if (strDate >= 0 && strDate <= 9) {
        strDate = '0' + strDate
      }
      var nowData = year + seperator1 + month + seperator1 + strDate
      this.timeData = [formatDate, nowData] // 默认赋值一年时间
    }
  },
  mounted() {
    this.getPassYearFormatDate()
    this.$nextTick(() => {
      let lineHeight = 22
      if (this.$refs.content.offsetHeight > lineHeight * 3) {
        this.expande = false
        this.needShowExpande = true
      } else {
        this.expande = true
      }
    })
  }
}
</script>

<style>
.content-wrap {
  width: 300px;
  height: 200px;
  position: relative;
}
.content {
  font-size: 14px;
  color: black;
  letter-spacing: 0;
  line-height: 22px;
  text-align: justify;
  overflow: hidden;
  /* display: -webkit-box; */
  /* -webkit-line-clamp: 3;
    -webkit-box-orient: vertical; */
  /* text-overflow: ellipsis; */
}

.expande {
  overflow: auto;
  height: auto;
  padding-bottom: 22px;
}

.close {
  overflow: hidden;
  height: 66px;
  padding-bottom: 0;
}

.expande-button-wrap {
  position: absolute;
  bottom: 0;
  right: 0;
  height: 22px;
  background: white;
}

.expande-button {
  text-align: right;
  vertical-align: middle;
  color: #5995ef;
  font-size: 14px;
  line-height: 22px;
}
</style>