• uniapp中实现圆形进度条的方式有哪些?


    前言

            在uniapp开发小程序或者apk时,页面需要用到一个圆形进度条(带文字和百分比的),自己也自定义过一个,但是有一点小问题,咱先展示如何引入插件市场的在介绍自定义的!一共四种,但是你需要考虑自己的兼容性!

    正文

    一、插件市场

    1.进入DCloud插件市场:DCloud 插件市场

    2.找到了一款和自己需求符合的,兼容性也是比较好的,做uniapp项目是需要考虑和测试兼容性的,只有真机上能看的出来,模拟器不一定看的出来!!!圆形进度条 

    3.下载插件并导入HBuilderX

    4.点击之后需要登录账号密码,然后导入到你uniapp中的uni_modules文件夹下,这个文件夹下面不需要引入页面在引入了。

    5.页面中使用组件:

    1. <l-circularProgress :fontShow="false" bgColor="#f2f2f2" :lineWidth="10" boxWidth="90" boxHeight="90" progressColor="#7ef22e"
    2. :percent="80" style="position: relative;">
    3. <view class="centerTxtSpecial" style="position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%);">
    4. <view class="numSpecial">80%view>
    5. <view class="txtSpecial">性能view>
    6. view>
    7. l-circularProgress>

    css代码

    1. .centerTxtSpecial {
    2. position: absolute;
    3. top: 50%;
    4. left: 47%;
    5. transform: translate(-50%, -50%);
    6. text-align: center;
    7. }
    8. .numSpecial {
    9. font-size: 30rpx;
    10. font-family: Arial;
    11. /* font-weight: bold; */
    12. color: #008000;
    13. }
    14. .txtSpecial {
    15. font-size: 28rpx;
    16. font-family: PingFang SC;
    17. font-weight: 400;
    18. color: #999;
    19. margin-top: 8rpx;
    20. }

    6、效果如下

    二、自定义组件:

    1.html代码

    1. <div v-for="(item,index) in dataList" :key="index" class="setBorder" @click="handledetail(item)">
    2. /**主要内容*/
    3. <view class="circlecontent">
    4. <view class="circleprogress">
    5. <view class="progresstext">
    6. {{item.percent}}%
    7. <text style="font-size: 12px; width: 100%;">
    8. 性能
    9. text>
    10. view>
    11. <view class="wrapper">
    12. <view class="leftprogress" :style="{ transform: 'rotate('+(item.percent * 3.6 <= 180 ? -45 : -45+(item.percent * 3.6-180))+'deg)'}">view>
    13. view>
    14. <view class="wrapper">
    15. <view class="rightprogress" :style="{ transform: 'rotate('+(item.percent * 3.6 <= 180 ? 45 + item.percent * 3.6 : 45+180)+'deg)'}">view>
    16. view>
    17. view>
    18. view>
    19. div>

    2.js代码

    1. leftprogress: 'rotate(-45deg)',
    2. rightprogress: 'rotate(45deg)',
    3. dataList: []

    3.css代码

    1. .circlecontent {
    2. width: 80px;
    3. display: flex;
    4. justify-content: center;
    5. flex-flow: wrap;
    6. align-items: center;
    7. border-radius: 50%;
    8. text-align: center;
    9. height: 80px;
    10. position: relative;
    11. }
    12. .circleprogress {
    13. width: 80px;
    14. height: 80px;
    15. display: flex;
    16. justify-content: center;
    17. }
    18. .circleprogress .progresstext {
    19. position: absolute;
    20. font-size: 12px;
    21. width: 50px;
    22. display: flex;
    23. justify-content: center;
    24. align-items: center;
    25. color: #008000;
    26. flex-wrap: wrap;
    27. top: 45%;
    28. left: 15%;
    29. transform: translateY(-50%);
    30. }
    31. .circleprogress .wrapper {
    32. width: 80px;
    33. height: 80px;
    34. overflow: hidden;
    35. }
    36. .circleprogress .leftprogress,
    37. .rightprogress {
    38. width: 70px;
    39. height: 70px;
    40. border: 10px solid #eee;
    41. border-bottom: 10px solid #7ef22e;
    42. border-radius: 50%;
    43. }
    44. .circleprogress .leftprogress {
    45. border-right: 10px solid #7ef22e;
    46. }
    47. .circleprogress .rightprogress {
    48. border-left: 10px solid #7ef22e;
    49. margin-left: -40px;
    50. }

    4.效果:

    这个兼容性都没问题,但是有个缺角!

    三、第三方自定义组件:

    uniapp圆环进度条组件_环形进度条组件-CSDN博客

            问题:canvas层级高,目前覆盖文字信息没有展示!只有环形展示出来了!

    四、uview官方组件

    1.html

    1. <u-circle-progress active-color="#7ef22e" :percent="item.percent">
    2. <view class="centerTxtSpecial">
    3. <div class="numSpecial">{{item.percent}}%div>
    4. <text class='txtSpecial'>性能text>
    5. view>
    6. u-circle-progress>

    2.js引入组件

            看你自己文件位置,不能完全copy

    1. import uCircleProgressVue from "../../../components/owner/u-circle-progress.vue";
    2. export default {
    3. components: {
    4. 'u-circle-progress': uCircleProgressVue
    5. }
    6. }

    3.这个官方的在安卓手机上apk无法正常显示,小程序都是ok的!

    总结

            个人是很推荐和支持第一种的,canvas绘制图形很丝滑,但是也有层级很高的问题!原生虽然兼容性很好,但是可能并没有那么流程!你也可以尝试自己做好用的组件出来!

  • 相关阅读:
    刘未鹏 - 我在南大的七年 有感
    【C++初阶】类和对象(三)
    Junit 超时测试
    SpringBoot整合Redis、Redis、Jedis,Redis使用场景示例、面试点理论
    总结——》【Redis】
    C++中带默认值的函数参数
    MybatisPLUS,根据时间作为条件进行查询
    WEIXIN day_08(8.25) 学子影院项目实践4
    MapReduce核心原理(下)
    基于智能合约的银行借贷方案设计与实现
  • 原文地址:https://blog.csdn.net/XU441520/article/details/134499580