diff --git a/packages/card/index.tsx b/packages/card/index.tsx index 9d4546896..6036ddb4b 100644 --- a/packages/card/index.tsx +++ b/packages/card/index.tsx @@ -46,82 +46,111 @@ function Card( ) { const { thumb } = props; - const showThumb = slots.thumb || thumb; - const showTag = slots.tag || props.tag; const showNum = slots.num || isDef(props.num); const showPrice = slots.price || isDef(props.price); const showOriginPrice = slots['origin-price'] || isDef(props.originPrice); const showBottom = showNum || showPrice || showOriginPrice; - const Thumb = showThumb && ( - - {slots.thumb ? ( - slots.thumb() - ) : props.lazyLoad ? ( + function ThumbTag() { + if (slots.tag || props.tag) { + const DefaultTag = ( + + {props.tag} + + ); + + return
{slots.tag ? slots.tag() : DefaultTag}
; + } + } + + function Thumb() { + if (slots.thumb || thumb) { + const DefaultThumb = props.lazyLoad ? ( ) : ( - )} - {showTag && ( -
- {slots.tag ? ( - slots.tag() - ) : ( - - {props.tag} - - )} + ); + + return ( + + {slots.thumb ? slots.thumb() : DefaultThumb} + {ThumbTag()} + + ); + } + } + + function Title() { + if (slots.title) { + return slots.title(); + } + + if (props.title) { + return
{props.title}
; + } + } + + function Desc() { + if (slots.desc) { + return slots.desc(); + } + + if (props.desc) { + return
{props.desc}
; + } + } + + function Price() { + if (showPrice) { + return ( +
+ {slots.price ? slots.price() : `${props.currency} ${props.price}`}
- )} - - ); + ); + } + } - const Title = slots.title - ? slots.title() - : props.title &&
{props.title}
; + function OriginPrice() { + if (showOriginPrice) { + const slot = slots['origin-price']; + return ( +
+ {slot ? slot() : `${props.currency} ${props.originPrice}`} +
+ ); + } + } - const Desc = slots.desc - ? slots.desc() - : props.desc &&
{props.desc}
; + function Num() { + if (showNum) { + return
{slots.num ? slots.num() : `x ${props.num}`}
; + } + } - const Price = showPrice && ( -
- {slots.price ? slots.price() : `${props.currency} ${props.price}`} -
- ); - - const OriginPrice = showOriginPrice && ( -
- {slots['origin-price'] - ? slots['origin-price']() - : `${props.currency} ${props.originPrice}`} -
- ); - - const Num = showNum && ( -
{slots.num ? slots.num() : `x ${props.num}`}
- ); - - const Footer = slots.footer &&
{slots.footer()}
; + function Footer() { + if (slots.footer) { + return
{slots.footer()}
; + } + } return (
- {Thumb} + {Thumb()}
- {Title} - {Desc} + {Title()} + {Desc()} {slots.tags && slots.tags()} {showBottom && (
- {Price} - {OriginPrice} - {Num} + {Price()} + {OriginPrice()} + {Num()}
)}
- {Footer} + {Footer()}
); }