|
1 | 1 | <template> |
2 | | - <tiny-carousel height="300px" arrow="always" indicator-position="outside"> |
| 2 | + <tiny-carousel arrow="never" height="300px" indicator-position="none" ref="carouselRef" :initial-index="index - 1"> |
| 3 | + <div class="btn-layout"> |
| 4 | + <div> |
| 5 | + <tiny-button type="text" @click="prev" :disabled="disabledLeft" :icon="TinyIconChevronLeft"> </tiny-button> |
| 6 | + </div> |
| 7 | + <div> |
| 8 | + <tiny-button type="text" @click="next" :disabled="disabledRight" :icon="TinyIconChevronRight"></tiny-button> |
| 9 | + </div> |
| 10 | + </div> |
3 | 11 | <tiny-carousel-item class="carousel-item-demo" v-for="(item, pos) in state.cardData" :key="item"> |
4 | 12 | <template #default> |
5 | | - <div v-for="num in state.cardData.length" :key="num"> |
| 13 | + <div class="card-layout" v-for="num in state.cardData.length" :key="num"> |
6 | 14 | <div v-if="num === pos + 1" :class="['card-dsp']"> |
7 | 15 | <tiny-card |
8 | 16 | v-for="(child, childIndex) in item.children" |
|
23 | 31 | </template> |
24 | 32 |
|
25 | 33 | <script setup> |
26 | | -import { ref, reactive } from 'vue' |
27 | | -import { Carousel as TinyCarousel, CarouselItem as TinyCarouselItem, Card as TinyCard } from '@opentiny/vue' |
| 34 | +import { ref, reactive, onMounted } from 'vue' |
| 35 | +import { |
| 36 | + Carousel as TinyCarousel, |
| 37 | + CarouselItem as TinyCarouselItem, |
| 38 | + Card as TinyCard, |
| 39 | + Button as TinyButton |
| 40 | +} from '@opentiny/vue' |
| 41 | +import { IconChevronRight, IconChevronLeft } from '@opentiny/vue-icon' |
| 42 | +
|
| 43 | +const TinyIconChevronRight = IconChevronRight() |
| 44 | +const TinyIconChevronLeft = IconChevronLeft() |
28 | 45 |
|
29 | 46 | let curIndex = ref(0) |
| 47 | +const index = ref(1) |
| 48 | +let disabledLeft = ref(false) |
| 49 | +let disabledRight = ref(false) |
| 50 | +const carouselRef = ref() |
30 | 51 | const dsj = ref(`${import.meta.env.VITE_APP_BUILD_BASE_URL}static/images/dsj.png`) |
31 | 52 | const userHead = ref(`${import.meta.env.VITE_APP_BUILD_BASE_URL}static/images/user-head.png`) |
32 | 53 | const state = reactive({ |
@@ -78,25 +99,99 @@ const state = reactive({ |
78 | 99 | cardType: 'logo', |
79 | 100 | cardSrc: `${userHead.value}`, |
80 | 101 | content: '1-3-content' |
| 102 | + }, |
| 103 | + { |
| 104 | + cardTitle: '2-4', |
| 105 | + cardType: 'logo', |
| 106 | + cardSrc: `${userHead.value}`, |
| 107 | + content: '2-4-content' |
81 | 108 | } |
82 | 109 | ] |
83 | 110 | } |
84 | 111 | ] |
85 | 112 | }) |
| 113 | +
|
| 114 | +onMounted(() => { |
| 115 | + disableStatus() |
| 116 | +}) |
| 117 | +
|
| 118 | +const next = () => { |
| 119 | + index.value = Math.min(index.value + 1, 8) |
| 120 | + carouselRef.value.next() |
| 121 | + disableStatus() |
| 122 | +} |
| 123 | +
|
| 124 | +const prev = () => { |
| 125 | + index.value = Math.max(index.value - 1, 0) |
| 126 | + carouselRef.value.prev() |
| 127 | + disableStatus() |
| 128 | +} |
| 129 | +
|
| 130 | +const disableStatus = () => { |
| 131 | + disabledRight.value = false |
| 132 | + disabledLeft.value = false |
| 133 | + if (index.value === 1) { |
| 134 | + disabledLeft.value = true |
| 135 | + disabledRight.value = false |
| 136 | + } |
| 137 | + if (index.value === state.cardData.length) { |
| 138 | + disabledRight.value = true |
| 139 | + disabledLeft.value = false |
| 140 | + } |
| 141 | +} |
86 | 142 | </script> |
87 | 143 |
|
88 | | -<style scoped> |
| 144 | +<style lang="less" scoped> |
| 145 | +.carousel-item-demo { |
| 146 | + display: flex; |
| 147 | + justify-content: center; |
| 148 | +} |
89 | 149 | .card-dsp { |
90 | 150 | display: flex; |
91 | 151 | justify-content: flex-start; |
92 | | - padding: 0 4px 0 12px; |
| 152 | + align-items: center; |
| 153 | + height: 100%; |
93 | 154 | } |
94 | 155 | .mb { |
95 | 156 | margin-bottom: 20px; |
96 | 157 | } |
97 | 158 | .card-demo { |
98 | 159 | width: 25%; |
99 | | - height: 300px; |
100 | 160 | margin-right: 8px; |
| 161 | + height: 200px; |
| 162 | + &:last-child { |
| 163 | + margin-right: 0; |
| 164 | + } |
| 165 | + &:hover { |
| 166 | + border-color: #1476ff; |
| 167 | + } |
| 168 | +} |
| 169 | +.btn-layout { |
| 170 | + position: relative; |
| 171 | + display: flex; |
| 172 | + justify-content: space-between; |
| 173 | + top: 45%; |
| 174 | + z-index: 10; |
| 175 | + padding: 0 76px; |
| 176 | +} |
| 177 | +/deep/ .tiny-button.tiny-button--text.tiny-button.is-only-icon { |
| 178 | + font-size: 16px; |
| 179 | + border: none; |
| 180 | + .tiny-svg { |
| 181 | + fill: #808080; |
| 182 | + } |
| 183 | + &.is-disabled { |
| 184 | + .tiny-svg { |
| 185 | + fill: #c2c2c2; |
| 186 | + } |
| 187 | + } |
| 188 | + &:hover { |
| 189 | + background-color: transparent; |
| 190 | + } |
| 191 | + &:not(.is-disabled) { |
| 192 | + .tiny-svg:hover { |
| 193 | + fill: #191919; |
| 194 | + } |
| 195 | + } |
101 | 196 | } |
102 | 197 | </style> |
0 commit comments