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

vue2+elementUI实现园型动态步骤条小组件,带缩放功能

成品:

代码:

在项目components文件夹中创建StepProgress.vue文件

<!-- eslint-disable prettier/prettier -->
<template><div class="step-progress"><divclass="step-progress":style="{ transform: `scale(${scale})`, transformOrigin: 'left top' }"><div v-for="(step, index) in steps" :key="step.value" class="step-item"><!-- 圆环 --><divclass="circle":class="{active: Number(step.value) <= Number(currentStep),inactive: Number(step.value) > Number(currentStep)}"><div class="circle-content"><divclass="step-number":class="{ blue: Number(step.value) <= Number(currentStep) }">{{ step.value.padStart(2, '0')}}</div><divclass="step-text":class="{ grey: Number(step.value) > Number(currentStep) }">{{ step.label }}</div></div></div><!-- 箭头(最后一步不显示) --><divv-if="index < steps.length - 1"class="arrow":class="{active: Number(step.value) < Number(currentStep),inactive: Number(step.value) >= Number(currentStep)}"></div></div></div></div>
</template><script>
export default {name: 'StepProgress',props: {currentStep: {type: String,required: true,},steps: {type: Array,default: () => [{ value: '1', label: '步骤\n1' },{ value: '2', label: '步骤\n介绍' },{ value: '3', label: '步骤\n3' },{ value: '4', label: '步骤\n4' },{ value: '5', label: '步骤\n5' },{ value: '6', label: '步骤\n6' },{ value: '7', label: '步骤\n7' },{ value: '8', label: '步骤\n8' },],},},data() {return {scale: 1,baseWidth: 1920, // 组件在 1200px 宽度下正常显示}},mounted() {this.updateScale()window.addEventListener('resize', this.updateScale)},beforeDestroy() {window.removeEventListener('resize', this.updateScale)},methods: {updateScale() {const width = window.innerWidththis.scale = Math.min(width / this.baseWidth, 1) // 不能超过 1 倍},},
}
</script>
<style scoped lang="less">
.step-progress {display: flex;align-items: center;/* justify-content: space-between; */width: 100%;.step-item {display: flex;align-items: center;/* flex: 1; */}.circle {width: 112px;height: 113px;background-size: cover;background-repeat: no-repeat;flex-shrink: 0;}.circle.active {background: url('~@assets/images/xw/ok.png') no-repeat;
//此背景图为(背景透明的蓝色圆环,背景图放到文章最后)background-size: contain;}.circle.inactive {background: url('~@assets/images/xw/no.png') no-repeat;
//此背景图为(背景透明的灰色圆环,背景图放到文章最后)background-size: contain;}.circle-content {display: flex;flex-direction: column;align-items: center;justify-content: center;height: 100%;}.step-number {font-weight: bold;font-size: 20px;color: #999; /* 默认灰色 */font-family: D-DIN, D-DIN;}.step-number.blue {color: #1677ff; /* 蓝色数字 */}.step-text {text-align: center;font-family: PingFangSC, PingFang SC;font-weight: 400;font-size: 14px;color: #2f3033;white-space: pre-line; /* 让 \n 换行生效 */}.step-text.grey {color: #999; /* 灰色文字 */}.arrow {width: 50px;height: 20px;background-size: contain;background-repeat: no-repeat;margin: 0 10px;flex-shrink: 0;}.arrow.active {background: url('~@assets/images/xw/jtlan.png') no-repeat;
//此背景图为(背景透明的蓝色箭头,背景图放到文章最后)background-size: contain;}.arrow.inactive {background: url('~@assets/images/xw/jthui.png') no-repeat;
//此背景图为(背景透明的灰色箭头,背景图放到文章最后)background-size: contain;}
}
</style>

使用:

再父组件中引入(currentStep 这个数传几就亮到第几步)

<template><div><StepProgress currentStep="5" /></div>
</template><script>
import StepProgress from '@/components/StepProgress.vue'export default {components: { StepProgress }
}
</script>

背景图片:

http://www.xdnf.cn/news/17630.html

相关文章:

  • 【4】Transformers快速入门:自然语言模型 vs 统计语言模型
  • 【无标题】centos 配置阿里云的yum源
  • vue文件或文件夹拖拽上传
  • WPS文字和Word:不只是表格,段落也可以排序
  • 校园快递小程序(腾讯地图API、二维码识别、Echarts图形化分析)
  • 【Dify学习笔记】:Dify搭建图片文件数据分析助手
  • Kimi K2 架构深度解析:万亿MoE模型的效率革命与智能体突破
  • Linux文件系统:从虚拟接口到物理实现的架构解析
  • 【C++】5. 内存管理
  • Android Studio注释如何不从行首开始
  • gpt-5与gpt-5-fast
  • CPPIO流
  • Postman接口测试:postman设置接口关联,实现参数化
  • 当多模态大语言模型遇上视觉难题!AI视觉探索之旅
  • 视频输入输出模块介绍和示例
  • 编译 BusyBox for ARM 平台
  • 力扣面试150题--爬楼梯 打家劫舍 零钱兑换 最长递增子序列
  • Elasticsearch JS 自定义 ConnectionPool / Connection / Serializer、敏感信息脱敏与 v8 平滑迁移
  • 01-Ansible 自动化介绍与使用
  • 83. 删除排序链表中的重复元素
  • Neo4j Cypher
  • Fiddler国内中文网使用经验分享,从抓包入门到API调试进阶
  • 【读代码】深度解析 Researcher:开源自动化科研助手
  • K8S 节点初始化一键脚本(禁用 SELinux + 关闭 swap + 开启 ipvs 亲测实用)
  • Golang 语言中 Context 的使用方式
  • 计算机视觉(6)-自动驾驶感知方案对比
  • AV、IPS、WAF对比
  • CMake笔记:PUBLIC/PRIVATE/INTERFACE的使用
  • 力扣经典算法篇-50-单词规律(双哈希结构+正反向求解)
  • 微软发布GPT-5赋能的Copilot:重构办公场景的智能革命