Newer
Older
smartKitchenFront / src / views / dashboard / components / deviceList.vue
<template>
  <div class="container">
    <div v-for="(item, index) of device" class="device" :key="item.title">
      <div class="content">
        <div><svg-icon :icon-class="item.icon"></svg-icon></div>
        <div class="count">{{ item.count }}</div>
      </div>
      <div class="title">{{ item.title }}</div>
    </div>
  </div>
</template>

<script>
import SvgIcon from "@/components/SvgIcon";
import { getDeviceInfo } from "@/api/cockpit/cockpit";
export default {
  name: "deviceList",
  components: {
    SvgIcon,
  },
  data() {
    return {
      device: [
        {
          title: "设备总数",
          count: "",
          icon: "cockpit-device-total",
          type: "total",
        },
        {
          title: "IOT设备数量",
          count: "",
          icon: "cockpit-lot-count",
          type: "iot",
        },
        {
          title: "IOT设备在线率",
          count: "",
          icon: "cockpit-lot-online",
          type: "iotRatio",
        },
      ],
    };
  },
  methods: {
    fetchData() {
      // 获取设备总数、IOT设备数量、IOT设备在线率
      getDeviceInfo().then((res) => {
        for (var i = 0; i < this.device.length; i++) {
          for (var device in res.data) {
            if (this.device[i].type === device) {
              this.device[i].count = res.data[device];
            }
          }
        }
      });
    },
  },
  created() {
    this.fetchData();
  },
};
</script>

<style lang="scss" scoped>
.container {
  padding: 10px;
  padding-bottom: 0px;
  display: flex;
  justify-content: space-between;
  color: #2076a1;
  font-size: 14px;
  font-weight: 700;

  .device {
    flex: 1;
    .content {
      display: flex;
      justify-content: space-around;
      // padding: 5px;
      align-items: center;
      .count{
        font-size: 20px;
      }
      ::v-deep .svg-icon {
        width: 40px;
        height: 40px;
      }
    }
  }
  .title{
    text-align: center;
    // padding:10px ;
    margin-top: 5px;
  }
}
</style>