catalogue.vue 5.56 KB
<!--
 * @Description: 
 * @Date: 2021-06-09 19:05:20
-->
<template>
  <div class="bi-catalogue" ref="bi-catalogue">
    <div class="bi-catalogue-title">
      <div class="bi-catalogue-title_cn_name">目录</div>
      <div class="bi-catalogue-title_en_name">Contents</div>
      <div class="bi-catalogue-title_hr"></div>
    </div>
    <div class="bi-catalogue_list">
      <div
        class="bi-catalogue_list_item"
        v-for="({ name, child }, index) in catalogueArr"
        :key="index"
      >
        <div class="bi-catalogue_list_item_name">
          <span style="margin-right:20px;">
            {{ `${index + 1}`.padStart(2, 0) }}
          </span>
          {{ name }}
        </div>
        <div class="bi-catalogue_list_item_hr"></div>
        <div class="bi-catalogue_list_item_child">
          <div
            class="bi-catalogue_list_item_child_item"
            v-for="({ name, page }, cIndex) in child"
            :key="cIndex"
          >
            <div>
              <p class="bi-catalogue_list_item_child_item_name">
                <span>{{ `${index + 1}.${cIndex + 1}  ` }}{{ name }}</span>
              </p>
              <div class="bi-catalogue_list_item_child_item_hr"></div>
              <span class="bi-catalogue_list_item_child_item_page">
                {{ `${+page + cataloguePageSize}`.padStart(2, 0) }}
              </span>
            </div>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import { heightToPage } from '../chart-type/common';
import mixin from '../mixin/index';
export default {
  name: 'bi-catalogue',
  mixins: [mixin],
  props: {
    catalogueArr: {
      type: Array,
      default: () => []
    }
  },
  data() {
    return {
      cataloguePageSize: 0
    };
  },
  computed: {
    // cataloguePageSize() {
    //   const catalogueCount =
    //     5 +
    //     this.catalogueArr.slice(2).reduce((pre, cur) => {
    //       pre.push(...cur.child);
    //       return pre;
    //     }, []).length -
    //     10;
    //   const cataloguePageSize = 1 + Math.ceil(catalogueCount / 17);
    //   return cataloguePageSize;
    // }
  },
  created() {},
  watch: {
    catalogueArr: {
      handler() {
        this.$nextTick(() => {
          this.cataloguePageSize = heightToPage(
            this.$refs['bi-catalogue'].offsetHeight
          );
        });
      },
      immediate: true,
      deep: true
    }
  }
};
</script>

<style lang="scss" scoped>
.bi-catalogue {
  $color: #2a3558;
  $colorNormal: #6f7a91;
  padding: 0 50px;
  box-sizing: border-box;
  color: $color;
  &-title {
    padding-top: 44px;
    &_cn_name {
      font-size: 55px;
      line-height: 1.5;
    }
    &_en_name {
      font-size: 28px;
      line-height: 45px;
      padding-left: 10px;
    }
    &_hr {
      width: 1090px;
      height: 3px;
      background: $color;
      margin-top: 17px;
    }
  }
  &_list {
    margin-top: 133px;
    &_item {
      & + .bi-catalogue_list_item {
        padding-top: 65px;
      }
      &_name {
        font-size: 25px;
      }
      &_hr {
        width: 1090px;
        height: 2px;
        background: $color;
        margin-top: 17px;
      }
      &_child {
        padding-top: 30px;
        &_item {
          padding: 30px 0;
          font-size: 21px;
          page-break-inside: avoid;
          & > div {
            position: relative;
          }
          &_hr {
            width: 1096px;
            position: absolute;
            top: 50%;
            z-index: 1;
            &::after {
              content: '';
              display: block;
              width: 1096px;
              height: 0;
              border-top: 1px dashed #707070;
            }
          }

          &_name {
            line-height: 30px;
            max-width: 950px;
            position: relative;
            z-index: 2;
            span {
              background: #fff;
              padding-right: 20px;
              position: relative;
              z-index: 2;
              display: inline-block;
            }
          }
          &_page {
            line-height: 30px;
            padding-left: 10px;
            background: #fff;
            position: absolute;
            right: 0;
            top: 50%;
            z-index: 2;
            margin-top: -15px;
          }
        }
      }
      &:last-child {
        .bi-catalogue_list_item_child {
          &_item:last-child {
            padding-bottom: 77px;
          }
        }
      }
    }
  }
}
.mobile {
  padding: 0.59rem 0.43rem;
  .bi-catalogue-title {
    &_cn_name {
      font-size: 0.44rem;
    }
    &_en_name {
      font-size: 0.27rem;
      line-height: 0.36rem;
      padding-left: 0;
    }
    &_hr {
      width: 9.09rem;
      height: 0.03rem;
      margin-top: 0.15rem;
    }
  }
  .bi-catalogue_list {
    margin-top: 0.95rem;
    &_item {
      padding-top: 0.3rem;
      &_name {
        font-size: 0.35rem;
        span {
          margin-right: 0.1rem !important;
        }
      }
      &_hr {
        width: 9.09rem;
        height: 0.03rem;
        margin-top: 0.11rem;
      }
      &_child {
        padding-top: 0.35rem;
        &_item {
          padding: 0.3rem 0;
          overflow: hidden;
          &_name {
            top: 0.3rem;
            font-size: 0.32rem;
            padding-right: 0.2rem;
            max-width: 8rem;
          }
          &_hr {
            width: 9.09rem;
          }
          &_page {
            top: 0.3rem;
            font-size: 0.32rem;
            padding-left: 0.2rem;
          }
        }
      }
      & + .bi-catalogue_list_item {
        margin-top: 0.59rem;
      }
    }
  }
}
</style>