Skip to content

Commit

Permalink
feat: 添加无法自定义显示天,时,分,秒
Browse files Browse the repository at this point in the history
  • Loading branch information
robinv8 committed Dec 11, 2023
1 parent 2247d4e commit 37fc4d4
Showing 1 changed file with 16 additions and 19 deletions.
35 changes: 16 additions & 19 deletions packages/taro-ui/rn/components/countdown/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,12 @@ export default class AtCountdown extends React.Component<

if (this.seconds > 0) {
day = this.props.isShowDay ? Math.floor(this.seconds / (60 * 60 * 24)) : 0
hours = Math.floor(this.seconds / (60 * 60)) - day * 24
minutes = Math.floor(this.seconds / 60) - day * 24 * 60 - hours * 60
hours = this.props.isShowHour
? Math.floor(this.seconds / (60 * 60)) - day * 24
: 0
minutes = this.props.isShowMinute
? Math.floor(this.seconds / 60) - day * 24 * 60 - hours * 60
: 0
seconds =
Math.floor(this.seconds) -
day * 24 * 60 * 60 -
Expand Down Expand Up @@ -134,7 +138,8 @@ export default class AtCountdown extends React.Component<
format,
isShowDay,
isCard,
isShowHour
isShowHour,
isShowMinute
} = this.props
const { _day, _hours, _minutes, _seconds } = this.state

Expand All @@ -150,25 +155,15 @@ export default class AtCountdown extends React.Component<
style={customStyle}
>
{isShowDay && (
<AtCountdownItem isCard={isCard} num={_day} separator={format!.day} />
<AtCountdownItem num={_day} separator={format?.day || '天'} />
)}
{isShowHour && (
<AtCountdownItem
isCard={isCard}
num={_hours}
separator={format!.hours}
/>
<AtCountdownItem num={_hours} separator={format?.hours || ''} />
)}
<AtCountdownItem
isCard={isCard}
num={_minutes}
separator={format!.minutes}
/>
<AtCountdownItem
isCard={isCard}
num={_seconds}
separator={format!.seconds}
/>
{isShowMinute && (
<AtCountdownItem num={_minutes} separator={format?.minutes || ''} />
)}
<AtCountdownItem num={_seconds} separator={format?.seconds || ''} />
</View>
)
}
Expand All @@ -180,6 +175,7 @@ AtCountdown.defaultProps = {
isCard: false,
isShowDay: false,
isShowHour: true,
isShowMinute: true,
format: {
day: '天',
hours: '时',
Expand All @@ -198,6 +194,7 @@ AtCountdown.propTypes = {
isCard: PropTypes.bool,
isShowDay: PropTypes.bool,
isShowHour: PropTypes.bool,
isShowMinute: PropTypes.bool,
format: PropTypes.object,
day: PropTypes.number,
hours: PropTypes.number,
Expand Down

0 comments on commit 37fc4d4

Please sign in to comment.