<template>
  <view :style="{ color }">
    <view
      style="
        font-size: 26rpx;
        line-height: 160%;
        position: relative;
        transform: 0.2s all;
        color: inherit;
        white-space: normal;
      "
      v-if="value.length < splitLength"
    >
      {{ value }}
    </view>
    <view
      v-else
      style="
        font-size: 26rpx;
        line-height: 160%;
        position: relative;
        transform: 0.2s all;
        color: inherit;
        white-space: normal;
      "
      @tap="isShowAllText = !isShowAllText"
    >
      {{ isShowAllText ? value : `${value.slice(1, splitLength)}...` }}
      <text style="color: #17c653; padding-left: 4px">
        {{ isShowAllText ? '收起' : '展开' }}
      </text>
    </view>
  </view>
</template>

<script>
export default {
  name: 'cs-text-more',
  data() {
    return {
      isShowAllText: false
    }
  },
  props: {
    value: {
      type: String,
      default: '文本简介'.repeat(20)
    },
    color: {
      type: String
    },
    splitLength: {
      type: Number,
      default: 100
    }
  }
}
</script>

<style lang="scss"></style>