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

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

仪表盘

开始是想着使用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) * idial[i].style.transform = 'rotate(' + angle + 'deg)'dial2[i].style.transform = 'rotate(' + angle + 'deg)'}},methods: {},watch: {speed(val) {this.carSpeed = vallet 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.xdnf.cn/news/148259.html

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

相关文章

多源最短路径的原理及C++实现

时间复杂度 O(n3),n是端点数。 核心代码 template<class T, T INF 1000 * 1000 * 1000> class CNeiBoMat { public: CNeiBoMat(int n, const vector<vector<int>>& edges,bool bDirectfalse,bool b1Base false) { m_vMat.assign(n, vector<…

2023年【R2移动式压力容器充装】模拟考试及R2移动式压力容器充装模拟考试题

题库来源&#xff1a;安全生产模拟考试一点通公众号小程序 R2移动式压力容器充装模拟考试考前必练&#xff01;安全生产模拟考试一点通每个月更新R2移动式压力容器充装模拟考试题题目及答案&#xff01;多做几遍&#xff0c;其实通过R2移动式压力容器充装操作证考试很简单。 1…

MySQL5.7版本与8.0版本在Ubuntu(WSL环境)系统安装

目录 前提条件 1. MySQL5.7版本在Ubuntu&#xff08;WSL环境&#xff09;系统安装 1. 1 下载apt仓库文件 1.2 配置apt仓库 1.3 更新apt仓库的信息 1.4 检查是否成功配置MySQL5.7的仓库 5. 安装MySQL5.7 1.6 启动MySQL 1.7 对MySQL进行初始化 1.7.1 输入密码 …

PDF文件压缩软件 PDF Squeezer mac中文版​软件特点

PDF Squeezer mac是一款macOS平台上的PDF文件压缩软件&#xff0c;可以帮助用户快速地压缩PDF文件&#xff0c;从而减小文件大小&#xff0c;使其更容易共享、存储和传输。PDF Squeezer使用先进的压缩算法&#xff0c;可以在不影响文件质量的情况下减小文件大小。 PDF Squeezer…

排序算法之【快速排序】

&#x1f4d9;作者简介&#xff1a; 清水加冰&#xff0c;目前大二在读&#xff0c;正在学习C/C、Python、操作系统、数据库等。 &#x1f4d8;相关专栏&#xff1a;C语言初阶、C语言进阶、C语言刷题训练营、数据结构刷题训练营、有感兴趣的可以看一看。 欢迎点赞 &#x1f44d…

[sping] spring core - 依赖注入

[sping] spring core - 依赖注入 所有代码实现基于 Spring Boot3&#xff0c;core 的概念很宽广&#xff0c;这里的 core concept 主要指的就是 Inversion of Control 和 Dependency Injection&#xff0c;其他的按照进度应该是会被放到其他的 section 记录 之前有写过 IoC 和…

MARS: An Instance-aware, Modular and Realistic Simulator for Autonomous Driving

MARS: An Instance-aware, Modular and Realistic Simulator for Autonomous Driving&#xff08;基于神经辐射场的自动驾驶仿真器&#xff09;https://github.com/OPEN-AIR-SUN/marshttps://arxiv.org/pdf/2307.15058.pdfhttps://mp.weixin.qq.com/s/6Ion_DZGJwzs8JOoWMMbPw …

Ubuntu基于Docker快速配置GDAL的Python、C++环境

本文介绍在Linux的Ubuntu操作系统中&#xff0c;基于Docker快速配置Python与C 这2种不同编程语言可用的地理数据处理库GDAL开发环境的方法。 本文就将Python与C 这2种不同编程语言的GDAL模块配置方法分开来介绍&#xff0c;大家依据自己的需求来选择即可——但无论是哪种方法&a…

计算机竞赛 目标检测-行人车辆检测流量计数

文章目录 前言1\. 目标检测概况1.1 什么是目标检测&#xff1f;1.2 发展阶段 2\. 行人检测2.1 行人检测简介2.2 行人检测技术难点2.3 行人检测实现效果2.4 关键代码-训练过程 最后 前言 &#x1f525; 优质竞赛项目系列&#xff0c;今天要分享的是 行人车辆目标检测计数系统 …

springmvc-JSR303进行服务端校验分组验证SpringMVC定义Restfull接口异常处理流程RestController异常处理

目录& 1. JSR303 2. JSR303中含有的注解 3. spring中使用JSR303进行服务端校验 3.1 导入依赖包 3.2 添加验证规则 3.3 执行校验 4. 分组验证 4.1 定义分组验证规则 4.2 验证时通过参数指定验证规则 4.3 验证信息的显示 5. SpringMVC定义Restfull接口 5.1 增加s…

opentelemetry、grafana、Prometheus、jaeger、victoria-metrics 介绍、关系与使用

Opentelemetry OTEL 是 OpenTelemetry 的简称&#xff0c; 是 CNCF 的一个可观测性项目&#xff0c;旨在提供可观测性领域的标准化方案&#xff0c;解决观测数据的数据模型、采集、处理、导出等的标准化问题&#xff0c;提供与三方 vendor 无关的服务。 OpenTelemetry 是一组标…

postgresql新特性之Merge

postgresql新特性之Merge 创建测试表测试案例 创建测试表 create table cps.public.test(id integer primary key,balance numeric,status varchar(1));测试案例 官网介绍 merge into test t using ( select 1 id,0 balance,Y status) s on(t.id s.id) -- 当匹配上了,statu…

TempleteMethod

TempleteMethod 动机 在软件构建过程中&#xff0c;对于某一项任务&#xff0c;它常常有稳定的整体操作结构&#xff0c;但各个子步骤却有很多改变的需求&#xff0c;或者由于固有的原因 &#xff08;比如框架与应用之间的关系&#xff09;而无法和任务的整体结构同时实现。如…

嵌入式Linux应用开发-驱动大全-同步与互斥①

嵌入式Linux应用开发-驱动大全-同步与互斥① 第一章 同步与互斥①1.1 内联汇编1.1.1 C语言实现加法1.1.2 使用汇编函数实现加法1.1.3 内联汇编语法1.1.4 编写内联汇编实现加法1.1.5 earlyclobber的例子 1.2 同步与互斥的失败例子1.2.1 失败例子11.2.2 失败例子21.2.3 失败例子3…

使用CrawlSpider爬取全站数据。

CrawpSpider和Spider的区别 CrawlSpider使用基于规则的方式来定义如何跟踪链接和提取数据。它支持定义规则来自动跟踪链接&#xff0c;并可以根据链接的特征来确定如何爬取和提取数据。CrawlSpider可以对多个页面进行同样的操作&#xff0c;所以可以爬取全站的数据。CrawlSpid…

【2023年11月第四版教材】第17章《干系人管理》(合集篇)

第17章《干系人管理》&#xff08;合集篇&#xff09; 1 章节内容2 管理基础3 管理过程3.1 管理的过程★★★ &#xff08;22上44&#xff09;3.2 管理ITTO汇总★★★ 4 过程1-识别干系人4.1 数据收集★★★4.3数据分析4.4 权力利益方格4.5 数据表现&#xff1a;干系人映射分析…

springmvc中DispatcherServlet关键对象

以下代码为 spring boot 2.7.15 中自带的 spring 5.3.29 RequestMappingInfo 请求方法相关信息封装&#xff0c;对应的信息解析在 RequestMappingHandlerMapping 的 createRequestMappingInfo() 中实现。 对于 RequestMapping 赋值的相关信息进行解析 protected RequestMappi…

零基础Linux_11(进程)进程程序替换+实现简单的shell

目录 1. 进程程序替换 1.1 程序替换原理 1.2 execl 接口 1.3 execv execlp execvp 1.4 exec 调各种程序 1.5 execle 接口 2. 实现简单的shell 2.1 打印提示和获取输入 2.2 拆开输入的命令和选项 2.3 创建进程和程序替换执行命令 2.4 内建命令实现路径切换 2.5 my…

创建GCP service账号并管理权限

列出当前GCP项目的所有service account 我们可以用gcloud 命令 gcloud iam service-accounts list gcloud iam service-accounts list DISPLAY NAME EMAIL DISABLED terraform …