DivisionTestStepper.vue 2.87 KB
<template>
  <div class="division-test-stepper">
    <div class="stepper-track">
      <template v-for="n in 3">
        <button
          :key="'node-' + n"
          type="button"
          class="stepper-node"
          :class="'is-' + stepVisualState(n)"
          @click="onStepClick(n)"
        >
          <i v-if="stepVisualState(n) === 'done'" class="el-icon-check stepper-check" />
          <span v-else class="stepper-num">{{ n }}</span>
        </button>
        <div
          v-if="n < 3"
          :key="'line-' + n"
          class="stepper-line"
          :class="{ 'is-done': isConnectorDone(n) }"
        />
      </template>
    </div>
  </div>
</template>

<script>
export default {
  name: 'DivisionTestStepper',
  props: {
    maxReachedStep: {
      type: Number,
      default: 1
    },
    viewStep: {
      type: Number,
      default: 1
    },
    stepCompletedFlags: {
      type: Array,
      default: () => [false, false, false]
    }
  },
  methods: {
    /** done=蓝色勾 | current=蓝色序号 | wait=灰色序号 */
    stepVisualState(stepNum) {
      const idx = stepNum - 1
      const completed =
        !!this.stepCompletedFlags[idx] || stepNum < Number(this.viewStep)
      if (completed) return 'done'
      if (stepNum === Number(this.viewStep)) return 'current'
      return 'wait'
    },
    /** 步骤 n 与 n+1 之间的连线:前序步骤已完成时为蓝色 */
    isConnectorDone(stepNum) {
      return this.stepVisualState(stepNum) === 'done'
    },
    onStepClick(stepNum) {
      this.$emit('step-click', stepNum)
    }
  }
}
</script>

<style scoped lang="scss">
$step-primary: #2a58ad;
$step-wait-border: #dcdfe6;
$step-wait-text: #c0c4cc;
$step-line-wait: #dcdfe6;

.division-test-stepper {
  margin-bottom: 24px;
  padding: 0 40px;
}

.stepper-track {
  display: flex;
  align-items: center;
  justify-content: center;
  max-width: 360px;
  margin: 0 auto;
}

.stepper-node {
  flex-shrink: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  padding: 0;
  border-radius: 50%;
  border: 1px solid $step-wait-border;
  background: #fff;
  cursor: pointer;
  outline: none;
  cursor: pointer;
  transition: border-color 0.2s, color 0.2s;

  &:focus-visible {
    box-shadow: 0 0 0 2px rgba($step-primary, 0.25);
  }

  &.is-done {
    border-color: $step-primary;
    color: $step-primary;
  }

  &.is-current {
    border-color: $step-primary;
    color: $step-primary;
  }

  &.is-wait {
    border-color: $step-wait-border;
    color: $step-wait-text;
  }
}

.stepper-check {
  font-size: 14px;
  font-weight: 700;
  line-height: 1;
}

.stepper-num {
  font-size: 14px;
  font-weight: 500;
  line-height: 1;
}

.stepper-line {
  flex: 1;
  height: 1px;
  min-width: 48px;
  margin: 0 8px;
  background: $step-line-wait;
  transition: background-color 0.2s;

  &.is-done {
    background: $step-primary;
  }
}
</style>