index.vue 8.05 KB
<!-- 首页 -->
<template>
  <d2-container class="indexPage">
    <div class="show-num">
      <div class="w-40">
        <div class="num-block">
          <p class="num">{{ TopNumberData.customerCount || 0 }}</p>
          <p>注册客户数量</p>
        </div>
        <div class="num-block">
          <p class="num">{{ TopNumberData.deviceCount || 0 }}</p>
          <p>出货设备数量</p>
        </div>
      </div>
      <div class="w-60">
        <div class="grid-content bg-purple">
          <div
            class="chart"
            id="decivceType"
          ></div>
        </div>
      </div>
    </div>
    <!-- <div class="show-num">
      <div class="num-block">
        <p>{{ TopNumberData.customerCount || 0 }}</p>
        <p>注册客户数量</p>
      </div>
      <div class="num-block">
        <p>{{ TopNumberData.deviceCount || 0 }}</p>
        <p>接入设备数量</p>
      </div>
      <div class="num-block">
        <p>{{ TopNumberData.userCount || 0 }}</p>
        <p>注册用户数量</p>
      </div>
      <div class="num-block">
        <p>{{ TopNumberData.apiCallCount || 0 }}</p>
        <p>服务调用次数</p>
      </div>
    </div> -->

    <!-- <el-row :gutter="40">
      <div class="charts">
        <el-col
          :span="12"
          style="padding-right: 10px;"
        >
          <div class="grid-content bg-purple">
            <div
              class="chart"
              id="decivceType"
            ></div>
          </div>
        </el-col>

        <el-col
          :span="12"
          style="padding-left: 10px;"
        >
          <div class="grid-content bg-purple">
            <div
              class="chart"
              id="serviceType"
            ></div>
          </div>
        </el-col>
      </div>
    </el-row> -->

    <p class="Trend">设备接入趋势</p>
    <div
      id="AccessTrend"
      style="width: 100%; height: 400px"
    ></div>

    <!-- <p class="Trend">服务调用趋势</p>
    <div
      id="CallTrend"
      style="width: 100%; height: 400px"
    ></div> -->
  </d2-container>
</template>

<script>
import _ from 'lodash'
import echarts from 'echarts'
import walden from './walden'
import { getStatisticData, getGraphData, getPolylineData } from '@api/api'
export default {
  name: 'index',
  data() {
    return {
      radio: '全部',
      TopNumberData: {},
      message: '',

      // 绘图

      option: {
        title: {
          top: '20',
          text: '',
          subtext: '',
          left: '20'
        },
        tooltip: {
          trigger: 'item',
          formatter: '{a} <br/>{b} : {c} ({d}%)'
        },
        legend: {
          orient: 'vertical',
          left: 'right',
          padding: [50, 50, 50, 0],
          data: []
        },
        series: [
          {
            name: '访问来源',
            type: 'pie',
            radius: '55%',
            center: ['50%', '60%'],
            data: [],
            emphasis: {
              itemStyle: {
                shadowBlur: 10,
                shadowOffsetX: 0,
                shadowColor: 'rgba(0, 0, 0, 0.5)'
              }
            }
          }
        ]
      },
      Trendoption: {
        tooltip: {
          trigger: 'axis'
        },
        xAxis: {
          type: 'category',
          data: []
        },
        yAxis: {
          type: 'value'
        },
        series: [
          {
            data: [],
            type: 'line'
          }
        ]
      }
    }
  },

  mounted() {
    // 初始化各表实例
    this.$echarts = echarts
    this.totalECharts = this.$echarts.init(document.getElementById('decivceType'), 'walden')
    // this.totalEChart2 = this.$echarts.init(document.getElementById('serviceType'), 'walden')
    this.trendCharts = this.$echarts.init(document.getElementById('AccessTrend'), 'walden')
    // this.apiCallCharts = this.$echarts.init(document.getElementById('CallTrend'), 'walden')

    // this.getPie()

    // 获取顶部数据
    getStatisticData({}).then((res) => {
      this.TopNumberData = res
      //  console.log( this.TopNumberData)
      this.TopNumberData.customerCount = this.formatNumber(res.customerCount)
      this.TopNumberData.deviceCount = this.formatNumber(res.deviceCount)
      this.TopNumberData.userCount = this.formatNumber(res.userCount)
      this.TopNumberData.apiCallCount = this.formatNumber(res.apiCallCount)
    })

    // 获取饼状图数据
    getGraphData({}).then((res) => {
      this.chartData = res
      // console.log(res)
      // 修改特定的数值,注意数组和对象的区别
      // 左图
      var option1 = _.cloneDeep(this.option)
      option1.title.text = '设备类型分布'
      option1.legend.data = res.deviceGraphData.map((item) => item.deviceType)

      option1.series[0].data = res.deviceGraphData.map((item) => {
        return {
          value: item.num,
          name: item.deviceType
        }
      })

      this.totalECharts.setOption(option1)
      window.onresize = this.totalECharts.resize

      // 右图
      // var option2 = _.cloneDeep(this.option)
      // option2.title.text = '调用服务类型分布'
      // var formatData = res.apiCallGraphData.map((item) => {
      //   return {
      //     1: '授权管理',
      //     2: '设备管理',
      //     3: '数据服务'
      //   }[item.apiClassification]
      // })

      // option2.legend.data = formatData
      // option2.series[0].data = res.apiCallGraphData.map((item) => {
      //   return {
      //     value: item.num,
      //     name: {
      //       1: '授权管理',
      //       2: '设备管理',
      //       3: '数据服务'
      //     }[item.apiClassification]
      //   }
      // })

      // this.totalEChart2.setOption(option2)
      // window.onresize = this.totalEChart2.resize
    })

    // 折线图数据获取

    getPolylineData({}).then((res) => {
      // 接入设备折线图
      var option3 = _.cloneDeep(this.Trendoption)
      option3.xAxis.data = res.deviceAccessTrendList.map((item) => item.activatTime)

      option3.series[0].data = res.deviceAccessTrendList.map((item) => {
        return {
          value: item.num
        }
      })
      this.trendCharts.setOption(option3)

      // 服务调用趋势
      // var option4 = _.cloneDeep(this.Trendoption)
      // option4.xAxis.data = res.apiCallTrendList.map((item) => item.createTime)
      // option4.series[0].data = res.apiCallTrendList.map((item) => item.num)

      // this.apiCallCharts.setOption(option4)
    })
  },

  methods: {

    // 每隔三位加一个逗号
    formatNumber(n) {
      var b = parseInt(n).toString()
      var len = b.length
      if (len <= 3) {
        return b
      }
      var r = len % 3
      return r > 0
        ? b.slice(0, r) + ',' + b.slice(r, len).match(/\d{3}/g).join(',')
        : b.slice(r, len).match(/\d{3}/g).join(',')
    }
  }
}
</script>
<style>
.indexPage {
  overflow-y: scroll;
}
:root {
  overflow-y: auto;
  overflow-x: hidden;
}
:root body.indexPage {
  position: absolute;
}
body.indexPage {
  width: 100vw;
  overflow: hidden;
}

.show-num {
  display: flex;
}
.show-num .w-40 {
  width: 40%;
  height: 400px;
}
.show-num .w-60 {
  width: 60%;
  height: 400px;
}
.show-num .num-block {
  /* width: 25%; */
  height: 47.8%;
  font-size: 16px;
  text-align: center;
  margin: 0 16px 16px 0;
  border: 1px solid #999999;
}
.show-num .num-block .num {
  padding-top: 34px;
  font-size: 25px;
  font-weight: bold;
}
.show-num .num-block:last-child {
  margin-bottom: 0px;
}
.indexPage .el-row {
  margin-bottom: 20px;
  margin-top: 20px;
}
.indexPage .el-row:last-child {
  margin-bottom: 0;
}

.el-col {
  border-radius: 1px;
}
.bg-purple-dark {
  background: white;
}
.bg-purple {
  background: white;
}
.bg-purple-light {
  background: white;
}
.grid-content {
  border-radius: 4px;
  min-height: 36px;
  min-width: 100px;
}
.row-bg {
  padding: 10px 0;
  background-color: #f9fafc;
}

.Trend {
  padding: 0px;
  margin: 0px;
  margin-left: 30px;
  margin-top: 50px;
  margin-bottom: -20px;
}
.charts {
  display: flex;
}
.chart {
  border: 1px solid #999999;
  width: 100%;
  height: 400px;
  min-width: 100px;
}
</style>