feat:完善舆情监测功能

This commit is contained in:
zjc
2024-12-26 13:46:27 +08:00
parent 50a6b06381
commit 809c950301
11 changed files with 192 additions and 139 deletions

View File

@@ -8,7 +8,7 @@
<template #dropdown>
<el-dropdown-menu>
<el-dropdown-item v-for="(item, index) in options" :key="index" :command="item">
<span class="label"> {{ item.label }}</span>
<span class="label"> {{ item.ssname }}</span>
</el-dropdown-item>
</el-dropdown-menu>
</template>
@@ -27,8 +27,10 @@
default: () => []
}
})
let emit = defineEmits(['on-change'])
const handleCommand = (command) => {
console.log(command)
emit('on-change', command)
}
</script>

View File

@@ -8,10 +8,10 @@
/>
</template>
<script setup>
import * as echarts from 'echarts'
import styleUtil from '@/utils/styleUtil'
import { fitChartSize } from '@/utils/dataUtil'
import { guid } from '@/utils/util'
import { useEchart } from '@/hooks/echart'
const props = defineProps({
width: {
type: Number,
@@ -38,9 +38,8 @@
default: () => {}
}
})
const { id, setOption, initChart } = useEchart()
let id = ref(guid())
let lineChart = null
let timer = null
let currentIndex = -1
@@ -64,14 +63,14 @@
valueStr += `<div>${item.seriesName}${item.value}</div>`
})
let str = `<div style="
background: #07356B;
border: 1px solid #0096FF;
color: #fff;
font-weight: 600;
font-size: ${fitChartSize(16)}px;
border-radius: ${fitChartSize(4)}px;
padding: ${fitChartSize(4)}px ${fitChartSize(12)}px;">
${valueStr}</div>`
background: #07356B;
border: 1px solid #0096FF;
color: #fff;
font-weight: 600;
font-size: ${fitChartSize(16)}px;
border-radius: ${fitChartSize(4)}px;
padding: ${fitChartSize(4)}px ${fitChartSize(12)}px;">
${valueStr}</div>`
return str
}
},
@@ -131,20 +130,8 @@
},
series: []
}
watch(
() => props.data,
(val) => {
if (val.length > 0) {
setTimeout(() => {
initChart()
}, 500)
}
},
{ immediate: true }
)
const initChart = () => {
const dom = document.getElementById(id.value)
lineChart = echarts.init(dom)
const init = () => {
initChart()
defaultConfig.xAxis.data = props.xAxisData
props.data.map((item, index) => {
defaultConfig.series.push({
@@ -163,53 +150,28 @@
})
defaultConfig.legend.data.push(item.name)
})
lineChart.setOption({
setOption({
...defaultConfig,
...props.config
})
// // 开启轮播
// startTooltipLoop()
// // 鼠标悬浮,停止轮播
// dom.addEventListener('mousemove', () => {
// console.log('mouse move')
// closeSwitchTooltip()
// })
// // 鼠标离开,继续轮播
// dom.addEventListener('mousedown', () => {
// console.log('mouse down')
// startTooltipLoop()
// })
// 监听窗口大小变化
window.addEventListener('resize', resize)
}
const resize = () => {
if (lineChart) {
lineChart.dispose()
lineChart = null
initChart()
}
}
// // 切换tooltip
// const switchTooltip = () => {
// // 取消之前高亮的图形
// lineChart.dispatchAction({
// chart.value.dispatchAction({
// type: 'downplay',
// seriesIndex: 0,
// dataIndex: currentIndex
// })
// currentIndex = (currentIndex + 1) % 8
// // 高亮当前图形
// lineChart.dispatchAction({
// chart.value.dispatchAction({
// type: 'highlight',
// seriesIndex: 0,
// dataIndex: currentIndex
// })
// // 显示tooltip
// lineChart.dispatchAction({
// chart.value.dispatchAction({
// type: 'showTip',
// seriesIndex: 0,
// dataIndex: currentIndex

View File

@@ -9,10 +9,9 @@
</template>
<script setup>
import * as echarts from 'echarts'
import styleUtil from '@/utils/styleUtil'
import { fitChartSize } from '@/utils/dataUtil'
import { guid } from '@/utils/util'
import { useEchart } from '@/hooks/echart'
const props = defineProps({
width: {
@@ -32,12 +31,16 @@
dataList: {
type: Array,
default: () => []
},
total: {
type: Number,
default: () => 0
}
})
let id = ref(guid())
let pieChart = null
var colorList = ['#FDC40A', '#FF5232', '#50F0A6', '#5FDFFA', '']
const { id, chart, setOption, initChart } = useEchart()
var colorList = ['#FDC40A', '#FF5232', '#50F0A6', '#5FDFFA']
var defaultCofig = {
color: colorList,
@@ -45,16 +48,12 @@
orient: 'vertical',
bottom: 'center',
left: '70%',
data: [],
itemWidth: fitChartSize(16),
itemHeight: fitChartSize(16),
itemGap: fitChartSize(10),
formatter: (name) => {
return name + '\u3000' + '19%'
},
itemWidth: fitChartSize(20),
itemHeight: fitChartSize(20),
itemGap: fitChartSize(20),
textStyle: {
color: '#ffffff',
fontSize: fitChartSize(12)
fontSize: fitChartSize(20)
}
},
series: [
@@ -71,7 +70,7 @@
position: 'center',
fontWeight: 'bold',
formatter: function (o) {
return `{value|123456}` + '\n' + `{name|整改率}`
return `{value|123456}` + '\n' + `{name|舆情总数 }`
},
rich: {
value: {
@@ -94,30 +93,24 @@
]
}
const initChart = () => {
const dom = document.getElementById(id.value)
pieChart = echarts.init(dom)
defaultCofig.series[0].data = props.dataList
pieChart.setOption({
...defaultCofig,
...props.config
})
// 监听窗口大小变化
window.addEventListener('resize', resize)
}
const resize = () => {
if (pieChart) {
pieChart.dispose()
pieChart = null
initChart()
}
}
watch(
() => props.dataList,
(newVal) => {
if (newVal.length > 0) {
nextTick(() => {
initChart()
defaultCofig.legend.formatter = (name) => {
let percent = props.dataList.find((item) => item.name == name).value
return name + '\u3000' + `${percent}%`
}
defaultCofig.series[0].data = props.dataList
defaultCofig.series[0].label.formatter = () => {
return `{value|${props.total}}` + '\n' + `{name|舆情总数 }`
}
setOption({
...defaultCofig,
...props.config
})
})
}
},