2015-06-25 20:01:20 +08:00
|
|
|
# 切换到下一步
|
2015-06-25 16:01:04 +08:00
|
|
|
|
|
|
|
- order: 3
|
|
|
|
|
2015-09-01 17:43:08 +08:00
|
|
|
随机生成 3~6 个步骤,初始随机进行到其中一个步骤。
|
2015-06-25 20:01:20 +08:00
|
|
|
|
2015-06-25 18:12:42 +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 container = document.getElementById('components-steps-demo-step-next');
|
|
|
|
const array = Array.apply(null, Array(Math.floor(Math.random() * 3) + 3));
|
|
|
|
const steps = array.map(function(item, i) {
|
2015-09-16 16:28:57 +08:00
|
|
|
return {
|
|
|
|
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 {
|
|
|
|
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>
|
|
|
|
<div>当前正在执行第 {cs + 1} 步</div>
|
|
|
|
<Steps current={cs}>
|
|
|
|
{steps.map((s, i) => <Step key={i} title={s.title} description={s.description} />)}
|
|
|
|
</Steps>
|
|
|
|
<div>
|
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-10-20 16:47:55 +08:00
|
|
|
ReactDOM.render(<App />, container);
|
2015-06-25 20:01:20 +08:00
|
|
|
````
|