2016-03-31 09:40:55 +08:00
|
|
|
---
|
|
|
|
order: 3
|
|
|
|
title: 切换到下一步
|
|
|
|
---
|
2015-06-25 16:01:04 +08:00
|
|
|
|
2015-09-01 17:43:08 +08:00
|
|
|
随机生成 3~6 个步骤,初始随机进行到其中一个步骤。
|
2015-06-25 20:01:20 +08:00
|
|
|
|
2015-07-08 16:36:08 +08:00
|
|
|
````css
|
2015-09-16 16:28:57 +08:00
|
|
|
#components-steps-demo-step-next > div > div {
|
2015-07-08 16:36:08 +08:00
|
|
|
margin-bottom: 30px;
|
2015-06-25 18:12:42 +08:00
|
|
|
}
|
2015-07-08 16:36:08 +08:00
|
|
|
````
|
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;
|
|
|
|
const array = Array.apply(null, Array(Math.floor(Math.random() * 3) + 3));
|
2016-01-23 15:22:16 +08:00
|
|
|
const steps = array.map((item, i) => {
|
2015-09-16 16:28:57 +08:00
|
|
|
return {
|
2016-02-17 18:04:42 +08:00
|
|
|
title: `步骤${i + 1}`
|
2015-09-16 16:28:57 +08:00
|
|
|
};
|
|
|
|
});
|
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 {
|
|
|
|
currentStep: 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() {
|
2015-10-28 20:55:49 +08:00
|
|
|
let s = this.state.currentStep + 1;
|
2015-06-25 18:12:42 +08:00
|
|
|
if (s === steps.length) {
|
|
|
|
s = 0;
|
|
|
|
}
|
|
|
|
this.setState({
|
|
|
|
currentStep: s
|
|
|
|
});
|
|
|
|
},
|
|
|
|
render() {
|
2015-10-28 20:55:49 +08:00
|
|
|
const cs = this.state.currentStep;
|
2015-09-16 16:28:57 +08:00
|
|
|
return (
|
|
|
|
<div>
|
2016-04-06 16:16:46 +08:00
|
|
|
<div style={{ marginBottom: 24 }}>当前正在执行第 {cs + 1} 步</div>
|
2015-09-16 16:28:57 +08:00
|
|
|
<Steps current={cs}>
|
|
|
|
{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>
|
|
|
|
);
|
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
|
|
|
````
|