2019-01-09 20:38:09 +08:00
|
|
|
---
|
|
|
|
order: 3
|
|
|
|
title:
|
|
|
|
zh-CN: 倒计时
|
|
|
|
en-US: Countdown
|
|
|
|
---
|
|
|
|
|
|
|
|
## zh-CN
|
|
|
|
|
|
|
|
倒计时组件。
|
|
|
|
|
|
|
|
## en-US
|
|
|
|
|
|
|
|
Countdown component.
|
|
|
|
|
2022-05-19 09:46:26 +08:00
|
|
|
```tsx
|
2022-05-21 22:14:15 +08:00
|
|
|
import { Col, Row, Statistic } from 'antd';
|
2022-07-04 22:09:54 +08:00
|
|
|
import type { countdownValueType } from 'antd/es/statistic/utils';
|
2022-05-21 22:14:15 +08:00
|
|
|
import React from 'react';
|
2019-01-09 20:38:09 +08:00
|
|
|
|
2019-06-19 19:09:08 +08:00
|
|
|
const { Countdown } = Statistic;
|
2022-02-14 14:40:40 +08:00
|
|
|
const deadline = Date.now() + 1000 * 60 * 60 * 24 * 2 + 1000 * 30; // Dayjs is also OK
|
2019-01-09 20:38:09 +08:00
|
|
|
|
2022-05-19 09:46:26 +08:00
|
|
|
const App: React.FC = () => {
|
|
|
|
const onFinish = () => {
|
|
|
|
console.log('finished!');
|
|
|
|
};
|
|
|
|
|
|
|
|
const onChange = (val: countdownValueType) => {
|
|
|
|
if (4.95 * 1000 < val && val < 5 * 1000) {
|
|
|
|
console.log('changed!');
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
return (
|
|
|
|
<Row gutter={16}>
|
|
|
|
<Col span={12}>
|
|
|
|
<Countdown title="Countdown" value={deadline} onFinish={onFinish} />
|
|
|
|
</Col>
|
|
|
|
<Col span={12}>
|
|
|
|
<Countdown title="Million Seconds" value={deadline} format="HH:mm:ss:SSS" />
|
|
|
|
</Col>
|
|
|
|
<Col span={24} style={{ marginTop: 32 }}>
|
|
|
|
<Countdown title="Day Level" value={deadline} format="D 天 H 时 m 分 s 秒" />
|
|
|
|
</Col>
|
|
|
|
<Col span={12}>
|
|
|
|
<Countdown title="Countdown" value={Date.now() + 10 * 1000} onChange={onChange} />
|
|
|
|
</Col>
|
|
|
|
</Row>
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
export default App;
|
2019-01-09 20:38:09 +08:00
|
|
|
```
|