123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279 |
- <template>
- <div class="eventStat">
- <div class="eventStat-header">
- <el-card>
- <template #header>
- <div class="event-category">
- <span>监控点位违反统计</span>
- <el-radio-group v-model="eventDateType" @change="getBarData" size="small">
- <el-radio-button label="今天" value="1" />
- <el-radio-button label="近7天" value="7" />
- <el-radio-button label="近30天" value="30" />
- </el-radio-group>
- </div>
- </template>
- <BaseChart width="100%" height="250px" :option="barOptions" />
- </el-card>
- <el-card>
- <template #header>
- <div class="event-category">
- <span>区域违法分布</span>
- <el-radio-group v-model="regionDateType" @change="getPieData" size="small">
- <el-radio-button label="今天" value="1" />
- <el-radio-button label="近7天" value="7" />
- <el-radio-button label="近30天" value="30" />
- </el-radio-group>
- </div>
- </template>
- <BaseChart width="100%" height="250px" :option="pieOptions" />
- </el-card>
- </div>
- <el-card style="margin-top: 10px;">
- <template #header>
- <div class="event-category">
- <span>每分钟{{ formatDict(eventType) }}统计</span>
- <el-select v-model="eventType" @change="getLineData">
- <el-option v-for="item in eventTypeOptions" :key="item.dictValue" :label="item.dictLabel"
- :value="item.dictValue" />
- </el-select>
- </div>
- </template>
- <BaseChart width="100%" height="250px" :option="lineOptions" />
- </el-card>
- </div>
- </template>
- <script setup lang="ts">
- import BaseChart from '@/components/BaseChart/index.vue'
- import { pointEventsStat, regionEventsStat, minuteEventsStat } from '@/api/sense/events/index'
- import { getDicts } from '@/api/system/dict/data/index'
- const pieData = ref([])
- const barData = ref([])
- const lineData = ref([])
- const eventTypeOptions = ref([])
- const eventType = ref('1')
- const eventDateType = ref('1')
- const regionDateType = ref('1')
- const pieOptions = computed(() => {
- let options = {
- tooltip: {
- trigger: 'item'
- },
- legend: {
- orient: 'vertical',
- top: '8%',
- right: 0,
- itemWidth: 10,
- itemHeight: 10,
- itemGap: 10
- },
- grid: {
- },
- series: [
- {
- type: 'pie',
- radius: '50%',
- data: pieData.value,
- center: ['40%', '50%'],
- emphasis: {
- itemStyle: {
- shadowBlur: 10,
- shadowOffsetX: 0,
- shadowColor: 'rgba(0, 0, 0, 0.5)'
- }
- }
- }
- ]
- };
- return options
- })
- const barOptions = computed(() => {
- const colors = [
- "#FF5733",
- "#7B3F00",
- "#FFC300",
- "#DAF7A6",
- "#FF5733",
- "#008080",
- "#E8EAF6",
- "#FFEEC1",
- "#B39DDB",
- "#4CAF50"
- ];
- const barObj = {}
- barData.value.forEach(item => {
- barObj[item.area_name] = item.event_count
- })
- let options = {
- tooltip: {
- trigger: 'axis',
- axisPointer: {
- type: 'shadow'
- }
- },
- grid: {
- left: '5%',
- right: '3%',
- bottom: 0,
- top: '6%',
- containLabel: true
- },
- xAxis: {
- type: 'category',
- data: Object.keys(barObj),
- axisLabel: {
- interval: 0,
- // rotate: 15 // 表示倾斜的角度
- }
- },
- yAxis: {
- type: 'value'
- },
- series: [
- {
- data: Object.values(barObj),
- type: 'bar',
- barWidth: 20,
- itemStyle: {
- color: (params) => {
- return colors[params.dataIndex]
- }
- },
- label: {
- show: true, // 显示数值
- position: 'top' // 在顶部显示
- }
- }
- ]
- };
- return options
- })
- const lineOptions = computed(() => {
- const xData = lineData.value.map(item => item.time_format)
- const yData = lineData.value.map(item => item.count)
- const options = {
- tooltip: {
- trigger: 'axis',
- appendToBody: true
- },
- grid: {
- left: '1%',
- right: '3%',
- bottom: 0,
- top: '22%',
- containLabel: true
- },
- xAxis: {
- type: 'category',
- axisLabel: {
- show: true,
- // interval: 0,//横轴信息全部显示
- // margin: 5, //刻度标签与轴线之间的距离
- },
- data: xData
- },
- yAxis: {
- type: 'value'
- },
- series: [
- // {
- // name: '',
- // type: 'line',
- // symbol: 'circle', // 默认是空心圆(中间是白色的),改成实心圆
- // showAllSymbol: true,
- // symbolSize: 0,
- // data: yData
- // }
- {
- name: '',
- data: yData,
- type: 'pictorialBar',
- barMinHeight: 50,
- barCategoryGap: '80%',
- symbol: 'path://M0,10 L10,10 C5.5,10 5.5,5 5,0 C4.5,5 4.5,10 0,10 z',
- itemStyle: {
- normal: {
- color: '#65B1E9'
- }
- },
- },
- ]
- };
- return options
- })
- onMounted(() => {
- getPieData()
- getBarData()
- getLineData()
- getDicts('event_type').then(({ code, data }) => {
- if (code === 200) {
- eventTypeOptions.value = data || []
- }
- })
- })
- const getPieData = () => {
- regionEventsStat({ dateType: regionDateType.value }).then(({ code, data }) => {
- if (code === 200) {
- pieData.value = data || []
- }
- })
- }
- const getBarData = () => {
- pointEventsStat({ dateType: eventDateType.value }).then(({ code, data }) => {
- if (code === 200) {
- barData.value = data || []
- }
- })
- }
- const getLineData = () => {
- minuteEventsStat({ eventType: eventType.value }).then(({ code, data }) => {
- if (code === 200) {
- lineData.value = data || {}
- }
- })
- }
- const formatDict = (val) => {
- let name = ''
- eventTypeOptions.value.forEach(item => {
- if (item.dictValue === val) {
- name = item.dictLabel
- }
- })
- return name
- }
- </script>
- <style lang="scss" scoped>
- .eventStat {
- padding: 10px;
- height: 100%;
- background-color: #F0F2F5;
- position: relative;
- }
- .event-category {
- display: flex;
- align-items: center;
- justify-content: space-between;
- .el-select {
- width: 250px;
- }
- }
- .eventStat-header {
- display: flex;
- .el-card {
- flex: 1;
- &:not(:first-child) {
- margin-left: 10px;
- }
- }
- }
- </style>
|