feat(关系图): 优化关系图交互并增加点击高亮功能

- 增加点击表格行高亮相关节点的功能
- 优化关系图布局和样式,根据选中状态调整参数
- 为图表元素添加指针样式提升交互体验
- 清理调试用的console.log语句
- 扩展颜色数组和月份选项
This commit is contained in:
yindongqi 2025-08-11 17:44:47 +08:00
parent 34f0b3eba9
commit 1241191f38

View File

@ -485,15 +485,15 @@ const navigation = ref({
// modules使 // modules使
const modules = [Autoplay, Pagination, Navigation, Scrollbar]; const modules = [Autoplay, Pagination, Navigation, Scrollbar];
const prevEl = () => { const prevEl = () => {
console.log("上一张"); // console.log("");
}; };
const nextEl = () => { const nextEl = () => {
console.log("下一张"); // console.log("");
}; };
// swiper // swiper
const onSlideChange = (swiper: any) => { const onSlideChange = (swiper: any) => {
// swiperswiperactiveIndex // swiperswiperactiveIndex
console.log(swiper.activeIndex, "活动swiper更改"); // console.log(swiper.activeIndex, "swiper");
}; };
const swiperBoxHeight = ref("300px"); const swiperBoxHeight = ref("300px");
@ -555,35 +555,35 @@ const monthOptions = [
value: "5", value: "5",
label: "五月", label: "五月",
}, },
// { {
// value: "6", value: "6",
// label: "", label: "六月",
// } }
// , ,
// { {
// value: "7", value: "7",
// label: "", label: "七月",
// }, },
// { {
// value: "8", value: "8",
// label: "", label: "八月",
// }, },
// { {
// value: "9", value: "9",
// label: "", label: "九月",
// }, },
// { {
// value: "10", value: "10",
// label: "", label: "十月",
// }, },
// { {
// value: "11", value: "11",
// label: "", label: "十一月",
// }, },
// { {
// value: "12", value: "12",
// label: "", label: "十二月",
// }, },
]; ];
//"" //""
@ -664,15 +664,26 @@ const districtOptions = [
const webPageBackgroundColor = "#F0F0F0"; const webPageBackgroundColor = "#F0F0F0";
// //
const echartsColorArray = [ const echartsColorArray = [
"#5470c6", '#5470C6',
"#91cc75", '#91CC75',
"#fac858", '#FAC858',
"#ee6666", '#EE6666',
"#73c0de", '#73C0DE',
"#3ba272", '#3BA272',
"#fc8452", '#FC8452',
"#9a60b4", '#9A60B4',
"#ea7ccc", '#EA7CCC',
'#27727B',
'#FE8463',
'#9BCA63',
'#FAD860',
'#F3A43B',
'#60C0DD',
'#D7504B',
'#C6E579',
'#F4E001',
'#F0805A',
'#26C0C0'
]; ];
// const echartsColorArray = ['#FF00FF', '#00FF00']; // const echartsColorArray = ['#FF00FF', '#00FF00'];
@ -1576,7 +1587,7 @@ const echarts2 = () => {
var svg = d3 var svg = d3
.select(main2.value) .select(main2.value)
.append("svg") .append("svg")
.attr("width", windowWidth.value * 0.23) .attr("width", windowWidth.value * 0.24)
.attr("height", (windowHeight.value - 100 - 3 * 4) / 3); .attr("height", (windowHeight.value - 100 - 3 * 4) / 3);
// //
@ -1648,6 +1659,7 @@ const echarts2 = () => {
return echartsColorArray[randomIndex]; return echartsColorArray[randomIndex];
}) })
.style("opacity", 0.7) .style("opacity", 0.7)
.style("cursor", "pointer")
// //
.on("mousemove", function (event, d: any) { .on("mousemove", function (event, d: any) {
isTooltipVisible.value = true; isTooltipVisible.value = true;
@ -1659,6 +1671,8 @@ const echarts2 = () => {
tooltip.transition().duration(200).style("opacity", 0.9); tooltip.transition().duration(200).style("opacity", 0.9);
tooltip tooltip
.html(d.data.name + "" + d.data.value) .html(d.data.name + "" + d.data.value)
.style("color", "gray")
.style("border", "1px solid " + echartsColorArray[Math.floor(Math.random() * echartsColorArray.length)])
.style("left", x + "px") // tooltip .style("left", x + "px") // tooltip
.style("top", y + "px"); // tooltip .style("top", y + "px"); // tooltip
}) })
@ -1745,7 +1759,7 @@ const echarts2 = () => {
svg svg
.append("text") .append("text")
.attr("class", "subtitle") .attr("class", "subtitle")
.attr("x", 5) // .attr("x", 0) //
.attr( .attr(
"y", "y",
((windowHeight.value - 100 - 3 * 4) / 3 - 198) / 2 + 78 + 14 * index ((windowHeight.value - 100 - 3 * 4) / 3 - 198) / 2 + 78 + 14 * index
@ -3613,6 +3627,9 @@ const initStreetChart = () => {
// //
const initRelationshipChart = () => { const initRelationshipChart = () => {
if (chartRelationship) {
chartRelationship.dispose();
}
// return; // return;
const chartDom = main9.value; const chartDom = main9.value;
if (!chartDom) return; if (!chartDom) return;
@ -3620,24 +3637,60 @@ const initRelationshipChart = () => {
chartRelationship = echarts.init(chartDom); chartRelationship = echarts.init(chartDom);
getRelationshipNetwork().then((res) => { getRelationshipNetwork().then((res) => {
let nodes;
let links;
// //
const nodes = res.data.nodes.map((node: any) => ({ if (handleRowValue.value == "") {
...node, // 线线
symbolSize: 10, // links = res.data.links.map((link: any) => ({
value: 15, // ...link,
draggable: false, // lineStyle: {
itemStyle: { opacity: 0.3, // 线
opacity: 0.8, // },
}, }));
}));
// 线线 nodes = res.data.nodes.map((node: any) => ({
const links = res.data.links.map((link: any) => ({ ...node,
...link, symbolSize: 10, //
lineStyle: { value: 15, //
opacity: 0.3, // 线 draggable: false, //
}, itemStyle: {
})); opacity: 0.8, //
},
}));
} else {
// 线线
links = res.data.links.filter((link: any) => link.target === handleRowValue.value || link.source === handleRowValue.value)
.map((link: any) => ({
...link,
lineStyle: {
opacity: 1, // 线
},
}))
nodes = res.data.nodes
// 线
.filter((node: any) =>
links.some(link =>
link.target === node.name || link.source === node.name
)
)
//
.map((node: any) => ({
...node,
symbolSize: 10, //
value: 15, //
draggable: false, //
itemStyle: {
opacity: 0.8, //
},
}));
}
// console.log(nodes, links, "------------");
// ECharts // ECharts
const option: echarts.EChartsOption = { const option: echarts.EChartsOption = {
@ -3660,10 +3713,10 @@ const initRelationshipChart = () => {
{ {
type: "graph", // type: "graph", //
layout: "force", // 使 layout: "force", // 使
zoom: 0.8, zoom: handleRowValue.value == "" ? 0.8 : 1.2,
force: { force: {
repulsion: 1000, // repulsion: 1000, //
edgeLength: 1000, // edgeLength: handleRowValue.value == "" ? 1000 : 200, //
gravity: 10, // gravity: 10, //
}, },
emphasis: { emphasis: {
@ -4279,15 +4332,19 @@ const highlightGraphNodeByName = (nodeName: string) => {
name: nodeName, name: nodeName,
}); });
}; };
const handleRowValue = ref("");
const handleRowClick = (item: any, index: number) => { const handleRowClick = (item: any, index: number) => {
console.log(item, index); // console.log(item, index);
// //
if (index !== 0) { if (index !== 0) {
jubaoGaofaData.value.splice(index, 1); // jubaoGaofaData.value.splice(index, 1); //
jubaoGaofaData.value.unshift(item); // jubaoGaofaData.value.unshift(item); //
} }
handleRowValue.value = "投诉举报-" + item.huanjie.slice(0, 2) + "-" + item.zhonglei;
console.log(handleRowValue.value);
initRelationshipChart();
}; };
@ -4435,6 +4492,7 @@ const handleFancyClick = (e: MouseEvent) => {
overflow: hidden; overflow: hidden;
background: rgba(0, 0, 0, 0.2); background: rgba(0, 0, 0, 0.2);
border-bottom: 1px solid rgba(255, 255, 255, 0.1); border-bottom: 1px solid rgba(255, 255, 255, 0.1);
cursor: pointer;
} }
.scroll-item { .scroll-item {