前端状态标识组件封装

实现效果

没有失败的截图,失败就是红色的点
在这里插入图片描述

组件封装

<template>
  <span class="badge">
    <span
      :class="{
        'badge-status-dot': !!status,
        [`badge-status-${status}`]: !!status
      }"
    />
    <span class="badge-status-text">{{ text }}</span>
  </span>
</template>

<script>
export default {
  name: 'status-badge',
  props: {
    status: String,
    text: String
  }
};
</script>

<style lang="scss" scoped>
$badge-status-size: 6px;
.badge {
  position: relative;
  display: inline-block;
  line-height: 1;
  color: unset;

  &-status {
    line-height: inherit;
    vertical-align: baseline;
    &-dot {
      width: $badge-status-size;
      height: $badge-status-size;
      display: inline-block;
      border-radius: 50%;
      vertical-align: middle;
      position: relative;
      top: -1px;
    }
    &-success {
      background-color: $--color-success;
    }
    &-processing {
      background-color: $--color-primary;
      position: relative;
      &:after {
        position: absolute;
        top: 0;
        left: 0;
        width: 100%;
        height: 100%;
        border-radius: 50%;
        border: 1px solid $--color-primary;
        content: '';
        animation: statusProcessing 1.2s infinite ease-in-out;
      }
    }
    &-default {
      background-color: $--color-info;
    }
    &-error {
      background-color: $--color-danger;
    }
    &-warning {
      background-color: $--color-warning;
    }
    &-text {
      margin-left: 8px;
    }
  }
}

@keyframes statusProcessing {
  0% {
    transform: scale(0.8);
    opacity: 0.5;
  }
  100% {
    transform: scale(2.4);
    opacity: 0;
  }
}
</style>

组件使用

  <status-badge
    :status="BUILD_STATUS_BADGE_MAP[getBuildStatus(row)]"
    :text="BUILD_STATUS_TEXT[getBuildStatus(row)]"
  ></status-badge>

颜色状态常量配置

export const BUILD_STATUS_TEXT = {
  [BUILD_STATUS.All]: '全部',
  [BUILD_STATUS.UNDO]: '未构建',
  [BUILD_STATUS.DOING]: '构建中',
  [BUILD_STATUS.FAIL]: '失败',
  [BUILD_STATUS.CANCEL]: '取消',
  [BUILD_STATUS.SUCCESS]: '成功'
};
export const BUILD_STATUS_BADGE_MAP = {
  [BUILD_STATUS.UNDO]: 'warning',
  [BUILD_STATUS.DOING]: 'processing',
  [BUILD_STATUS.FAIL]: 'error',
  [BUILD_STATUS.CANCEL]: 'default',
  [BUILD_STATUS.SUCCESS]: 'success '
};
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

胡肖一

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值