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

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.dtcms.com/a/73066.html

相关文章:

  • 基于阿里云函数计算(FC)x 云原生 API 网关构建生产级别 LLM Chat 应用方案最佳实践
  • 关于修改 Ollama 及其模型默认路径、迁移已安装的 Ollama 程序和模型以及重启 Ollama 的操作指南
  • 深入解析 item_get_video 接口:获取小红书笔记详情的高效工具
  • C#的委托Action
  • LabVIEW与雷赛OPC-UA测试
  • 解决VueI18n使用浏览器插件翻译后,切换国际化失效的问题
  • Jupyter notebook的安装与使用
  • 共享内存shm_size和内存锁ulimits.memlock配置
  • Flutter_学习记录_connectivity_plus 检测网络
  • java简单基础学习
  • 利用pprof对golang进行性能分析
  • 图片填充容器,如何描述
  • Flutter 边框按钮:OutlinedButton 完全手册与设计最佳实践
  • Java集成WebSocket实现消息推送,详细步骤以及出现的问题如何解决
  • LeetCode 解题思路 18(Hot 100)
  • ESP32移植Openharmony外设篇(10)inmp441麦克风
  • 【接口耗时】⭐️自定义拦截器实现接口耗时统计
  • 基于消息方式的系统间通信
  • (分块)洛谷 P2801 教主的魔法 题解
  • TimeGAN:开启时间序列生成新纪元,结合GAN与自回归模型的优势
  • 智能运维管理系统的主要优势
  • 基于asp.net实现的连锁餐厅收银系统[包运行成功+永久免费答疑辅导]
  • 4、linux c 进程
  • RK3568 android11 基于PN7160的NXP NFC移植
  • C++基础——从C语言快速入门
  • 前端权限系统
  • ctfshow web刷题记录
  • 2.机器学习-回归模型-非线性模型
  • 面试求助:接口测试用例设计主要考虑哪些方面?
  • Matlab自学笔记四十八:各类型缺失值的创建、判断、替换、移位和处理方法