EquipmentPage.vue 3.34 KB
Newer Older
hucy's avatar
hucy committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
<script setup lang="ts">
import { watch, ref } from 'vue';

interface Props {
  list: any[];
  autoplay: number;
}

const props = withDefaults(defineProps<Props>(), {
  list: () => [],
  autoplay: 10000,
});

const slide = ref('1');

watch(
  () => props.list,
hucy's avatar
hucy committed
18 19
  (newVal, oldVal) => {
    listChange(newVal, oldVal);
hucy's avatar
hucy committed
20 21 22
  }
);

hucy's avatar
hucy committed
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38
function listChange(newVal: any, oldVal: any) {
  console.log('newVal', newVal.length, 'oldVal', oldVal.length);
  if (oldVal.length < newVal.length && oldVal.length === 1) {
    setTimeout(() => {
      slide.value = '2';
    }, props.autoplay);
  }
  if (newVal.length < Number(slide.value)) {
    slide.value = '1';
  }
}

function clickPoint(value: string) {
  if (value !== slide.value) {
    slide.value = value;
  }
hucy's avatar
hucy committed
39 40 41 42
}
</script>
<template>
  <div class="my-carousel-box">
hucy's avatar
hucy committed
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67
    <template v-if="props.list.length > 0">
      <div class="content">
        <q-carousel
          v-model="slide"
          transition-prev="slide-right"
          transition-next="slide-left"
          animated
          infinite
          :keep-alive="false"
          :autoplay="props.autoplay"
          class="my-carousel"
        >
          <q-carousel-slide
            :name="String(index + 1)"
            class="my-carousel-slide"
            v-for="(item, index) in props.list"
            :key="index"
          >
            <div class="item-carousel-content">
              <div class="item" v-for="(ele, el_index) in item" :key="el_index">
                <div class="pic"></div>
                <div class="item-name" :style="{ backgroundColor: ele.color }">
                  {{ ele.code }}
                </div>
              </div>
hucy's avatar
hucy committed
68
            </div>
hucy's avatar
hucy committed
69 70 71 72 73 74 75 76 77 78 79 80 81
          </q-carousel-slide>
        </q-carousel>
      </div>
      <div class="points">
        <div
          class="cursor-pointer"
          :class="{ active: slide === String(index + 1) }"
          v-for="(i, index) in props.list"
          :key="index"
          @click="clickPoint(String(index + 1))"
        ></div>
      </div>
    </template>
hucy's avatar
hucy committed
82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102
  </div>
</template>

<style lang="scss" scoped>
.my-carousel-box {
  width: 100%;
  height: 100%;

  display: flex;
  flex-flow: column nowrap;
}
.content {
  flex: 1;
}
.my-carousel {
  height: 100% !important;
  background-color: transparent;
}
.my-carousel-slide {
  padding: 0 !important;
}
hucy's avatar
hucy committed
103
.item-carousel-content {
hucy's avatar
hucy committed
104 105 106 107 108 109 110 111
  width: 100%;
  height: 100%;
  overflow: hidden;

  // 5列 * 2行
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  grid-template-rows: repeat(2, 1fr);
hucy's avatar
hucy committed
112 113 114
  // grid-template-columns: repeat(2, 1fr);
  // grid-template-rows: repeat(2, 1fr);
  grid-gap: 5px 5px;
hucy's avatar
hucy committed
115
}
hucy's avatar
hucy committed
116
.item {
hucy's avatar
hucy committed
117 118 119 120 121 122 123 124 125 126 127 128 129 130 131
  display: flex;
  flex-flow: column nowrap;
  .pic {
    width: 100%;
    background-image: url('https://img0.baidu.com/it/u=925843206,3288141497&fm=253&app=138&size=w931&n=0&f=JPEG&fmt=auto?sec=1666803600&t=81f620f962ec6a70673c05d6a55328b5');
    background-size: 100% 100%;
    flex: 1;
  }
  .item-name {
    height: 30px;
    display: flex;
    justify-content: center;
    align-items: center;
  }
}
hucy's avatar
hucy committed
132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151
.points {
  padding: 5px;
  display: flex;
  flex-flow: row wrap;
  justify-content: center;
  align-items: center;
}
// 小圆点
.cursor-pointer {
  height: 4px;
  width: 40px;
  margin-right: 5px;
  border-radius: 50px;
  background-color: rgba($color: #3ecdff, $alpha: 0.3);
  cursor: pointer;
  transition: all 0.5s;
}
.active {
  background-color: #3ecdff;
}
hucy's avatar
hucy committed
152
</style>