[Uni-app] 微信小程序的圆环进度条

2024-03-19 12:44

本文主要是介绍[Uni-app] 微信小程序的圆环进度条,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

效果图:

组件完整代码如下:

<template><view class="base-style":style="'position: relative;width: ' + diameter + 'px;height: ' + diameter + 'px;display: flex;flex-direction: row;background-color: ' + bgColor + ';'"><!-- 左半圆和右半圆都要经历下面的5步:[第1步]第1层限定区域; [第2步]第2层决定显示一个整圆的左半边还是右半边; [第3步]第3层先使用激活颜色绘制一个圆环, 再添加一个同级且宽度为区域一半的盒子A;[第4步]在盒子A中再使用圆环底色绘制一个圆环, 此时整个圆环是 '左一半是激活颜色、右一半是圆环底色', 但这个圆环同时只能被看到一半;[第5步]旋转第2层。 --><!-- 左半圆 --><view class="base-style" :style="firstLayerViewStyle"><view :style="secondLayerViewStyle + secondLayerForLeft"><!-- 使用激活颜色绘制一个圆环。 --><view :style="thirdLayerStyle"></view><!-- 再使用背景色遮盖同级圆环的一半。 --><view class="base-style" :style="thirdLayerStyleForBg"><view :style="fourthLayerStyleForBg" /></view><view v-if="0 < ePercent && ePercent < 0.5" :style="endPointStyle + endPointStyleForLeft" /></view></view><!-- 右半圆 --><view class="base-style" :style="firstLayerViewStyle"><!-- 适配:为了避免右侧遮盖显示不全 此处向左多移动了1px --><view :style="secondLayerViewStyle + 'left: ' + (- diameter / 2 - 1) + 'px;' + secondLayerForRight"><!-- 使用激活颜色绘制一个圆环。 --><view :style="thirdLayerStyle"></view><!-- 再使用背景色遮盖同级圆环的一半。 --><view class="base-style" :style="thirdLayerStyleForBg"><view :style="fourthLayerStyleForBg" /></view><view v-if="ePercent > 0.5" :style="endPointStyle + endPointStyleForRight" /></view></view><view v-if="0.5 == ePercent" :style="endPointStyle + 'background-color: ' + this.hoopBgColor + ';'" /><!-- #ifdef APP-PLUS --><!-- 处理现象: 安卓App的顶部和底部会有一个小白点。 --><!-- <view v-if="ePercent > 0.5" :style="'position: absolute;top: 0;' + repairPointStyle" /> --><!-- <view v-if="1.0 == ePercent" :style="'position: absolute;bottom: 0;' + repairPointStyle" /> --><!-- #endif --></view>
</template><!-- 组件名称: 圆环进度条。启发地址: https://www.cnblogs.com/jr1993/p/4677921.html 。编者信息: 867003077@qq.com 。 -->
<script>export default {name: 'progressCircle',props: {// 背景色(不宜设置为透明 否则 需要 在 左thirdLayer 的外面 再嵌套一个盒子)。bgColor: {type: String,default: '#FFFFFF'},// 圆环的外直径(单位px)。diameter: {type: Number,default: 250},// 圆环线条的厚度(单位px)。hoopThickness: {type: Number,default: 8},// 圆环底色(灰色的圆环)。hoopBgColor: {type: String,// default: 'transparent'default: '#F3F3F3'},// 圆环激活部分的颜色。hoopColor: {type: String,default: '#FF4C20'},// 圆环进度百分比值(其值范围在0到1之间)。percent: {type: [Number, String],default: 0,validator: val => {return val >= 0 && val <= 1;},},animate: {type: Boolean,default: false,},},data() {return {targetPercent: 0,ePercent: 0,showTimer: undefined,};},watch: {percent: {handler: function() {console.log('progressCircle_watch_percent', this.percent);this.loadData();},},},computed: {firstLayerViewStyle() {return 'position: relative;width: ' + (this.diameter / 2) +'px;height: ' + this.diameter + 'px;';},secondLayerViewStyle() {return 'box-sizing: border-box;position: absolute;top: 0;width: ' + this.diameter +'px;height: ' + this.diameter + 'px;';},thirdLayerStyle() {return 'box-sizing: border-box;width: ' + this.diameter + 'px;height: ' + this.diameter +'px;border-radius: ' + (this.diameter / 2) +'px;border-width: ' + this.hoopThickness +'px;border-style: solid;border-color: ' + this.hoopColor + ';';},thirdLayerStyleForBg() {return 'box-sizing: border-box;position: absolute;top: 0;left: ' + (this.diameter / 2) + 'px;width: ' +this.diameter + 'px;height: ' + this.diameter + 'px;background-color: ' + this.bgColor + ';';},fourthLayerStyleForBg() {return 'box-sizing: border-box;margin-left: ' + (-this.diameter / 2) + 'px;width: ' + this.diameter +'px;height: ' +this.diameter + 'px;border-radius: ' + (this.diameter / 2) + 'px;border-width: ' +this.hoopThickness + 'px;border-style: solid;border-color: ' + this.hoopBgColor + ';';},secondLayerForLeft() {let angle = 0;if (this.ePercent < 0.5) {angle += (180 * (this.ePercent - 0.5) / 0.5);}// #ifdef APP-PLUSreturn 'left: 0;transform: rotate(' + angle + 'deg);';// #endif// #ifdef MP-WEIXINreturn 'left: 0;transform: rotate(' + angle + 'deg);-webkit-transform: rotate(' + angle + 'deg);';// #endif},secondLayerForRight() {let angle = 0;if (this.ePercent > 0.5) {angle += (180 * (this.ePercent - 0.5) / 0.5);}// #ifdef APP-PLUSreturn 'right: 0;transform: rotate(' + angle + 'deg);';// #endif// #ifdef MP-WEIXINreturn 'right: 0;transform: rotate(' + angle + 'deg);-webkit-transform: rotate(' + angle + 'deg);';// #endif},// repairPointStyle() {// 	return 'left: ' + (this.diameter - this.hoopThickness) / 2 + 'px;width: ' +// 		this.hoopThickness + 'px;height: ' + this.hoopThickness + 'px;border-radius: ' +// 		this.hoopThickness / 2 + 'px;background-color: ' + this.hoopColor + ';';// },endPointStyle() {// 结束点圆心圈直径。const _circleCenterRadius = 2;return 'box-sizing: border-box;position: absolute;top: 0;left: ' + (this.diameter - this.hoopThickness) / 2 +'px;width: ' +this.hoopThickness + 'px;height: ' + this.hoopThickness + 'px;border-radius: ' + (this.hoopThickness / 2) +'px;border-width: ' + (this.hoopThickness / 2 - _circleCenterRadius) +'px;border-style: solid;border-color: ' +this.hoopColor + ';';},endPointStyleForLeft() {return 'background-color: ' + ((this.ePercent > 0.5) ? this.hoopColor : this.hoopBgColor) + ';';},endPointStyleForRight() {return 'background-color: ' + ((1 == this.ePercent) ? this.hoopColor : this.hoopBgColor) + ';';},},mounted() {console.log('progressCircle_mounted');this.loadData();},methods: {loadData() {this.targetPercent = parseFloat(this.percent);console.log('progressCircle_loadData');if (!this.animate) {this.ePercent = this.targetPercent;} else {let _this = this;this.ePercent = 0;this.showTimer && clearInterval(this.showTimer);this.showTimer = setInterval(() => {let tempPercent = _this.ePercent + 0.1;if (tempPercent < _this.targetPercent) {_this.ePercent = tempPercent;return;};_this.ePercent = _this.targetPercent;clearInterval(_this.showTimer);}, 200);}}}}
</script><style scoped>.base-style {box-sizing: border-box;/* 溢出隐藏 */overflow: hidden;}
</style>

调用页面:

<template><view class="my-page-container" :style="{ 'height': pageBoxH + 'px' }" @click="currentPercent=0.8"><progress-circle class="mine-member-level-progress" :diameter="180" :hoopThickness="10" :hoopColor="'orange'":percent="currentPercent" :animate="true" /></view>
</template><script>/** 演示页面 */import progressCircle from "@/components/progress-circle/index.vue";// import {//   queryDetail,// } from '@/api/mine.js';export default {name: 'myDemo',components: {progressCircle,},data() {return {pageBoxH: 1000,currentPercent: 0.25,};},beforeCreate() {console.log('beforeCreate enter');},created() {console.log('created enter');},mounted() {console.log('mounted enter');},onLoad(option) {console.log('onLoad enter');},onReady() {},methods: {},}
</script><style scoped>.my-page-container {background-color: white;box-sizing: border-box;padding: 10px 10px 50px 10px;display: flex;flex-direction: column;}
</style>

这篇关于[Uni-app] 微信小程序的圆环进度条的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/826034

相关文章

Python基于微信OCR引擎实现高效图片文字识别

《Python基于微信OCR引擎实现高效图片文字识别》这篇文章主要为大家详细介绍了一款基于微信OCR引擎的图片文字识别桌面应用开发全过程,可以实现从图片拖拽识别到文字提取,感兴趣的小伙伴可以跟随小编一... 目录一、项目概述1.1 开发背景1.2 技术选型1.3 核心优势二、功能详解2.1 核心功能模块2.

python编写朋克风格的天气查询程序

《python编写朋克风格的天气查询程序》这篇文章主要为大家详细介绍了一个基于Python的桌面应用程序,使用了tkinter库来创建图形用户界面并通过requests库调用Open-MeteoAPI... 目录工具介绍工具使用说明python脚本内容如何运行脚本工具介绍这个天气查询工具是一个基于 Pyt

Ubuntu设置程序开机自启动的操作步骤

《Ubuntu设置程序开机自启动的操作步骤》在部署程序到边缘端时,我们总希望可以通电即启动我们写好的程序,本篇博客用以记录如何在ubuntu开机执行某条命令或者某个可执行程序,需要的朋友可以参考下... 目录1、概述2、图形界面设置3、设置为Systemd服务1、概述测试环境:Ubuntu22.04 带图

Python程序打包exe,单文件和多文件方式

《Python程序打包exe,单文件和多文件方式》:本文主要介绍Python程序打包exe,单文件和多文件方式,具有很好的参考价值,希望对大家有所帮助,如有错误或未考虑完全的地方,望不吝赐教... 目录python 脚本打成exe文件安装Pyinstaller准备一个ico图标打包方式一(适用于文件较少的程

Python程序的文件头部声明小结

《Python程序的文件头部声明小结》在Python文件的顶部声明编码通常是必须的,尤其是在处理非ASCII字符时,下面就来介绍一下两种头部文件声明,具有一定的参考价值,感兴趣的可以了解一下... 目录一、# coding=utf-8二、#!/usr/bin/env python三、运行Python程序四、

如何基于Python开发一个微信自动化工具

《如何基于Python开发一个微信自动化工具》在当今数字化办公场景中,自动化工具已成为提升工作效率的利器,本文将深入剖析一个基于Python的微信自动化工具开发全过程,有需要的小伙伴可以了解下... 目录概述功能全景1. 核心功能模块2. 特色功能效果展示1. 主界面概览2. 定时任务配置3. 操作日志演示

Redis迷你版微信抢红包实战

《Redis迷你版微信抢红包实战》本文主要介绍了Redis迷你版微信抢红包实战... 目录1 思路分析1.1hCckRX 流程1.2 注意点①拆红包:二倍均值算法②发红包:list③抢红包&记录:hset2 代码实现2.1 拆红包splitRedPacket2.2 发红包sendRedPacket2.3 抢

无法启动此程序因为计算机丢失api-ms-win-core-path-l1-1-0.dll修复方案

《无法启动此程序因为计算机丢失api-ms-win-core-path-l1-1-0.dll修复方案》:本文主要介绍了无法启动此程序,详细内容请阅读本文,希望能对你有所帮助... 在计算机使用过程中,我们经常会遇到一些错误提示,其中之一就是"api-ms-win-core-path-l1-1-0.dll丢失

SpringBoot后端实现小程序微信登录功能实现

《SpringBoot后端实现小程序微信登录功能实现》微信小程序登录是开发者通过微信提供的身份验证机制,获取用户唯一标识(openid)和会话密钥(session_key)的过程,这篇文章给大家介绍S... 目录SpringBoot实现微信小程序登录简介SpringBoot后端实现微信登录SpringBoo

uniapp小程序中实现无缝衔接滚动效果代码示例

《uniapp小程序中实现无缝衔接滚动效果代码示例》:本文主要介绍uniapp小程序中实现无缝衔接滚动效果的相关资料,该方法可以实现滚动内容中字的不同的颜色更改,并且可以根据需要进行艺术化更改和自... 组件滚动通知只能实现简单的滚动效果,不能实现滚动内容中的字进行不同颜色的更改,下面实现一个无缝衔接的滚动