可以动态改变刻度背景色的车速仪表盘

news2024/10/6 12:30:39

最近做的项目的主页面需要用到一个仪表盘来动态显示车速,同时改变对应的背景色

仪表盘

开始是想着使用echarts,修修改改拿来用,但是人家客户有规定,必须搞个差不多的,那没办法,自
己动手搞个吧
截图如下:
这是人家的
在这里插入图片描述
这是我搞出来的
在这里插入图片描述
这样看着似乎差不多了哈,客户没提啥意见,搞定
接下来是代码,考虑到代码的复用性,封装成了件,及引入的方法,因为要适配不同电脑的分辨率,所以使用了把px根据比例全部换成了rem,这里的1rem=80px,若是不想使用rem,可以把数值乘以80,然后把rem换成px就可以了

代码思路
首先是让UI小伙伴扣了两张图
yibiao5.png
在这里插入图片描述
yibiaoBoot.png
在这里插入图片描述
1.然后根据找好最外层的父级,根据定位把图片和文字的位置搞个差不多;
2.接着就是刻度了,可以看到刻度是有两层的,外面有一层,里面有一层,这些刻度我想着前端动态生成,然后给这些刻度设置一个默认背景色,然后我就可以通过style样式控制背景色,我看了原图上面的刻度是64个,然后底部有16个是不变色的,被遮罩住了,所以通过css3的旋转,改变下角度,然后只控制其余48个刻度即可,
3.因为最大的速度是200,所以根据200/48即可得出,1速度等于多少个刻度
封装仪表盘组件
代码如下

<template>
  <div class="data-left-1">
    <div class="box_style">
      <div class="mybox_wrap">
        <div class="yibiao_style">
          <div class="clock_box">
            <div class="clock_dial"></div>
            <div class="clock_dial2"></div>
          </div>
          <div class="yibiao_boot"></div>
          <div class="yibiao_speed">{{ carSpeed }}</div>
          <div class="yibiao_span">速度(km/h)</div>
          <div class="yibiao_max">200</div>
        </div>
      </div>
    </div>
  </div>
</template>
<script>
export default {
  props: {
    isShow: {
      type: Boolean,
      default: true,
    },
    speed: {
      type: Number,
      default: 0,
    },
    rate: {
      default: 0,
    },
  },
  data() {
    return {
      carSpeed: 0, //列车速度
      showTabulation: true,
    }
  },
  computed: {
  },
  mounted() {
    let clock_dial = document.querySelector('.clock_dial')
    let clock_dial2 = document.querySelector('.clock_dial2')
    //1 制作表盘
    for (let i = 0; i < 64; i++) {
      var div = document.createElement('div')
      div.setAttribute('class', 'dial')
      div.innerHTML = '<span></span>'
      clock_dial.appendChild(div)
    }
    let dial = document.querySelectorAll('.dial')
    for (let i = 0; i < dial.length; i++) {
      dial[i].style.position = 'absolute'
      dial[i].style.width = '0.125rem'
      dial[i].style.height = '100%'
      dial[i].style.top = '0'
      dial[i].style.left = '0.625rem'
    }
    let dialSpan = document.querySelectorAll('.dial span')
    for (let i = 0; i < dialSpan.length; i++) {
      dialSpan[i].style.width = '0.05rem'
      dialSpan[i].style.height = '0.125rem'
      dialSpan[i].style.background = '#699B9A';
      dialSpan[i].style.backgroundImage = ''
      dialSpan[i].style.display = 'inline-block'
      dialSpan[i].style.verticalAlign = 'top'
      dialSpan[i].style.borderRadius = '0.0125rem'
    }
    for (let i = 0; i < 64; i++) {
      var div = document.createElement('div')
      div.setAttribute('class', 'dial2')
      div.innerHTML = '<span></span>'
      clock_dial2.appendChild(div)
    }
    let dial2 = document.querySelectorAll('.dial2')
    for (let i = 0; i < dial2.length; i++) {
      dial2[i].style.position = 'absolute'
      dial2[i].style.width = '0.125rem'
      dial2[i].style.height = '100%'
      dial2[i].style.top = '0'
      dial2[i].style.left = '0.5rem'
    }
    let dialSpan2 = document.querySelectorAll('.dial2 span')
    for (let i = 0; i < dialSpan2.length; i++) {
      dialSpan2[i].style.width = '0.0375rem'
      dialSpan2[i].style.height = '0.0625rem'
      dialSpan2[i].style.background = '#699B9A'
      dialSpan2[i].style.backgroundImage = ''
      dialSpan2[i].style.display = 'inline-block'
      dialSpan2[i].style.verticalAlign = 'top'
      dialSpan2[i].style.borderRadius = '0.0125rem'
    }
    for (let i = 0; i < dial.length; i++) {
      var angle = (360 / 64) * i
      dial[i].style.transform = 'rotate(' + angle + 'deg)'
      dial2[i].style.transform = 'rotate(' + angle + 'deg)'
    }
  },
  methods: {},
  watch: {
    speed(val) {
      this.carSpeed = val
      let basicParam = 200 / 48;
      let dialSpan = document.querySelectorAll('.dial span')
      let dialSpan2 = document.querySelectorAll('.dial2 span')
      let actNum = Math.ceil(this.carSpeed / basicParam);
      for(let m=0;m<48;m++){
        dialSpan[m].style.background = "#699B9A";
        dialSpan2[m].style.background = "#699B9A";
      }
      if (this.carSpeed > 0&&this.carSpeed <100) {
        for (let i = 0; i < actNum; i++) {
          dialSpan[i].style.background = "#43EDEA"
          dialSpan2[i].style.background = "#43EDEA"
        }
      }else{
        for (let i = 0; i < 24; i++) {
          dialSpan[i].style.backgroundImage = "linear-gradient(to right,#43EDEA,#359EC7)"
          dialSpan2[i].style.backgroundImage = "linear-gradient(to right,#43EDEA,#359EC7)"
        }
        for (let j = 24; j< actNum; j++) {
          dialSpan[j].style.backgroundImage = "linear-gradient(to right,#359EC7,#3B87F3)"
          dialSpan2[j].style.backgroundImage = "linear-gradient(to right,#359EC7,#3B87F3)"
        }
      }
    },
    isShow(val) {
      console.log(val)
      this.showTabulation = val
    },
  },
}
</script>
<style scoped lang="less">
//字体资源,若是没有的话,可以去掉这行代码
//@font-face {
//  font-family: 'son';
//  src: url('~@/assets/font/son.ttf') format('truetype');
//}

.yibiao_speed {
  position: absolute;
  left: 34%;
  top: 37%;
  font-size: 0.375rem;
  width: 0.75rem;
  height: 0.45rem;
  text-align: center;
}
.yibiao_span {
  position: absolute;
  left: 22%;
  top: 72%;
  font-size: 0.175rem;
  width: 1.3rem;
  height: 0.45rem;
  text-align: center;
  z-index: 1000;
}
.yibiao_max {
  position: absolute;
  left: 66%;
  top: 63%;
  font-size: 0.225rem;
  width: 0.75rem;
  height: 0.45rem;
  text-align: center;
}

.yibiao_style {
  width: 2.25rem;
  height: 2.25rem;
  background-image: url(~@/assets/3d2/yibiao5.png);
  background-size: cover;
  position: relative;
  color: #fff;
}
.data-left-1 {
  width: 100%;
  height: 2.375rem;
  // padding: 0.1rem;
  display: flex;
  box-sizing: border-box;
  box-sizing: border-box;
  justify-content: center;
  // align-items: center;
  margin-bottom: 0.0625rem;
}
.mybox_wrap {
  width: 100%;
  height: 100%;
  display: flex;
  justify-content: center;
  align-items: center;
}

.box_style {
  width: 2.25rem;
  height: 2.25rem;
}
.clock_box {
  width: 1.4375rem;
  height: 1.4375rem;
  border-radius: 50%;
  position: absolute;
  left: 0.375rem;
  top: 0.375rem;
}

.clock_dial,
.clock_dial2 {
  width: 100%;
  height: 100%;
  position: relative;
  -moz-transform-origin: center center;
  -webkit-transform-origin: center center;
  -o-transform-origin: center center;
  transform-origin: center center;
  text-align: center;
  transform: rotate(-132deg);
}

.clock_dial2 {
  width: 1.0625rem;
  height: 1.0625rem;
  top: 0.2375rem;
  left: 0.2375rem;;
  transform: rotate(-132deg);
  position: absolute;
}
.clock_dial div {
  position: absolute;
  width: 0.125rem;
  height: 100%;
  top: 0;
  left: 0.625rem;
}

.dial,
.dial2 {
  position: absolute;
  width: 0.125rem;
  height: 100%;
  top: 0;
  left: 0.625rem;
}

.dial2 {
  width: 0.125rem;
  left: 0.5rem;
}

.dial span,
.dial2 span {
  width: 0.05rem;
  height: 0.125rem;
  background: #699b9a;
  display: inline-block;
  vertical-align: top;
  border-radius: 0.0125rem;
}

.dial2 span {
  width: 0.0375rem;
  height:0.0625rem;
}

.yibiao_boot {
  width: 1.25rem;
  height: 0.875rem;
  background-image: url(~@/assets/3d2/yibiaoBoot.png);
  background-size: contain;
  color: #fff;
  position: absolute;
  z-index: 666;
  bottom: 0;
  left: 0.5rem;
  opacity: 0.9;
  background-repeat: no-repeat;
}
</style>

页面中使用

<dashboard ref="dashboardwe" :speed="carSpeed" :rate="carRate">
        </dashboard>
import dashboard from './modules/dashboard' //仪表盘组件

data() {
    return {
      carSpeed: 0, //列车速度
     carRate: 0,//百分比
     }
}
 let that = this;
 that.carRate = 100 / 200 * 100;//测试数据
 that.carSpeed = Math.floor(Math.random()*200);//测试数据

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.coloradmin.cn/o/1045011.html

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈,一经查实,立即删除!

相关文章

【目标检测】——Gold-YOLO为啥能超过YOLOV8

华为 https://arxiv.org/pdf/2309.11331.pdf 文章的出发点&#xff1a;FPN中的信息传输问题 1. 简介 基于全局信息融合的概念&#xff0c;提出了一种新的收集和分发机制&#xff08;GD&#xff09;&#xff0c;用于在YOLO中进行有效的信息交换。通过全局融合多层特征并将全局信…

AIGC玩转卡通化技术实践

FaceChain写真开源项目插播&#xff1a; 最新 FaceChain支持多人合照写真、上百种单人写真风格&#xff0c;项目信息汇总&#xff1a;ModelScope 魔搭社区 。 github开源直达&#xff08;觉得有趣的点个star哈。&#xff09;&#xff1a;https://github.com/modelscope/…

护眼灯显色指数应达多少?眼科医生推荐灯光显色指数多少合适

台灯的显色指数是其非常重要的指标&#xff0c;它可以表示灯光照射到物体身上&#xff0c;物体颜色的真实程度&#xff0c;一般用平均显色指数Ra来表示&#xff0c;Ra值越高&#xff0c;灯光显色能力越强。常见的台灯显色指数最低要求一般是在Ra80以上即可&#xff0c;比较好的…

Spring进阶(AOP的应用)—— 动态代理AOP后controller层的private方法访问失效的问题

前言 动态代理&#xff0c;面向切面编程AOP&#xff08;Aspect Oriented Programming&#xff09;作为spring中的一个重点和难点&#xff0c;需要不断深入理解&#xff0c;并且在项目中学习如何灵活应用。 本篇博客介绍动态代理AOP在实际应用中遇到的private方法访问失效的问…

亚马逊电动玩具UL696的测试报告办理

在亚马逊平台销售的电子产品&#xff0c;要符合指定的标准&#xff0c;如果不合格很容易发生起火&#xff0c;爆炸等危及消费者生命财产的安全&#xff0c;因此很多客户因为缺少UL报告&#xff0c;导致产品被下架&#xff0c;销售权被移除等问题&#xff0c;也少不了同行之间的…

leetCode 63.不同路径II 动态规划 + 空间复杂度优化 一维dp

63. 不同路径 II - 力扣&#xff08;LeetCode&#xff09; 一个机器人位于一个 m x n 网格的左上角 &#xff08;起始点在下图中标记为 “Start” &#xff09;。 机器人每次只能向下或者向右移动一步。机器人试图达到网格的右下角&#xff08;在下图中标记为 “Finish”&…

.NET Core nuget 组件的安装、更新、卸载

上面的 NuGet\ 是可以省略的。 更新 Update-Package xxx 卸载 Uninstall-Package xxx Uninstall-Package Newtonsoft.Json

400G QSFP-DD FR4 与 400G QSFP-DD FR8光模块:哪个更适合您的网络需求?

QSFP-DD 光模块随着光通信市场规模的不断增长已成为400G市场中客户需求量最高的产品。其中400G QSFP-DD FR4和400G QSFP-DD FR8光模块都是针对波分中距离传输&#xff08;2km&#xff09;的解决方案&#xff0c;它们之间有什么不同&#xff1f;应该如何选择应用&#xff1f;飞速…

SpringBoot 学习(二)配置

2. SpringBoot 配置 2.1 配置文件类型 配置文件用于修改 SpringBoot 的默认配置。 2.1.1 properties 文件 **properties ** 是属性文件后缀。 文件名&#xff1a;application.properties 只能保存键值对。 基础语法&#xff1a;keyvalue namewhy注入配置类 Component //…

Java基于SpringBoot的民宿管理系统,附源码

博主介绍&#xff1a;✌程序员徐师兄、7年大厂程序员经历。全网粉丝30W、csdn博客专家、掘金/华为云/阿里云/InfoQ等平台优质作者、专注于Java技术领域和毕业项目实战✌ 文章目录 开发环境&#xff1a;后端&#xff1a;前端&#xff1a;数据库&#xff1a; 系统架构&#xff1a…

Vue computed计算属性购物车实例

效果演示 对于computed的计算属性可以通过这个购物车例子来了解&#xff0c;笔者最近很是疲累&#xff0c;真的不想过多解释了&#xff0c;还请读者自行看代码研究。 参考代码 <!DOCTYPE html> <html lang"en"> <head><meta charset"U…

数据库管理-第107期 Relocating PDB(20230927)

数据库管理-第107期 Relocating PDB&#xff08;20230927&#xff09; 在我长期的blog生涯&#xff0c;当需要迁移PDB的时候&#xff0c;出现了几种方式&#xff0c;基本上就是在线克隆或者datapump&#xff0c;然而这两种方式都需要一定的停机时间。在数据库版本一致的情况下…

Redis 数据类型底层原理

String 内部编码有三种&#xff1a;int、embstr、raw int&#xff1a;如果一个字符串对象保存的是整数值&#xff0c;并且这个整数值可以用 long类型来表示(不超过 long 的表示范围&#xff0c;如果超过了 long 的表示范围&#xff0c;那么按照存储字符串的编码来存储&#xf…

notepad++配置python2环境

&#xff08;1&#xff09;python2版本下载&#xff1a;Index of /ftp/python/2.7.8/https://www.python.org/ftp/python/2.7.8/ &#xff08;2&#xff09; 配置notepad环境 1.打开Notepad&#xff0c;点击“插件”-“插件管理器”&#xff0c;在“可用”选项卡中&#xff0c…

使用Process Monitor工具探测日志文件是程序哪个模块生成的

目录 1、问题描述 2、使用Process Monitor监测目标文件是哪个模块生成的思路说明 3、操作Process Monitor监测日志文件是哪个模块生成的 4、通过screenctach.dll库的时间戳&#xff0c;找到其pdb文件&#xff0c;然后去查看详细的函数调用堆栈 5、最后 VC常用功能开发汇总…

C++编程入门与提高:学习策略与技巧

&#x1f482; 个人网站:【工具大全】【游戏大全】【神级源码资源网】&#x1f91f; 前端学习课程&#xff1a;&#x1f449;【28个案例趣学前端】【400个JS面试题】&#x1f485; 寻找学习交流、摸鱼划水的小伙伴&#xff0c;请点击【摸鱼学习交流群】 摘要&#xff1a;C是一门…

淘宝商品sku信息抓取接口api

在电商行业中&#xff0c;SKU是一个经常被使用的术语&#xff0c;但是对于很多人来说&#xff0c;这个词可能还比较陌生。在这篇文章中&#xff0c;我们将详细解释什么是SKU&#xff0c;以及在电商业务中它的作用和意义。 什么是SKU&#xff1f; SKU是“Stock Keeping Unit”…

Ubuntu 20.04编译GPMP2过程记录

前言 GPMP2是董靖博士等人在16-17年提出的结合GTSAM因子图框架与Gaussian Processes完成motion planning的一项工作。前身源于Barfoot教授的课题组提出的STEAM(Simultaneous Trajectory Estimation and Mapping)问题及其相关工作。在提出董靖博士提出GPMP2后&#xff0c;borgl…

1400*B. Two Buttons(BFS)

解析&#xff1a; 每次一个点有两种情况&#xff0c;-1 和 *2 两种情况&#xff0c;直接 BFS 即可。 #include<bits/stdc.h> using namespace std; const int N2e55; int n,m,vis[N],cnt[N]; void bfs(){queue<int>q;vis[n]1;q.push(n);while(q.size()){auto tq.f…

使用低代码实现一个表单页面 ------ XinBuilder

平台介绍 如果你不是一个前端开发&#xff0c;但是想要实现出一个前端页面。 那么就可以通过低代码的方式&#xff0c;拖拽和配置出你想要的页面。 而XinBuilder就是简单的一套低代码平台&#xff0c;你可以在上面拖拽出自己想要使用的组件并进行配置。使用方式也很简单。 这…