2016-03-31 09:40:55 +08:00
|
|
|
---
|
|
|
|
order: 3
|
2016-07-21 10:07:30 +08:00
|
|
|
title:
|
|
|
|
zh-CN: 切换到下一步
|
|
|
|
en-US: Switch to next
|
2016-03-31 09:40:55 +08:00
|
|
|
---
|
2015-06-25 16:01:04 +08:00
|
|
|
|
2016-07-21 10:07:30 +08:00
|
|
|
## zh-CN
|
|
|
|
|
2015-09-01 17:43:08 +08:00
|
|
|
随机生成 3~6 个步骤,初始随机进行到其中一个步骤。
|
2015-06-25 20:01:20 +08:00
|
|
|
|
2016-07-21 10:07:30 +08:00
|
|
|
## en-US
|
|
|
|
|
|
|
|
Let's generate 3~6 steps randomly, and proceed to a random step.
|
|
|
|
|
2015-06-25 16:01:04 +08:00
|
|
|
````jsx
|
2015-10-28 20:55:49 +08:00
|
|
|
import { Steps, Button } from 'antd';
|
|
|
|
const Step = Steps.Step;
|
2016-08-23 21:00:35 +08:00
|
|
|
const array = [...Array(Math.floor(Math.random() * 3) + 3)];
|
2016-07-21 14:20:49 +08:00
|
|
|
const steps = array.map((item, i) => ({
|
|
|
|
title: `步骤${i + 1}`,
|
|
|
|
}));
|
2015-06-25 18:12:42 +08:00
|
|
|
|
2015-10-28 20:55:49 +08:00
|
|
|
const App = React.createClass({
|
2015-06-25 18:12:42 +08:00
|
|
|
getInitialState() {
|
|
|
|
return {
|
2016-07-21 14:20:49 +08:00
|
|
|
current: Math.floor(Math.random() * steps.length),
|
2015-11-25 17:35:49 +08:00
|
|
|
};
|
2015-06-25 18:12:42 +08:00
|
|
|
},
|
2015-09-16 16:28:57 +08:00
|
|
|
next() {
|
2016-07-21 14:20:49 +08:00
|
|
|
let current = this.state.current + 1;
|
|
|
|
if (current === steps.length) {
|
|
|
|
current = 0;
|
2015-06-25 18:12:42 +08:00
|
|
|
}
|
2016-07-21 14:20:49 +08:00
|
|
|
this.setState({ current });
|
2015-06-25 18:12:42 +08:00
|
|
|
},
|
|
|
|
render() {
|
2016-07-21 14:20:49 +08:00
|
|
|
const { current } = this.state;
|
2015-09-16 16:28:57 +08:00
|
|
|
return (
|
|
|
|
<div>
|
2016-07-21 14:20:49 +08:00
|
|
|
<div style={{ marginBottom: 24 }}>当前正在执行第 {current + 1} 步</div>
|
|
|
|
<Steps current={current}>
|
2015-09-16 16:28:57 +08:00
|
|
|
{steps.map((s, i) => <Step key={i} title={s.title} description={s.description} />)}
|
|
|
|
</Steps>
|
2016-04-06 16:16:46 +08:00
|
|
|
<div style={{ marginTop: 24 }}>
|
2015-10-08 15:13:04 +08:00
|
|
|
<Button onClick={this.next}>下一步</Button>
|
2015-09-16 16:28:57 +08:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
);
|
2016-05-11 09:32:33 +08:00
|
|
|
},
|
2015-06-25 18:12:42 +08:00
|
|
|
});
|
|
|
|
|
2015-12-29 12:08:58 +08:00
|
|
|
ReactDOM.render(<App />, mountNode);
|
2015-06-25 20:01:20 +08:00
|
|
|
````
|