自定义封装进度条标签

代码如下

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);
  })
}

效果展示

相关推荐
老虎06273 分钟前
JavaWeb前端(HTML,CSS具体案例)
前端·css·html
Mintopia9 分钟前
一个月速成 AI 工程师:从代码小白到智能工匠的修炼手册
前端·javascript·aigc
Mintopia12 分钟前
Next.js 全栈:接收和处理请求
前端·javascript·next.js
袁煦丞1 小时前
2025.8.18实验室【代码跑酷指南】Jupyter Notebook程序员的魔法本:cpolar内网穿透实验室第622个成功挑战
前端·程序员·远程工作
Joker Zxc1 小时前
【前端基础】flex布局中使用`justify-content`后,最后一行的布局问题
前端·css
无奈何杨1 小时前
风控系统事件分析中心,关联关系、排行、时间分布
前端·后端
Moment1 小时前
nginx 如何配置防止慢速攻击 🤔🤔🤔
前端·后端·nginx
晓得迷路了1 小时前
栗子前端技术周刊第 94 期 - React Native 0.81、jQuery 4.0.0 RC1、Bun v1.2.20...
前端·javascript·react.js
江城开朗的豌豆1 小时前
React Native 实战心得
javascript