StepsProgress.vue 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. <template>
  2. <div class="step-progress">
  3. <div class="step-menu">
  4. <el-steps :active="current" align-center process-status="finish">
  5. <el-step
  6. v-for="(step, index) in STEPS_LIST"
  7. :key="index"
  8. :title="step.title"
  9. ></el-step>
  10. </el-steps>
  11. </div>
  12. <div class="step-body">
  13. <component
  14. :is="currentComponent"
  15. :ref="currentComponent"
  16. @on-next="toNext"
  17. @on-ready="stepReady"
  18. ></component>
  19. </div>
  20. <div class="step-ctrl">
  21. <el-button type="primary" @click="prevStep" :disabled="isFirstStep"
  22. >上一步</el-button
  23. >
  24. <el-button
  25. type="primary"
  26. @click="nextStep"
  27. :disabled="nextHolder || isLastStep"
  28. >下一步</el-button
  29. >
  30. </div>
  31. </div>
  32. </template>
  33. <script>
  34. import StepOne from "./StepOne";
  35. import StepTwo from "./StepTwo";
  36. import StepThree from "./StepThree";
  37. import StepFour from "./StepFour";
  38. const STEPS_LIST = [
  39. {
  40. name: "step-one",
  41. title: "步骤1"
  42. },
  43. {
  44. name: "step-two",
  45. title: "步骤2"
  46. },
  47. {
  48. name: "step-three",
  49. title: "步骤3"
  50. },
  51. {
  52. name: "step-four",
  53. title: "步骤4"
  54. }
  55. ];
  56. export default {
  57. name: "step-progress",
  58. components: {
  59. StepOne,
  60. StepTwo,
  61. StepThree,
  62. StepFour
  63. },
  64. data() {
  65. return {
  66. STEPS_LIST,
  67. current: 0,
  68. nextHolder: true,
  69. dataReady: true
  70. };
  71. },
  72. computed: {
  73. currentComponent() {
  74. return this.STEPS_LIST[this.current].name;
  75. },
  76. isFirstStep() {
  77. return this.current === 0;
  78. },
  79. isLastStep() {
  80. return this.current === this.lastStep;
  81. },
  82. lastStep() {
  83. return this.STEPS_LIST.length - 1;
  84. }
  85. },
  86. watch: {
  87. current() {
  88. // 滚动条置顶
  89. // document.getElementById("home-body").scrollTop = 0;
  90. }
  91. },
  92. methods: {
  93. prevStep() {
  94. if (this.isFirstStep) return;
  95. this.current -= 1;
  96. },
  97. nextStep() {
  98. if (this.isLastStep || this.nextHolder) return;
  99. this.$refs[this.currentComponent].checkValid();
  100. },
  101. toNext() {
  102. if (this.isLastStep) return;
  103. this.current += 1;
  104. this.nextHolder = true;
  105. },
  106. stepReady() {
  107. this.nextHolder = false;
  108. }
  109. }
  110. };
  111. </script>
  112. <style lang="css">
  113. .step-body {
  114. min-height: 600px;
  115. padding: 20px;
  116. }
  117. .step-ctrl {
  118. text-align: center;
  119. margin-top: 50px;
  120. }
  121. </style>