当前位置: 首页 > article >正文

uniapp 实现的步进指示器组件

采用 uniapp 实现的一款步进指示器组件,展示业务步骤进度等内容,对外提供“前进”、“后退”方法,让用户可高度自定义所需交互,适配 web、H5、微信小程序(其他平台小程序未测试过,可自行尝试)

可到插件市场下载尝试: https://ext.dcloud.net.cn/plugin?id=22603

  • 使用示例

请添加图片描述

使用示例

分别演示vue2、vue3 setup示例

vue2 写法

<template>
  <view>
		<view class="font-class">示例一:</view>
		<view>
			<view style="background-color: #272822; padding: 10px; margin: 10px; border-radius: 6px; color: #fff;">
				<wo-step-indicator :default-step="1" :options="steps" ref="stepIndicator1" @change="onChangeStep"></wo-step-indicator>
			</view>
			<view style="padding: 10px 0; margin: 0 10px;">
			  <view v-show="step === 1">
			    <view
			      style="height: 100px; width: 100%; border-radius: 6px; background-color: #299B48; color: #fff; display: flex; justify-content: center; align-items: center;">
			      步骤一
			    </view>
			  </view>
			  <view v-show="step === 2">
			    <view
			      style="height: 100px; width: 100%; border-radius: 6px; background-color:#FF5739; color: #fff; display: flex; justify-content: center; align-items: center;">
			      步骤二
			    </view>
			  </view>
			  <view v-show="step === 3">
			    <view
			      style="height: 100px; width: 100%; border-radius: 6px; background-color: #41A5E1; color: #fff; display: flex; justify-content: center; align-items: center;">
			      步骤三
			    </view>
			  </view>
			  <view v-show="step === 4">
			    <view
			      style="height: 100px; width: 100%; border-radius: 6px; background-color: #272822; color: #fff; display: flex; justify-content: center; align-items: center;">
			      步骤四
			    </view>
			  </view>
			</view>
		</view>
		<view class="font-class">示例二:</view>
		<view style="display: flex; gap: 10px;">
			<view class="step-class" style="margin-right: 0px;">
				<wo-step-indicator   ref="stepIndicator2" @change="onChangeStep"></wo-step-indicator>
			</view>
			<view style="margin: 10px 10px 10px 0; flex: 1;">
			  <view v-show="step === 1">
			    <view
			      style="height: 200px; width: 100%; border-radius: 6px; background-color: #299B48; color: #fff; display: flex; justify-content: center; align-items: center;">
			      步骤一
			    </view>
			  </view>
			  <view v-show="step === 2">
			    <view
			      style="height: 200px; width: 100%; border-radius: 6px; background-color:#FF5739; color: #fff; display: flex; justify-content: center; align-items: center;">
			      步骤二
			    </view>
			  </view>
			  <view v-show="step === 3">
			    <view
			      style="height: 200px; width: 100%; border-radius: 6px; background-color: #41A5E1; color: #fff; display: flex; justify-content: center; align-items: center;">
			      步骤三
			    </view>
			  </view>
			  <view v-show="step === 4">
			    <view
			      style="height: 200px; width: 100%; border-radius: 6px; background-color: #272822; color: #fff; display: flex; justify-content: center; align-items: center;">
			      步骤四
			    </view>
			  </view>
			</view>
		</view>
		<view class="font-class">自定义操作:</view>
		<view style="display: flex; gap: 10px; padding-top: 10px;">
		  <button @click="prevStep" :disabled="step <= 1">上一步</button>
		  <button @click="nextStep" :disabled="step >= steps.length">下一步</button>
		  <button v-show="step >= steps.length">完成</button>
		</view>
  </view>
</template>

<script>
export default {
  data() {
    return {
      steps: [
        {
          index: '1',
          name: 'Step 1',
        },
        {
          index: '2',
          name: 'Step 2',
        },
        {
          index: '3',
          name: 'Step 3',
        },
        {
          index: '4',
          name: 'Step 4',
        },
      ],
      step: 1,
      stepIndicator1: null,
			stepIndicator2: null
    };
  },
  methods: {
    prevStep() {
      this.$refs.stepIndicator1.prev();
			this.$refs.stepIndicator2.prev();
    },
    nextStep() {
      this.$refs.stepIndicator1.next();
			this.$refs.stepIndicator2.next();
    },
    onChangeStep(data) {
      this.step = data.step;
      console.log('Current step:', data);
    }
  }
};
</script>

<style>
.font-class {
	font-size: 12px;
	padding: 10px 10px 0 10px;
}
.step-class {
	background-color: #272822;
	color: #fff;
	padding: 15px;
	margin: 10px;
	border-radius: 6px;
}
</style>

vue3 setup写法

<template>
	<view>
		<view class="font-class">示例一:</view>
		<view>
			<view style="background-color: #272822; padding: 10px; margin: 10px; border-radius: 6px; color: #fff;">
				<wo-step-indicator :default-step="1" :options="steps" ref="stepIndicator1"
					@change="onChangeStep"></wo-step-indicator>
			</view>
			<view style="padding: 10px 0; margin: 0 10px;">
				<view v-show="step === 1">
					<view
						style="height: 100px; width: 100%; border-radius: 6px; background-color: #299B48; color: #fff; display: flex; justify-content: center; align-items: center;">
						步骤一
					</view>
				</view>
				<view v-show="step === 2">
					<view
						style="height: 100px; width: 100%; border-radius: 6px; background-color:#FF5739; color: #fff; display: flex; justify-content: center; align-items: center;">
						步骤二
					</view>
				</view>
				<view v-show="step === 3">
					<view
						style="height: 100px; width: 100%; border-radius: 6px; background-color: #41A5E1; color: #fff; display: flex; justify-content: center; align-items: center;">
						步骤三
					</view>
				</view>
				<view v-show="step === 4">
					<view
						style="height: 100px; width: 100%; border-radius: 6px; background-color: #272822; color: #fff; display: flex; justify-content: center; align-items: center;">
						步骤四
					</view>
				</view>
			</view>
		</view>
		<view class="font-class">示例二:</view>
		<view style="display: flex; gap: 10px;">
			<view class="step-class" style="margin-right: 0px;">
				<wo-step-indicator ref="stepIndicator2" @change="onChangeStep"></wo-step-indicator>
			</view>
			<view style="margin: 10px 10px 10px 0; flex: 1;">
				<view v-show="step === 1">
					<view
						style="height: 200px; width: 100%; border-radius: 6px; background-color: #299B48; color: #fff; display: flex; justify-content: center; align-items: center;">
						步骤一
					</view>
				</view>
				<view v-show="step === 2">
					<view
						style="height: 200px; width: 100%; border-radius: 6px; background-color:#FF5739; color: #fff; display: flex; justify-content: center; align-items: center;">
						步骤二
					</view>
				</view>
				<view v-show="step === 3">
					<view
						style="height: 200px; width: 100%; border-radius: 6px; background-color: #41A5E1; color: #fff; display: flex; justify-content: center; align-items: center;">
						步骤三
					</view>
				</view>
				<view v-show="step === 4">
					<view
						style="height: 200px; width: 100%; border-radius: 6px; background-color: #272822; color: #fff; display: flex; justify-content: center; align-items: center;">
						步骤四
					</view>
				</view>
			</view>
		</view>
		<view class="font-class">自定义操作:</view>
		<view style="display: flex; gap: 10px; padding-top: 10px;">
			<button @click="prevStep" :disabled="step <= 1">上一步</button>
			<button @click="nextStep" :disabled="step >= steps.length">下一步</button>
			<button v-show="step >= steps.length">完成</button>
		</view>
	</view>
</template>

<script setup>
import { ref } from 'vue';

const steps = ref([
	{ index: '1', name: 'Step 1' },
	{ index: '2', name: 'Step 2' },
	{ index: '3', name: 'Step 3' },
	{ index: '4', name: 'Step 4' },
]);

const step = ref(1);
const stepIndicator1 = ref(null);
const stepIndicator2 = ref(null);

const prevStep = () => {
	stepIndicator1.value.prev();
	stepIndicator2.value.prev();
};

const nextStep = () => {
	stepIndicator1.value.next();
	stepIndicator2.value.next();
};

const onChangeStep = (data) => {
	step.value = data.step;
	console.log('Current step:', data);
};
</script>

<style>
.font-class {
	font-size: 12px;
	padding: 10px 10px 0 10px;
}

.step-class {
	background-color: #272822;
	color: #fff;
	padding: 15px;
	margin: 10px;
	border-radius: 6px;
}
</style>

http://www.kler.cn/a/584016.html

相关文章:

  • C++设计模式-原型模式:从基本介绍,内部原理、应用场景、使用方法,常见问题和解决方案进行深度解析
  • OpenHarmony 编译运行qemu模拟设备
  • MyBatis 中SQL 映射文件是如何与 Mapper 接口关联起来的? MyBatis 如何知道应该调用哪个 SQL 语句?
  • Tomcat新手入门指南:从零开始搭建Web服务器
  • SSR 框架是什么?
  • 使用 OpenAI 的 Node.js 通过 Ollama 在本地运行 DeepSeek R1
  • 工厂变电所运维云平台解决方案-直击运维痛点,重塑高效安全运维典范
  • 框架源码私享笔记(02)Mybatis核心框架原理 | 一条SQL透析核心组件功能特性
  • 过滤器(Filter)与拦截器(Interceptor)
  • 【Git】所有文章传送门(持续更新...)
  • eNSP中路由器的CON/AUX接口、GE Combo接口、Mini USB接口、USB接口、WAN侧uplink接口、FE接口、GE接口介绍
  • C++程序员职业规划
  • IP层之分片包的整合处理---BUG修复
  • celery入门
  • 大模型架构记录5-向量数据库
  • AutoSar架构-----XCP模块与协议介绍
  • 【Jmeter】使用教程
  • 基于WPF的雷达上位机系统开发实践
  • 【算法】蒙特卡洛树搜索(MCTS)算法
  • leetcode0026 删除有序数组中的重复项 easy