自定义封装进度条标签

代码如下

javascript 复制代码
<!-- 封装自定义progress标签 -->
<template>
  <div class="progress">
    <div class="item" :class="{active: item.complete == 1}"
    v-for="(item, index) in list" :key="index"
    @click="handlerStage(item)"
    >
    {{ item.stageName }}
  </div>
  </div>
</template>
<script setup>
import { ref } from 'vue'
const emit = defineEmits(['handlerStage'])
const props = defineProps({
  list: {
    type: Array,
    default: [] // 设置默认值为 false
  },
})
const handlerStage = (item) => {
  emit('handlerStage', item)
}
</script>
<style lang="scss" scoped>
.progress {
  display: flex;
  div {
    min-width: 95px;
    max-height: 30px;
    box-sizing: border-box;
    padding: 6px 18px;
    background: #fff;
    display: inline-block;
    color: #2D78FF /*#50abe4*/;
    position: relative;
    margin-right: 6px;
    border: 1px solid #2D78FF;
    border-bottom-right-radius: 2px;
  }
  div:after {
    content: '';
    display: block;
    width: 21px;
    height: 22px;
    box-sizing: border-box;
    transform: rotate(45deg);
    border: 1px solid #2D78FF;
    position: absolute;
    right: -11px;
    top: 3px;
    z-index: 10;
    border-bottom-color: transparent;
    border-left-color: transparent;
    border-top-left-radius: 1px;
    border-bottom-right-radius: 3px;
    border-top-right-radius: 4px;
  }
  div:before {
    content: '';
    display: block;
    width: 21px;
    height: 21px;
    box-sizing: border-box;
    transform: rotate(135deg);
    border: 1px solid #2D78FF;
    position: absolute;
    left: -11px;
    top: 3px;
    border-bottom-color: transparent;
    border-right-color: transparent;
    border-bottom-left-radius: 1px;
    border-top-left-radius: 2px;
    border-top-right-radius: 1px;
  }
  .item {
    padding-left: 35px;
    border-right-color: transparent;
    border-left-color: transparent;
  }
  div:first-child {
    border-left-color: #2D78FF;
    border-top-left-radius: 2px;
    border-bottom-left-radius: 2px;
  }

  div:last-child {
    border-right-color: #2D78FF;
    border-bottom-right-radius: 2px;
    border-top-right-radius: 2px;
  }

  div:first-child:before {
    display: none;
  }
  div:last-child:after{
    display: none;
  }
  div:hover {
    cursor: pointer;
    background-color: #2D78FF;
    color: #fff;
  }
  div:hover::after {
    background-color: #2D78FF;
  }
  div:hover::before {
    background-color: #fff;
  }
  div:first-child:hover::before {
    background-color: #fff;
  }
  .active:first-child {
    background-color: #2D78FF;
    color: #fff;
    &::after {
      background-color: #2D78FF;
    }
  }
  .active {
    background-color: #2D78FF;
    color: #fff;
    &::before {
      background-color: #fff;
    }
    &::after {
      background-color: #2D78FF;
    }
  }
  .active:last-child {
    background-color: #2D78FF;
    color: #fff;
    &::before {
      background-color: #fff;
    }
  }
}
</style>

在页面中引用

javascript 复制代码
<hpProgress :list="cusStageVoList" @handlerStage="handlerStage"></hpProgress>
// 以下代码是参考思路(不重要)
// 客户阶段数组
const cusStageVoList = ref<any>([])
// 修改客户阶段
const handlerStage = async (val: any) => {
  let query = {
    id: props.detailCusIdRef,
    stageId: val.id
  }
  await updateCusStageApi(query).then((res: any) => {
    if (res.code === 1) {
      ElMessage({
        type: "success",
        message: `修改成功`,
        duration: 1500,
      })
      emit("customerDetailInfo", props.detailCusIdRef)
    } else {
      ElMessage({
        type: "warning",
        message: `修改失败,${res.msg}`,
        duration: 1500,
      })
    }
  }).catch((err: any) => {
    console.log(err);
  })
}

效果展示

相关推荐
初圣魔门首席弟子6 分钟前
AI Agent 核心原理:工具调用(Function Calling)完整工作流程详解
前端·数据库·人工智能
CodeSheep12 分钟前
又是梁文锋,有点猛啊。
前端·后端·程序员
qq_4221525716 分钟前
视频转 GIF 工具怎么选?2026 年动图制作方案与画质参数对比
javascript·vue.js·音视频
陈老老老板23 分钟前
如何用 Bright Data Web Scraper API + Coze 搭建 Reddit 行业情报聚合 Bot(2026 实战指南)
前端·人工智能
恋猫de小郭29 分钟前
由于 iOS 26 的键盘变化,Flutter 又要重构键盘区域逻辑
android·前端·flutter
怕浪猫35 分钟前
Electron 开发实战(十五):实战项目|从零搭建桌面即时通讯(IM)应用
前端·javascript·electron
喜欢踢足球的老罗42 分钟前
破解 Chrome 扩展的「两世界难题」:MV3 下的 ISOLATED 与 MAIN World 桥接之道
前端·chrome
一拳一个娘娘腔43 分钟前
【第七期】漏洞攻防-前端篇:XSS 与 CSRF —— 当浏览器成为攻击者的“肉鸡”
前端·xss·csrf
不吃鱼的羊1 小时前
DaVinci配置NVM模块
前端·javascript·网络