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
|
|
|
|
|
2019-09-28 12:45:07 +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({
|
2019-09-28 12:45:07 +00:00
|
|
|
|
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 {
|
2019-09-28 12:45:07 +00:00
|
|
|
|
data() {
|
2018-03-09 10:52:31 +00:00
|
|
|
|
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: {
|
2019-09-28 12:45:07 +00:00
|
|
|
|
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
|
|
|
|
},
|
|
|
|
|
},
|
2019-09-28 12:45:07 +00:00
|
|
|
|
render() {
|
2019-01-12 03:33:27 +00:00
|
|
|
|
const cs = this.currentStep;
|
2018-03-09 10:52:31 +00:00
|
|
|
|
return (
|
2019-09-28 12:45:07 +00:00
|
|
|
|
<form class="my-step-form">
|
2018-03-09 10:52:31 +00:00
|
|
|
|
<div>这个demo随机生成3~6个步骤,初始随机进行到其中一个步骤</div>
|
|
|
|
|
<div>当前正在执行第{cs + 1}步</div>
|
2019-09-28 12:45:07 +00:00
|
|
|
|
<div class="my-step-container">
|
2018-03-09 10:52:31 +00:00
|
|
|
|
<Steps current={cs}>
|
2019-09-28 12:45:07 +00:00
|
|
|
|
{steps.map((s, i) => {
|
|
|
|
|
return <Step key={i} title={s.title} />;
|
|
|
|
|
})}
|
2018-03-09 10:52:31 +00:00
|
|
|
|
</Steps>
|
|
|
|
|
</div>
|
|
|
|
|
|
2019-09-28 12:45:07 +00:00
|
|
|
|
<div>
|
|
|
|
|
<button type="button" onClick={this.nextStep}>
|
|
|
|
|
下一步
|
|
|
|
|
</button>
|
|
|
|
|
</div>
|
2018-03-09 10:52:31 +00:00
|
|
|
|
</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>
|