uniapp 大屏加载后端数据循环显示

该博客展示了如何在Vue.js应用中创建和使用卡片组件,包括环形图和数字翻转器,用于显示生产统计数据。数据通过HTTP POST请求获取,并每5秒更新一次。卡片组件包含今日产量和计划量的展示,以及百分比完成率的环形图。
摘要由CSDN通过智能技术生成
<template>
  <div class="bottom-charts">
    <div id="cards">
      <div
        class="card-item"
        v-for="(card, i) in cards"
        :key="card.title"
      >
        <div class="card-header">
          <div class="card-header-left">{{ card.title }}</div>
          <div class="card-header-right">{{ (i + 1) }}</div>
        </div>
        <dv-charts class="ring-charts" :option="card.ring" />
        <div class="card-footer">
          <div class="card-footer-item">
            <div class="footer-title">今日已产</div>
            <div class="footer-detail">
              <dv-digital-flop :config="card.total" style="width:70%;height:30px;" /></div>
          </div>
          <div class="card-footer-item">
            <div class="footer-title">今日计划</div>
            <div class="footer-detail">
              <dv-digital-flop :config="card.num" style="width:70%;height:35px;" /></div>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
export default {
  name: 'Cards',
  data () {
    return {
      cards: []
    }
  },
  methods: {
    createData () {
      let postData = this.$qs.stringify({
          date_type:2,//日期类型0:昨天,1:今天,2:本月,3:今年
        });
      var that = this;
      this.$http({
          method: 'post',
          url:'/screen/eachCompanyProduceTotal',
          data:postData
        }).then((res)=>{
          if(res.data.code === 200){
            console.log(res.data.data);
            //先给数组的每一项都填充为0,让这个数组有数据项,而不仅仅只有长度
            //再用 map 替换各个项为 new Object( )
            this.cards = new Array(res.data.data.length).fill(0).map((data, i) => ({
              title: res.data.data[i].name,
              total: {
                number: [res.data.data[i].value],
                content: '{nt}',
                textAlign: 'right',
                style: {
                  fill: '#ea6027',
                }
              },
              num: {
                number: [res.data.data[i].plan],
                content: '{nt}',
                textAlign: 'right',
                style: {
                  fill: '#26fcd8',
                }
              },
              ring: {
                series: [
                  {
                    type: 'gauge',
                    startAngle: -Math.PI / 2,
                    endAngle: Math.PI * 1.5,
                    arcLineWidth: 13,
                    radius: '70%',
                    data: [
                      { name: '完成率', value: res.data.data[i].percentage }
                    ],
                    axisLabel: {
                      show: false
                    },
                    axisTick: {
                      show: false
                    },
                    pointer: {
                      show: false
                    },
                    backgroundArc: {
                      style: {
                        stroke: '#224590'
                      }
                    },
                    details: {
                      show: true,
                      formatter: '完成率{value}%',
                      style: {
                        fill: '#EFF804',
                        fontSize: 15
                      }
                    }
                  }
                ],
                color: ['#03d3ec']
              }
            }))
          }
      });

    }
  },
  mounted () {
    const { createData } = this

    createData()

    this.timer = setInterval(() => {
      createData();
    }, 5000);
  }
}
</script>

<style lang="less">
.bottom-charts {
  width: 100%;
  height: 100%;
  display: flex;
  position: relative;

  .bc-chart-item {
    width: 25%;
    height: 100%;
    padding-top: 20px;
    box-sizing: border-box;
  }

  .bcci-header {
    height: 50px;
    text-align: center;
    line-height: 50px;
    font-size: 20px;
  }

  .dv-active-ring-chart {
    height: calc(~"100% - 80px");
  }

  .label-tag {
    height: 30px;
  }

  .active-ring-name {
    font-size: 18px !important;
  }

  .decoration-1, .decoration-2, .decoration-3 {
    display: absolute;
    left: 0%;
  }
}

#cards {
  display: flex;
  justify-content: space-between;
  height: 100%;
width: 100%;
  .card-item {
    background-color: rgba(6, 30, 93, 0.5);
    border-top: 2px solid rgba(1, 153, 209, .5);
    width: 40%;
    display: flex;
    flex-direction: column;
  }

  .card-header {
    display: flex;
    height: 20%;
    align-items: center;
    justify-content: space-between;

    .card-header-left {
      font-size: 18px;
      font-weight: bold;
      padding-left: 20px;
    }

    .card-header-right {
      padding-right: 20px;
      font-size: 30px;
      color: #03d3ec;
    }
  }

  .ring-charts {
    height: 35%;
  }

  .card-footer {
    height: 25%;
    display: flex;
    align-items: center;
    justify-content: space-around;
  }

  .card-footer-item {
    padding: 5px 10px 0px 10px;
    box-sizing: border-box;
    width: 40%;
    background-color: rgba(6, 30, 93, 0.7);
    border-radius: 3px;

    .footer-title {
      font-size: 15px;
      margin-bottom: 5px;
    }

    .footer-detail {
      font-size: 15px;
      color: #1294fb;
      display: flex;
      align-items: center;

      .dv-digital-flop {
        margin-right: 5px;
      }
    }
  }
}
</style>

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值