mirror of
https://github.com/MrXujiang/h5-Dooring.git
synced 2026-01-18 11:28:12 +00:00
🆕 轮播图添加圆角
This commit is contained in:
parent
d3dd969317
commit
28a3a5e53a
@ -1,15 +1,19 @@
|
|||||||
import React, { memo } from 'react';
|
import React, { memo, PropsWithChildren } from 'react';
|
||||||
import { Carousel } from 'zarm';
|
import { Carousel } from 'zarm';
|
||||||
import styles from './index.less';
|
import styles from './index.less';
|
||||||
import { ICarouselConfig } from './schema';
|
import { ICarouselConfig } from './schema';
|
||||||
import logo from '@/assets/01-轮播.png';
|
import logo from '@/assets/01-轮播.png';
|
||||||
|
|
||||||
const XCarousel = memo((props: ICarouselConfig) => {
|
interface CarouselTypes extends ICarouselConfig {
|
||||||
const { direction, swipeable, autoPlay, isTpl, imgList } = props;
|
isTpl: boolean;
|
||||||
|
}
|
||||||
|
|
||||||
|
const XCarousel = memo((props: PropsWithChildren<CarouselTypes>) => {
|
||||||
|
const { direction, swipeable, autoPlay, isTpl, imgList, round } = props;
|
||||||
const contentRender = () => {
|
const contentRender = () => {
|
||||||
return imgList.map((item, i) => {
|
return imgList.map((item, i) => {
|
||||||
return (
|
return (
|
||||||
<div className={styles.carousel__item__pic} key={+i}>
|
<div className={styles.carousel__item__pic} key={+i} style={{ borderRadius: round + 'px' }}>
|
||||||
<a href={item.link}>
|
<a href={item.link}>
|
||||||
<img src={item.imgUrl.length > 0 ? item.imgUrl[0].url : ''} alt="" />
|
<img src={item.imgUrl.length > 0 ? item.imgUrl[0].url : ''} alt="" />
|
||||||
</a>
|
</a>
|
||||||
@ -18,38 +22,25 @@ const XCarousel = memo((props: ICarouselConfig) => {
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
return (
|
return (
|
||||||
<>
|
<div style={{ width: '100%', overflow: 'hidden' }}>
|
||||||
{isTpl ? (
|
{isTpl ? (
|
||||||
<div className={styles.carousel__item__pic}>
|
<div className={styles.carousel__item__pic}>
|
||||||
<img src={logo} alt="" />
|
<img src={logo} alt="" />
|
||||||
</div>
|
</div>
|
||||||
) : (
|
) : (
|
||||||
<div
|
<Carousel
|
||||||
style={{
|
onChange={index => {
|
||||||
overflow: 'hidden',
|
// console.log(`onChange: ${index}`);
|
||||||
position: 'absolute',
|
|
||||||
width: `${props.baseWidth}%`,
|
|
||||||
height: `${props.baseHeight}%`,
|
|
||||||
borderRadius: props.baseRadius,
|
|
||||||
transform: `translate(${props.baseLeft}px,${props.baseTop}px)
|
|
||||||
scale(${props.baseScale / 100})
|
|
||||||
rotate(${props.baseRotate}deg)`,
|
|
||||||
}}
|
}}
|
||||||
|
direction={direction}
|
||||||
|
swipeable={swipeable}
|
||||||
|
autoPlay={autoPlay}
|
||||||
|
loop
|
||||||
>
|
>
|
||||||
<Carousel
|
{contentRender()}
|
||||||
onChange={index => {
|
</Carousel>
|
||||||
// console.log(`onChange: ${index}`);
|
|
||||||
}}
|
|
||||||
direction={direction}
|
|
||||||
swipeable={swipeable}
|
|
||||||
autoPlay={autoPlay}
|
|
||||||
loop
|
|
||||||
>
|
|
||||||
{contentRender()}
|
|
||||||
</Carousel>
|
|
||||||
</div>
|
|
||||||
)}
|
)}
|
||||||
</>
|
</div>
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@ -1,27 +1,31 @@
|
|||||||
import {
|
import {
|
||||||
IDataListConfigType,
|
IDataListConfigType,
|
||||||
INumberConfigType,
|
|
||||||
IRadioConfigType,
|
IRadioConfigType,
|
||||||
ISwitchConfigType,
|
ISwitchConfigType,
|
||||||
|
INumberConfigType,
|
||||||
TDataListDefaultType,
|
TDataListDefaultType,
|
||||||
TRadioDefaultType,
|
TRadioDefaultType,
|
||||||
TSwitchDefaultType,
|
TSwitchDefaultType,
|
||||||
|
TNumberDefaultType,
|
||||||
} from '@/core/FormComponents/types';
|
} from '@/core/FormComponents/types';
|
||||||
import { baseConfig, baseDefault, ICommonBaseType } from '../../common';
|
|
||||||
|
import { serverUrl } from '@/utils/tool';
|
||||||
|
|
||||||
export type CarouselDirectionKeyType = 'down' | 'left';
|
export type CarouselDirectionKeyType = 'down' | 'left';
|
||||||
|
|
||||||
export type TCarouselEditData = Array<
|
export type TCarouselEditData = Array<
|
||||||
| INumberConfigType
|
|
||||||
| IRadioConfigType<CarouselDirectionKeyType>
|
| IRadioConfigType<CarouselDirectionKeyType>
|
||||||
| ISwitchConfigType
|
| ISwitchConfigType
|
||||||
| IDataListConfigType
|
| IDataListConfigType
|
||||||
|
| INumberConfigType
|
||||||
>;
|
>;
|
||||||
export interface ICarouselConfig extends ICommonBaseType {
|
export interface ICarouselConfig {
|
||||||
direction: TRadioDefaultType<CarouselDirectionKeyType>;
|
direction: TRadioDefaultType<CarouselDirectionKeyType>;
|
||||||
swipeable: TSwitchDefaultType;
|
swipeable: TSwitchDefaultType;
|
||||||
autoPlay: TSwitchDefaultType;
|
autoPlay: TSwitchDefaultType;
|
||||||
imgList: TDataListDefaultType;
|
imgList: TDataListDefaultType;
|
||||||
|
tplImg: string;
|
||||||
|
round: TNumberDefaultType;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface ICarouselSchema {
|
export interface ICarouselSchema {
|
||||||
@ -31,8 +35,6 @@ export interface ICarouselSchema {
|
|||||||
|
|
||||||
const Carousel: ICarouselSchema = {
|
const Carousel: ICarouselSchema = {
|
||||||
editData: [
|
editData: [
|
||||||
...baseConfig,
|
|
||||||
|
|
||||||
{
|
{
|
||||||
key: 'direction',
|
key: 'direction',
|
||||||
name: '方向',
|
name: '方向',
|
||||||
@ -53,6 +55,11 @@ const Carousel: ICarouselSchema = {
|
|||||||
name: '是否可拖拽',
|
name: '是否可拖拽',
|
||||||
type: 'Switch',
|
type: 'Switch',
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
key: 'round',
|
||||||
|
name: '圆角',
|
||||||
|
type: 'Number',
|
||||||
|
},
|
||||||
{
|
{
|
||||||
key: 'autoPlay',
|
key: 'autoPlay',
|
||||||
name: '是否自动播放',
|
name: '是否自动播放',
|
||||||
@ -67,6 +74,7 @@ const Carousel: ICarouselSchema = {
|
|||||||
config: {
|
config: {
|
||||||
direction: 'left',
|
direction: 'left',
|
||||||
swipeable: false,
|
swipeable: false,
|
||||||
|
round: 0,
|
||||||
autoPlay: false,
|
autoPlay: false,
|
||||||
imgList: [
|
imgList: [
|
||||||
{
|
{
|
||||||
@ -79,7 +87,7 @@ const Carousel: ICarouselSchema = {
|
|||||||
uid: '001',
|
uid: '001',
|
||||||
name: 'image.png',
|
name: 'image.png',
|
||||||
status: 'done',
|
status: 'done',
|
||||||
url: 'http://49.234.61.19/uploads/1_1740bd7c3dc.png',
|
url: `${serverUrl}/uploads/1_1740bd7c3dc.png`,
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
@ -93,12 +101,12 @@ const Carousel: ICarouselSchema = {
|
|||||||
uid: '001',
|
uid: '001',
|
||||||
name: 'image.png',
|
name: 'image.png',
|
||||||
status: 'done',
|
status: 'done',
|
||||||
url: 'http://49.234.61.19/uploads/2_1740bd8d525.png',
|
url: `${serverUrl}/uploads/2_1740bd8d525.png`,
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
...baseDefault,
|
tplImg: `${serverUrl}/uploads/carousal_17442e1420f.png`,
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
export default Carousel;
|
export default Carousel;
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user