2018-03-09 10:52:31 +00:00
|
|
|
|
<script>
|
2019-01-12 03:33:27 +00:00
|
|
|
|
import Steps, { Step } from '../index';
|
|
|
|
|
import '../assets/index.less';
|
|
|
|
|
import '../assets/iconfont.less';
|
2018-03-09 10:52:31 +00:00
|
|
|
|
|
|
|
|
|
function generateRandomSteps () {
|
2019-01-12 03:33:27 +00:00
|
|
|
|
const n = Math.floor(Math.random() * 3) + 3;
|
|
|
|
|
const arr = [];
|
2018-03-09 10:52:31 +00:00
|
|
|
|
for (let i = 0; i < n; i++) {
|
|
|
|
|
arr.push({
|
|
|
|
|
title: `步骤${(i + 1)}`,
|
2019-01-12 03:33:27 +00:00
|
|
|
|
});
|
2018-03-09 10:52:31 +00:00
|
|
|
|
}
|
2019-01-12 03:33:27 +00:00
|
|
|
|
return arr;
|
2018-03-09 10:52:31 +00:00
|
|
|
|
}
|
2019-01-12 03:33:27 +00:00
|
|
|
|
const steps = generateRandomSteps();
|
2018-03-09 10:52:31 +00:00
|
|
|
|
export default {
|
|
|
|
|
data () {
|
|
|
|
|
return {
|
|
|
|
|
currentStep: Math.floor(Math.random() * steps.length),
|
2019-01-12 03:33:27 +00:00
|
|
|
|
};
|
2018-03-09 10:52:31 +00:00
|
|
|
|
},
|
|
|
|
|
methods: {
|
|
|
|
|
nextStep () {
|
2019-01-12 03:33:27 +00:00
|
|
|
|
let s = this.currentStep + 1;
|
2018-03-09 10:52:31 +00:00
|
|
|
|
if (s === steps.length) {
|
2019-01-12 03:33:27 +00:00
|
|
|
|
s = 0;
|
2018-03-09 10:52:31 +00:00
|
|
|
|
}
|
2019-01-12 03:33:27 +00:00
|
|
|
|
this.currentStep = s;
|
2018-03-09 10:52:31 +00:00
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
render () {
|
2019-01-12 03:33:27 +00:00
|
|
|
|
const cs = this.currentStep;
|
2018-03-09 10:52:31 +00:00
|
|
|
|
return (
|
|
|
|
|
<form class='my-step-form'>
|
|
|
|
|
<div>这个demo随机生成3~6个步骤,初始随机进行到其中一个步骤</div>
|
|
|
|
|
<div>当前正在执行第{cs + 1}步</div>
|
|
|
|
|
<div class='my-step-container'>
|
|
|
|
|
<Steps current={cs}>
|
|
|
|
|
{
|
|
|
|
|
steps.map((s, i) => {
|
|
|
|
|
return (
|
|
|
|
|
<Step
|
|
|
|
|
key={i}
|
|
|
|
|
title={s.title}
|
|
|
|
|
/>
|
2019-01-12 03:33:27 +00:00
|
|
|
|
);
|
2018-03-09 10:52:31 +00:00
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
</Steps>
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
<div><button type='button' onClick={this.nextStep}>下一步</button></div>
|
|
|
|
|
</form>
|
2019-01-12 03:33:27 +00:00
|
|
|
|
);
|
2018-03-09 10:52:31 +00:00
|
|
|
|
},
|
2019-01-12 03:33:27 +00:00
|
|
|
|
};
|
2018-03-09 10:52:31 +00:00
|
|
|
|
</script>
|
|
|
|
|
<style>
|
|
|
|
|
.my-step-form {
|
|
|
|
|
width: 100%;
|
|
|
|
|
}
|
|
|
|
|
.my-step-form > div {
|
|
|
|
|
margin-bottom: 20px;
|
|
|
|
|
}
|
|
|
|
|
.my-step-container {
|
|
|
|
|
width: 100%;
|
|
|
|
|
}
|
|
|
|
|
</style>
|
|
|
|
|
|