智慧园区前端大屏
shuishen
2024-12-17 a07f79573d52f61ba6ec97766e9abc12309eadee
src/views/survey/components/box/fireContent.vue
@@ -2,11 +2,11 @@
 * @Author: shuishen 1109946754@qq.com
 * @Date: 2024-11-04 16:32:04
 * @LastEditors: shuishen 1109946754@qq.com
 * @LastEditTime: 2024-11-05 17:42:44
 * @LastEditTime: 2024-12-03 12:57:49
 * @FilePath: \bigScreen\src\views\survey\components\box\fireContent.vue
 * @Description:
 *
 * Copyright (c) 2024 by shuishen, All Rights Reserved.
 * @Description:
 *
 * Copyright (c) 2024 by shuishen, All Rights Reserved.
-->
<script setup>
import { useEchartsResize } from 'hooks/useEchartsResize'
@@ -15,25 +15,28 @@
let $echarts = inject('echarts')
const curEcharts = ref(null)
let myEcharts = reactive(null)
let myEcharts = reactive({
  chart: ''
})
let typeLevel = [
  {
    name: '低',
    name: '暂定',
    itemStyle: {
      color: '#31B5FF'
      color: '#ADADAD'
    }
  },
  {
    name: '一般',
    itemStyle: {
      color: '#FFFF00'
      color: '#FFC000'
    }
  },
  {
    name: '较大',
    itemStyle: {
      color: '#FFC000'
      color: '#F4090F'
    }
  },
  {
@@ -46,119 +49,97 @@
function getRiskSource () {
  getRiskSourceStatistic().then(res => {
    let xaxis_data = []
    let yaxis_data = []
    let seriesData = []
    res.data.data.forEach(element => {
      xaxis_data.push(element.riskLevel)
      yaxis_data.push({
        name: element.riskLevel,
        value: element.num
    let data = res.data.data
    let dataRsult = []
    var total = 0
    data.forEach(item => {
      dataRsult.push({
        name: item.riskLevel,
        value: item.num,
        itemStyle: typeLevel.find(i => i.name == item.riskLevel).itemStyle
      })
      seriesData.push({
        name: element.riskLevel,
        type: 'bar',
        data: [],
        barWidth: '30',
        barGap: '-100%',
        itemStyle: typeLevel.find(i => i.name == element.riskLevel).itemStyle
      })
      total = total + item.num
    })
    seriesData = seriesData.map(item => {
      return {
        ...item,
        data: yaxis_data.map(i => {
          return i.name == item.name ? i.value : 0
        })
      }
    })
    myEcharts.setOption({
      legend: {
        data: xaxis_data,
        top: "5%",
        right: "5%",
    myEcharts.chart.setOption({
      title: {
        text: "总数",
        subtext: String(total),
        textStyle: {
          color: '#fff'
        }
          fontSize: 16,
          color: "#fff",
          lineHeight: 20,
        },
        subtextStyle: {
          fontSize: 28,
          color: "#fff",
        },
        textAlign: "center",
        left: "62%",
        // right: "43%",
        top: "36%",
      },
      tooltip: {
        axisPointer: {
          type: 'shadow'
        }
      legend: {
        orient: "vertical",
        top: "40%",
        left: "5%",
        textStyle: {
          color: "#fff",
        },
      },
      grid: {
        top: '16%',
        top: '6%',
        left: '6%',
        right: '6%',
        bottom: '6%',
        containLabel: true
      },
      xAxis: [
        {
          type: 'category',
          data: xaxis_data,
          nameTextStyle: {
            color: '#fff'
          },
          axisLine: {
            lineStyle: {
              color: '#fff'
            }
          },
          axisTick: {
            alignWithLabel: true,
            lineStyle: {
              color: '#fff'
            }
          },
          axisLabel: {
            color: '#fff'
          },
        }
      ],
      tooltip: {
        trigger: 'item'
      },
      yAxis: [
      series: [
        {
          type: 'value',
          nameTextStyle: {
            color: '#fff'
          // name: 'Access From',
          type: 'pie',
          left: '-5%',
          radius: ['45%', '75%'],
          data: dataRsult,
          left: "25%",
          label: {
            show: false,
          },
          axisLine: {
            lineStyle: {
              color: '#fff'
            }
          },
          axisTick: {
            lineStyle: {
              color: '#fff'
            }
          },
          axisLabel: {
            color: '#fff'
          labelLine: {
            show: false,
          },
        }
      ],
      series: seriesData
      ]
    })
  })
}
nextTick(() => {
  myEcharts = $echarts.init(curEcharts.value)
  myEcharts.chart = $echarts.init(curEcharts.value)
  getRiskSource()
})
const echartsResize = () => {
  myEcharts && myEcharts.resize()
  myEcharts.chart && myEcharts.chart.resize()
}
useEchartsResize(echartsResize)
onUnmounted(() => {
  if (myEcharts.chart) {
    myEcharts.chart.clear()
    myEcharts.chart.dispose()
    myEcharts.chart = null
  }
})
</script>
<template>
@@ -167,4 +148,4 @@
  </div>
</template>
<style lang="scss" scoped></style>
<style lang="scss" scoped></style>