Skip to content

Commit 4253173

Browse files
committed
营销:适配商城装修组件【轮播图】
1 parent 6e9e1d0 commit 4253173

File tree

5 files changed

+182
-185
lines changed

5 files changed

+182
-185
lines changed
Lines changed: 32 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,30 @@
1-
import { DiyComponent } from '@/components/DiyEditor/util'
1+
import { ComponentStyle, DiyComponent } from '@/components/DiyEditor/util'
22

33
/** 轮播图属性 */
44
export interface CarouselProperty {
5-
// 选择模板
6-
swiperType: number
7-
// 图片圆角
8-
borderRadius: number
9-
// 页面边距
10-
pageMargin: number
11-
// 图片边距
12-
imageMargin: number
13-
// 分页类型
14-
pagingType: 'bullets' | 'fraction' | 'progressbar'
15-
// 一行个数
16-
rowIndividual: number
17-
// 添加图片
5+
// 类型:默认 | 卡片
6+
type: 'default' | 'card'
7+
// 指示器样式:点 | 数字
8+
indicator: 'dot' | 'number'
9+
// 是否自动播放
10+
autoplay: boolean
11+
// 播放间隔
12+
interval: number
13+
// 轮播内容
1814
items: CarouselItemProperty[]
15+
// 组件样式
16+
style: ComponentStyle
1917
}
20-
18+
// 轮播内容属性
2119
export interface CarouselItemProperty {
22-
title: string
20+
// 类型:图片 | 视频
21+
type: 'img' | 'video'
22+
// 图片链接
2323
imgUrl: string
24-
link: string
24+
// 视频链接
25+
videoUrl: string
26+
// 跳转链接
27+
url: string
2528
}
2629

2730
// 定义组件
@@ -30,15 +33,18 @@ export const component = {
3033
name: '轮播图',
3134
icon: 'system-uicons:carousel',
3235
property: {
33-
swiperType: 0, // 选择模板
34-
borderRadius: 0, // 图片圆角
35-
pageMargin: 0, // 页面边距
36-
imageMargin: 0, // 图片边距
37-
pagingType: 'bullets', // 分页类型
38-
rowIndividual: 2, // 一行个数
36+
type: 'default',
37+
indicator: 'dot',
38+
autoplay: false,
39+
interval: 3,
3940
items: [
40-
{ imgUrl: 'https://static.iocoder.cn/mall/banner-01.jpg' },
41-
{ imgUrl: 'https://static.iocoder.cn/mall/banner-02.jpg' }
42-
] as CarouselItemProperty[]
41+
{ type: 'img', imgUrl: 'https://static.iocoder.cn/mall/banner-01.jpg', videoUrl: '' },
42+
{ type: 'img', imgUrl: 'https://static.iocoder.cn/mall/banner-02.jpg', videoUrl: '' }
43+
] as CarouselItemProperty[],
44+
style: {
45+
bgType: 'color',
46+
bgColor: '#fff',
47+
marginBottom: 8
48+
} as ComponentStyle
4349
}
4450
} as DiyComponent<CarouselProperty>

src/components/DiyEditor/components/mobile/Carousel/index.vue

Lines changed: 27 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -6,70 +6,38 @@
66
>
77
<Icon icon="tdesign:image" class="text-gray-8 text-120px!" />
88
</div>
9-
<!-- 一行一个 -->
10-
<div
11-
v-if="property.swiperType === 0"
12-
class="flex flex-col"
13-
:style="{
14-
paddingLeft: property.pageMargin + 'px',
15-
paddingRight: property.pageMargin + 'px'
16-
}"
17-
>
18-
<div v-for="(item, index) in property.items" :key="index">
19-
<div
20-
class="img-item"
21-
:style="{
22-
marginBottom: property.imageMargin + 'px',
23-
borderRadius: property.borderRadius + 'px'
24-
}"
25-
>
26-
<img alt="" :src="item.imgUrl" />
27-
<div v-if="item.title" class="title">{{ item.title }}</div>
28-
</div>
29-
</div>
9+
<div v-else class="relative">
10+
<el-carousel
11+
height="174px"
12+
:type="property.type === 'card' ? 'card' : ''"
13+
:autoplay="property.autoplay"
14+
:interval="property.interval * 1000"
15+
:indicator-position="property.indicator === 'number' ? 'none' : undefined"
16+
@change="handleIndexChange"
17+
>
18+
<el-carousel-item v-for="(item, index) in property.items" :key="index">
19+
<el-image class="h-full w-full" :src="item.imgUrl" />
20+
</el-carousel-item>
21+
</el-carousel>
22+
<div
23+
v-if="property.indicator === 'number'"
24+
class="absolute p-y-2px bottom-10px right-10px rounded-xl bg-black p-x-8px text-10px text-white opacity-40"
25+
>{{ currentIndex }} / {{ property.items.length }}</div
26+
>
3027
</div>
31-
<el-carousel height="174px" v-else :type="property.swiperType === 3 ? 'card' : ''">
32-
<el-carousel-item v-for="(item, index) in property.items" :key="index">
33-
<div class="img-item" :style="{ borderRadius: property.borderRadius + 'px' }">
34-
<img alt="" :src="item.imgUrl" />
35-
<div v-if="item.title" class="title">{{ item.title }}</div>
36-
</div>
37-
</el-carousel-item>
38-
</el-carousel>
3928
</template>
4029
<script setup lang="ts">
4130
import { CarouselProperty } from './config'
4231
43-
/** 页面顶部导航栏 */
44-
defineOptions({ name: 'NavigationBar' })
32+
/** 轮播图 */
33+
defineOptions({ name: 'Carousel' })
4534
46-
const props = defineProps<{ property: CarouselProperty }>()
47-
</script>
35+
defineProps<{ property: CarouselProperty }>()
4836
49-
<style scoped lang="scss">
50-
.img-item {
51-
width: 100%;
52-
position: relative;
53-
overflow: hidden;
54-
&:last-child {
55-
margin: 0 !important;
56-
}
57-
/* 图片 */
58-
img {
59-
width: 100%;
60-
height: 100%;
61-
display: block;
62-
}
63-
.title {
64-
height: 36px;
65-
width: 100%;
66-
background-color: rgba(51, 51, 51, 0.8);
67-
text-align: center;
68-
line-height: 36px;
69-
color: #fff;
70-
position: absolute;
71-
bottom: 0;
72-
left: 0;
73-
}
37+
const currentIndex = ref(0)
38+
const handleIndexChange = (index: number) => {
39+
currentIndex.value = index + 1
7440
}
75-
</style>
41+
</script>
42+
43+
<style scoped lang="scss"></style>

0 commit comments

Comments
 (0)