Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: 扩展轮播图组件支持视频和左右滑动 #11528

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
136 changes: 108 additions & 28 deletions packages/amis-editor/src/plugin/Carousel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,9 @@ export class CarouselPlugin extends BasePlugin {
html: '<div style="width: 100%; height: 300px; background: #e3e3e3; text-align: center; line-height: 300px;">carousel data</div>'
},
{
image: mockValue({type: 'image'})
type: 'video',
src: 'https://media.w3.org/2010/05/sintel/trailer_hd.mp4',
poster: mockValue({type: 'image'})
}
]
};
Expand Down Expand Up @@ -152,6 +154,49 @@ export class CarouselPlugin extends BasePlugin {
type: 'html',
content: '<p>html 片段</p>'
}
},
{
label: '视频',
test: 'this.type === "video"',
items: [
{
name: 'src',
type: 'input-text',
label: '视频地址',
description:
'可以写静态值,也可以用变量取比如:<code>\\${videoSrc}</code>'
},
{
name: 'poster',
type: 'input-text',
label: '视频封面图片地址',
description:
'可以写静态值,也可以用变量取比如:<code>\\${videoPoster}</code>'
},
getSchemaTpl('switch', {
name: 'autoPlay',
label: '自动播放'
}),
getSchemaTpl('switch', {
name: 'muted',
label: '静音'
}),
getSchemaTpl('switch', {
name: 'isLive',
label: '直播流',
labelRemark: {
trigger: 'click',
rootClose: true,
content:
'如果是直播流,请勾选,否则有可能不能正常播放。'
}
})
],
scaffold: {
type: 'video',
src: 'https://media.w3.org/2010/05/sintel/trailer_hd.mp4',
poster: mockValue({type: 'image'})
}
}
],
pipeIn: (value: any) => {
Expand All @@ -165,24 +210,43 @@ export class CarouselPlugin extends BasePlugin {
titleClassName?: string;
description?: string;
descriptionClassName?: string;
}) =>
item && item.hasOwnProperty('html')
? {
type: 'html',
content: item.html
}
: {
type: 'image',
content: item.image,
title: item.title,
href: item.href,
titleClassName: item.titleClassName,
description: item.description,
descriptionClassName: item.descriptionClassName
}
type?: string;
src?: string;
poster?: string;
autoPlay?: boolean;
muted?: boolean;
isLive?: boolean;
}) => {
if (item && item.hasOwnProperty('html')) {
return {
type: 'html',
content: item.html
};
} else if (item && item.type === 'video') {
return {
type: 'video',
src: item.src,
poster: item.poster,
autoPlay: item.autoPlay,
muted: item.muted,
isLive: item.isLive
};
} else {
return {
type: 'image',
content: item.image,
title: item.title,
href: item.href,
titleClassName: item.titleClassName,
description: item.description,
descriptionClassName: item.descriptionClassName
};
}
}
)
: [];
},

pipeOut: (value: any, originValue: any, data: any) => {
return Array.isArray(value) && value.length
? value.map(
Expand All @@ -194,19 +258,35 @@ export class CarouselPlugin extends BasePlugin {
titleClassName?: string;
description?: string;
descriptionClassName?: string;
src?: string;
poster?: string;
autoPlay?: boolean;
muted?: boolean;
isLive?: boolean;
}) => {
return item.type === 'html'
? {
html: item.content
}
: {
image: item.content,
href: item.href,
title: item.title,
titleClassName: item.titleClassName,
description: item.description,
descriptionClassName: item.descriptionClassName
};
if (item.type === 'html') {
return {
html: item.content
};
} else if (item.type === 'video') {
return {
type: 'video',
src: item.src,
poster: item.poster,
autoPlay: item.autoPlay,
muted: item.muted,
isLive: item.isLive
};
} else {
return {
image: item.content,
href: item.href,
title: item.title,
titleClassName: item.titleClassName,
description: item.description,
descriptionClassName: item.descriptionClassName
};
}
}
)
: [];
Expand Down
90 changes: 81 additions & 9 deletions packages/amis-ui/scss/components/_carousel.scss
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
position: relative;
display: block;
background: var(--Carousel-bg);
user-select: none;

&.#{$ns}Carousel--light {
.#{$ns}Carousel-dot {
Expand Down Expand Up @@ -63,6 +64,8 @@
width: 100%;
height: 100%;
overflow: hidden;
touch-action: pan-y pinch-zoom;
user-select: none;

.#{$ns}Carousel-item {
width: 100%;
Expand Down Expand Up @@ -127,6 +130,62 @@
height: 100%;
background-size: cover;
}

.#{$ns}Video {
height: 100%;
position: relative;
z-index: 2;

.#{$ns}Video-player {
height: 100%;

.video-react {
height: 100% !important;
padding-top: 0 !important;
background-color: var(--Carousel-bg) !important;

.video-react-control-bar {
z-index: 4;
pointer-events: auto;
touch-action: auto !important;

* {
pointer-events: auto;
touch-action: auto !important;
}

.video-react-progress-control,
.video-react-volume-menu-button {
pointer-events: auto;
touch-action: auto !important;

.video-react-slider,
.video-react-menu,
.video-react-volume-bar {
pointer-events: auto;
touch-action: auto !important;
}
}
}

.video-react-poster {
background-color: var(--Carousel-bg) !important;
}

.video-react-video {
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
width: 100%;
height: 100%;
object-fit: contain;
pointer-events: auto;
touch-action: auto !important;
}
}
}
}
}
}

Expand All @@ -144,8 +203,9 @@
position: absolute;
bottom: 0px;
width: 100%;
z-index: 100;
z-index: 3;
text-align: center;
pointer-events: none;

.#{$ns}Carousel-dot {
cursor: pointer;
Expand All @@ -156,13 +216,24 @@
margin: var(--Carousel-dot-margin);
transition-duration: var(--Carousel-transitionDuration);
opacity: 0.3;
pointer-events: auto;

&.is-active {
opacity: 1;
}
}
}

.#{$ns}Carousel-leftArrow,
.#{$ns}Carousel-rightArrow {
z-index: 3;
pointer-events: none;

.icon {
pointer-events: auto;
}
}

.#{$ns}Carousel-leftArrow {
@include arrow-control;
display: none;
Expand Down Expand Up @@ -215,8 +286,9 @@
top: 0;
justify-content: center;
}

&-leftArrow, &-rightArrow {

&-leftArrow,
&-rightArrow {
height: 10%;
width: 100%;
left: 0;
Expand All @@ -238,27 +310,27 @@
transform: translate(-50%, -50%) rotate(90deg);
}
}

&-item.slide {
transform: translateY(100%);
}

&-item.slide.in {
transform: translateY(0);
}

&-item.slide.out {
transform: translateY(-100%);
}

&-item.slideRight {
transform: translateY(-100%);
}

&-item.slideRight.in {
transform: translateY(0);
}

&-item.slideRight.out {
transform: translateY(100%);
}
Expand Down
Loading