首页 > 其他分享 >Vue2 实现印章徽章组件

Vue2 实现印章徽章组件

时间:2023-10-30 14:45:46浏览次数:32  
标签:background stamp content width 徽章 Vue2 组件 ring badge

Vue2 实现印章徽章组件

需要实现的组件效果:

img

该组件有设置颜色、大小、旋转度数和文本内容功能。

一、组件实现代码

<template>
  <div
    class="first-ring"
    v-bind="getBindValue"
    :class="getStampBadgeClass"
    :style="{ transform: `rotate(${rotate}deg)` }"
  >
    <div class="second-ring" :class="getStampBadgeClass">
      <div class="third-ring" :class="getStampBadgeClass">
        <div class="forth-ring" :class="getStampBadgeClass">
          <div class="content-rectangle ellipsis" :class="getStampBadgeClass">
            <span class="">{{ content }}</span>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
  export default {
    name: "StampBadge",
    // inheritAttrs: false,
    props: {
      color: {
        type: String,
        default: "primary",
        validator: (v) =>
          ["primary", "error", "warning", "success", "info"].includes(v),
      },
      /**
       * stamp badge size.
       * @default: middle
       */
      size: {
        type: String,
        default: "middle",
        validator: (v) => ["large", "middle", "small"].includes(v),
      },
      /**
       * stamp badge rotate deg.
       * @default: 0
       */
      rotate: { type: Number, default: 0 },
      content: { type: String, default: "Unknown" },
    },
    computed: {
      getStampBadgeClass() {
        const { color, size } = this.$props;
        return [
          {
            [`stamp-badge-${color}`]: !!color,
            [`stamp-badge-${size}`]: !!size,
          },
        ];
      },
      getBindValue() {
        return { ...this.$attrs, ...this.$props };
      },
    },
    methods: {},
  };
</script>

<style lang="less" scoped>
  .first-ring {
    border-radius: 100px;
    display: flex;
    justify-content: center;
    align-items: center;
  }

  .second-ring {
    background: #fff;
    border-radius: 100px;
    display: flex;
    justify-content: center;
    align-items: center;
  }

  .third-ring {
    border-radius: 100px;
    display: flex;
    justify-content: center;
    align-items: center;
  }

  .forth-ring {
    background: #fff;
    border-radius: 100px;
    display: flex;
    justify-content: center;
    align-items: center;
    position: relative;
  }

  .content-rectangle {
    background: #fff;
    font-weight: bold;
    text-align: center;
    position: absolute;
  }

  .ellipsis {
    overflow: hidden;
    white-space: nowrap;
    text-overflow: ellipsis;
  }

  // primary
  .stamp-badge-primary.first-ring {
    background: #1890ff;
  }

  .stamp-badge-primary.third-ring {
    background: #1890ff;
  }

  .stamp-badge-primary.content-rectangle {
    border: 1px solid #1890ff;
    color: #1890ff;
  }

  // success
  .stamp-badge-success.first-ring {
    background: #52c41a;
  }

  .stamp-badge-success.third-ring {
    background: #52c41a;
  }

  .stamp-badge-success.content-rectangle {
    border: 1px solid #52c41a;
    color: #52c41a;
  }

  // error
  .stamp-badge-error.first-ring {
    background: #ff4d4f;
  }

  .stamp-badge-error.third-ring {
    background: #ff4d4f;
  }

  .stamp-badge-error.content-rectangle {
    border: 1px solid #ff4d4f;
    color: #ff4d4f;
  }

  // warning
  .stamp-badge-warning.first-ring {
    background: #faad14;
  }

  .stamp-badge-warning.third-ring {
    background: #faad14;
  }

  .stamp-badge-warning.content-rectangle {
    border: 1px solid #faad14;
    color: #faad14;
  }

  // info
  .stamp-badge-info.first-ring {
    background: #ccc;
  }

  .stamp-badge-info.third-ring {
    background: #ccc;
  }

  .stamp-badge-info.content-rectangle {
    border: 1px solid #ccc;
    color: #ccc;
  }

  // large
  .stamp-badge-large.first-ring {
    width: 84px;
    height: 84px;
  }

  .stamp-badge-large.second-ring {
    width: 80px;
    height: 80px;
  }

  .stamp-badge-large.third-ring {
    width: 74px;
    height: 74px;
  }

  .stamp-badge-large.forth-ring {
    width: 64px;
    height: 64px;
  }

  .stamp-badge-large.content-rectangle {
    width: 90px;
    font-size: 1.2rem;
  }

  // middle
  .stamp-badge-middle.first-ring {
    width: 64px;
    height: 64px;
  }

  .stamp-badge-middle.second-ring {
    width: 60px;
    height: 60px;
  }

  .stamp-badge-middle.third-ring {
    width: 56px;
    height: 56px;
  }

  .stamp-badge-middle.forth-ring {
    width: 48px;
    height: 48px;
  }

  .stamp-badge-middle.content-rectangle {
    width: 70px;
    font-size: 1rem;
  }

  // small
  .stamp-badge-small.first-ring {
    width: 54px;
    height: 54px;
  }

  .stamp-badge-small.second-ring {
    width: 50px;
    height: 50px;
  }

  .stamp-badge-small.third-ring {
    width: 46px;
    height: 46px;
  }

  .stamp-badge-small.forth-ring {
    width: 38px;
    height: 38px;
  }

  .stamp-badge-small.content-rectangle {
    width: 60px;
    font-size: 0.8rem;
  }
</style>

二、组件应用代码:

<div style="width: 500px; height: 100px; position: relative">
  <StampBadge
    style="position: absolute; top: 0; right: 0"
    size="middle"
    color="success"
    content="已支付"
    :rotate="45"
  />
</div>

标签:background,stamp,content,width,徽章,Vue2,组件,ring,badge
From: https://www.cnblogs.com/yuzhihui/p/17797793.html

相关文章

  • 短视频app源码,Flutter组件--搜索页面布局
    短视频app源码,Flutter组件--搜索页面布局 classLayoutDemoextendsStatelessWidget{ constLayoutDemo({Key?key}):super(key:key); @override Widgetbuild(BuildContextcontext){  returnPadding(   padding:constEdgeInsets.all(10),   c......
  • Java后端常用功能组件(持续更新)
    写项目时会存在大量的重复业务,不想重复的自己coding,就需要去cv。这里存放常用的功能代码,进行二次开发。说明这里只给出后端的代码,前端页面的请求用postman或其他应用。springboot应用结合目录与CTRL+f,可以快速定位到指定需求目录文件上传文件上传代码展示importl......
  • 基于Vue2+elementUI的二手书管理系统-计算机毕业设计源码+LW文档
    摘 要本设计完成了基于Vue2+elementUI的二手书管理系统的设计与实现。现代移动化网络发展下,不同于以往的短信、邮件、收音机传递信息,网页是向用户传输信息的主要媒介之一。书籍也是向人们传递信息和知识的媒介,如今书籍印刷和出版的快速发展,以及社会文化水平的进步,越来越多的读书......
  • springboot+vue2+element学生信息管理系统
    效果:  .vue<template><div><el-containerstyle="height:700px;border:1pxsolid#eee"><el-headerstyle="font-size:40px;background-color:rgb(238,241,246)">学生管理</el-header&......
  • React学习一:环境搭建、JSX基础、事件绑定、组件使用、样式控制
    一、概念React由Meta公司研发,是一个用于构建Web和原生交互界面的库。react中文文档地址:https://zh-hans.react.dev/learnReact的优势相较传统基于DOM开发的优势:组件化的开发方式;不错的性能相较于其他前端框架的优势:丰富的生态;跨平台支持二、环境搭建首先和vue项目一样,项目......
  • web前端(Vue2.x)接收H264实时视频码流(二进制)进行播放
    1、安装 [email protected]、.vue文件中使用<template><div><videoid="dom_id"muted="muted"controlsclass="video_box"></video><divv-if="!has_data"v-loading="!......
  • UniApp实战技巧:页面导航、数据传递和组件通信,以及资源管理和优化
    UniApp是一个基于Vue.js的开发框架,可以使用它快速构建跨平台的移动应用。本文将介绍UniApp中的一些实战技巧,包括页面导航、数据传递和组件通信。这些技巧可以帮助开发者更好地使用UniApp进行开发。1.页面导航在UniApp中,我们可以使用uni.navigateTo和uni.redirectTo等方法进行页面......
  • vue2和vue3的区别
    vue2和vue3都是前端JavaScript框架,基本概念和功能大部分都相同,它们的区别主要在语法、原理、生态以及打包四个方面.语法:Vue.js2使用基于Object.defineProperty的双向绑定来追踪变化,而Vue.js3采用Proxy来实现响应式变化追踪,这提高了性能并允许更广泛的响应式追踪。在Vue.js3......
  • BootstrapBlazor组件库,Table组件导出数据到剪切板
    BootstrapBlazor组件库,Table组件导出数据到剪切板解决方案使用ClipboardService将Table数据导出到剪切板中,并且可以直接粘贴到Excel。这里我直接采用ExportButtonDropdownTemplate添加了2个新的导出选项,一个是导出当前页,一个是导出所有页。Razor代码<TableTItem="Foo"......
  • [ApacheCommon组件使用-IO]关于JavaIO,相当输入的一个工具就是ApacheCommon-IO
    1.首先,如果你使用的是maven或者gradle建立的项目,maven只需要<!--https://mvnrepository.com/artifact/commons-io/commons-io--><dependency><groupId>commons-io</groupId><artifactId>commons-io</artifactId>......