Skip to content

ProStepForm 步骤表单

概述

ProStepForm 是步骤表单组件,封装了 a-steps + 步骤内容 + 导航按钮的三段式布局。通过插槽提供每个步骤的内容,支持异步校验、草稿保存等场景。

基本用法

vue
<script setup lang="ts">
import { ref } from 'vue'
import ProStepForm from '@/components/Pro/ProStepForm/index.vue'
import type { ProStepFormStep } from '@/types/pro'

const currentStep = ref(0)

const steps: ProStepFormStep[] = [
  { title: '基本信息' },
  { title: '详细配置' },
  { title: '确认提交' },
]

const handleNext = async (step: number) => {
  // 在这里进行当前步骤的校验
  currentStep.value = step + 1
}

const handleSubmit = () => {
  console.log('提交表单')
}
</script>

<template>
  <ProStepForm
    v-model="currentStep"
    :steps="steps"
    @next="handleNext"
    @submit="handleSubmit"
  >
    <template #step-0>
      <p>第一步内容</p>
    </template>
    <template #step-1>
      <p>第二步内容</p>
    </template>
    <template #step-2>
      <p>第三步内容</p>
    </template>
  </ProStepForm>
</template>

Props

属性类型默认值说明
stepsProStepFormStep[]步骤配置
modelValuenumber0当前步骤索引(v-model)
loadingbooleanfalse按钮加载状态
prevTextstring'上一步'上一步按钮文案
nextTextstring'下一步'下一步按钮文案
submitTextstring'提交'提交按钮文案

ProStepFormStep

typescript
interface ProStepFormStep {
  title: string
  description?: string
  icon?: Component
}

Events

事件参数说明
update:modelValue(step: number)步骤变化
next(currentStep: number)点击下一步,在回调中完成校验后手动推进步骤
prev(currentStep: number)点击上一步
submit点击提交

Slots

插槽名说明
step-{index}index 步的内容
extra-actions额外操作按钮(如保存草稿、重置)

Methods (via ref)

方法说明
prev()回到上一步
goTo(step)跳转到指定步骤

基于 MIT 许可发布