123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153 |
- <template>
- <ComponentsHeader v-bind="$props" />
- <view class="banner" :style="{ padding: `0 ${gap}px` }">
- <!-- 单图模式 -->
- <view v-if="mode === 'single'" class="single-image">
- <image :src="images[0]?.image || `http://iph.href.lu/400x200?text=1`" :style="{ borderRadius: `${radius}px` }" mode="aspectFill" @click="_handleClick(images[0].urlMap?.internal_url)" />
- </view>
- <!-- 轮播图模式 -->
- <swiper
- v-else-if="mode === 'swiper' || mode === 'swiper-no-dots'"
- :autoplay="true"
- :interval="swiperDuration"
- :circular="true"
- :indicator-dots="mode === 'swiper'"
- class="swiper"
- :style="{ borderRadius: `${radius}px` }"
- >
- <swiper-item v-for="(item, index) in images" :key="index">
- <image @click="_handleClick(item.urlMap?.internal_url)" :src="item.image || `http://iph.href.lu/400x200?text=${index}`" :style="{ borderRadius: `${radius}px` }" mode="aspectFill" />
- </swiper-item>
- </swiper>
- <!-- 网格模式 -->
- <view v-else-if="mode === 'grid'" class="grid-container" :style="{ borderRadius: `${radius}px` }">
- <view v-for="(item, index) in images.slice(0, 4)" :key="index" class="grid-item">
- <image @click="_handleClick(item.urlMap?.internal_url)" :src="item.image || `http://iph.href.lu/400x200?text=${index}`" :style="{ borderRadius: `${radius}px` }" />
- </view>
- </view>
- <!-- 双图模式 -->
- <view v-else-if="mode === 'double'" class="double-container" :style="{ borderRadius: `${radius}px` }">
- <view v-for="(item, index) in images.slice(0, 2)" :key="index" class="double-item">
- <image @click="_handleClick(item.urlMap?.internal_url)" :src="item.image || `http://iph.href.lu/400x200?text=${index}`" :style="{ borderRadius: `${radius}px` }" mode="aspectFill" />
- </view>
- </view>
- </view>
- </template>
- <script setup>
- import ComponentsHeader from '../ComponentsHeader';
- defineProps({
- images: {
- type: Array,
- default: () => [],
- },
- mode: {
- type: String,
- default: 'single',
- validator: (value) => ['single', 'swiper', 'swiper-no-dots', 'grid', 'double'].includes(value),
- },
- radius: {
- type: Number,
- default: 0,
- },
- swiperDuration: {
- type: Number,
- default: 3000,
- },
- gap: {
- type: Number,
- default: 0,
- },
- title: {
- type: String,
- default: '',
- },
- showTitle: {
- type: Boolean,
- default: false,
- },
- });
- const _handleClick = (url) => {
- if (url) {
- uni.navigateTo({
- url,
- fail: (err) => {
- uni.switchTab({
- url,
- });
- },
- });
- }
- };
- </script>
- <style lang="less" scoped>
- .navigator {
- width: 100%;
- height: 100%;
- }
- .banner {
- width: 100%;
- overflow: hidden;
- box-sizing: border-box;
- .single-image {
- width: 100%;
- height: 150px;
- overflow: hidden;
- image {
- width: 100%;
- height: 100%;
- }
- }
- .swiper {
- width: 100%;
- height: 150px;
- image {
- width: 100%;
- height: 100%;
- }
- }
- .grid-container {
- display: grid;
- grid-template-rows: repeat(2, 1fr);
- grid-template-columns: repeat(2, 1fr);
- gap: 4px;
- width: 100%;
- .grid-item {
- height: 100px;
- image {
- width: 100%;
- height: 100%;
- }
- }
- }
- .double-container {
- display: flex;
- gap: 4px;
- width: 100%;
- .double-item {
- flex: 1;
- height: 150px;
- image {
- width: 100%;
- height: 100%;
- }
- }
- }
- }
- </style>
|