实现跨组件通信和按钮高亮功能

This commit is contained in:
于磊奇 2025-06-18 19:59:06 +08:00
commit 1507e2b4b4

View File

@ -1,8 +1,31 @@
<<<<<<< HEAD
<template>
<div style="width: 100%; height: 100%;">
<div class="graph-box" id="graph-container"></div>
<div class="slider-box">
=======
<!-- <script setup>
// import { RouterView } from 'vue-router'
// import HelloWorld from './components/HelloWorld.vue'
// import Visualize from '../views/visualize/index.vue'
// import graphData from "../views/visualize/data/graphData.ts"
</script> -->
<template>
<div style="width: 100%; height: 100%">
<div class="graph-box" id="graph-container"></div>
<div class="slider-box">
<button @click="handleCombineAction">定位并高亮</button>
<el-button
@click="toggleAutoPlay"
:loading="state.isProcessingAutoPlay"
:disabled="!Object.keys(state.marks).length"
:class="{'el-button--danger': state.isAutoPlaying}"
>
{{ state.isAutoPlaying ? '停止播放' : '开始自动播放' }}
</el-button>
>>>>>>> main
<el-slider v-model="state.sliderValue" @input="sliderChange" :marks="state.marks" />
</div>
</div>
@ -10,16 +33,25 @@
<script setup>
import axios from "axios";
<<<<<<< HEAD
import { onMounted, reactive } from "vue";
import { Graph } from "@antv/g6";
import { ElLoading } from 'element-plus';
=======
import { onMounted,onUnmounted, reactive, watch } from "vue";
import { Graph } from "@antv/g6";
import { ElLoading } from 'element-plus';
import { ElMessage } from 'element-plus';
import { useActionStore } from '@/store';
>>>>>>> main
const state = reactive({
graph: null,
marks: {
'0': "2024-01-03",
'10': "2024-01-04",
'20': "2024-01-05",
<<<<<<< HEAD
'30': "2024-03-16",
'40': "2024-03-17",
'50': "2024-04-08",
@ -32,6 +64,32 @@ const state = reactive({
sliderValue: 0,
loadingInstance: null
})
=======
'30': "2024-03-14",
'40': "2024-03-25",
'60': "2024-04-01",
'70': "2024-05-12",
'90': "2024-06-23",
'100': "2024-06-28"
},
sliderValue: 0,
loadingInstance: null,
isAutoPlaying: false,
isProcessingAutoPlay: false, //
remainingTime: 0, //
})
const actionStore = useActionStore();
watch(() => actionStore.triggerCombineAction, (value) => {
if (value) {
state.sliderValue = 30;
sliderChange(30);
setTimeout(() => {
highlightNode(actionStore.targetNodeId);
}, 500);
}
});
>>>>>>> main
let loadingInstance = null;
// Loading
const showLoading = () => {
@ -62,7 +120,13 @@ const sliderChange = (val) => {
const getData = async (dataTime) => {
showLoading()
const res = await axios.get("http://10.7.1.52:1922/demo/edge/getEdgeData", {
<<<<<<< HEAD
params: { dataTime }
=======
params:
{ dataTime }
>>>>>>> main
});
if (res.data.code == 200) {
createGraph(res.data.data)
@ -130,12 +194,84 @@ const createGraph = (data) => {
});
state.graph = graph
}
<<<<<<< HEAD
=======
//
const toggleAutoPlay = () => {
//
if (state.isProcessingAutoPlay) return;
state.isProcessingAutoPlay = true;
try {
if (state.isAutoPlaying) {
//
if (state.autoPlayTimer) {
clearInterval(state.autoPlayTimer);
state.autoPlayTimer = null;
}
state.isAutoPlaying = false;
state.isPaused = false;
//
if (state.graph?.stop) state.graph.stop();
ElMessage.success('自动播放已停止');
} else {
//
const markValues = Object.keys(state.marks).map(Number).sort((a, b) => a - b);
if (markValues.length <= 1) {
ElMessage.warning('标记点不足,无法启动自动播放');
return;
}
state.isAutoPlaying = true;
state.autoPlayTimer = setInterval(() => {
const currentIndex = markValues.indexOf(state.sliderValue);
const nextIndex = currentIndex + 1;
if (nextIndex >= markValues.length) {
//
clearInterval(state.autoPlayTimer);
state.autoPlayTimer = null;
state.isAutoPlaying = false;
ElMessage.success('所有标记点已播放完成');
return;
}
state.sliderValue = markValues[nextIndex];
sliderChange(state.sliderValue);
}, 12000);
ElMessage.success('自动播放已启动');
}
} catch (error) {
console.error('自动播放控制错误:', error);
ElMessage.error('操作失败,请重试');
//
if (state.autoPlayTimer) {
clearInterval(state.autoPlayTimer);
state.autoPlayTimer = null;
}
state.isAutoPlaying = false;
state.isPaused = false;
} finally {
state.isProcessingAutoPlay = false;
}
};
const handleLocationClick = () => {
// marks3.1430
state.sliderValue = 30;
sliderChange(30);
}
>>>>>>> main
/**
* 高亮节点
* @param id 节点id
*/
<<<<<<< HEAD
const highlightNode = (id) => {
=======
const highlightNode = (id) => {
>>>>>>> main
state.graph.getNodes().forEach((node) => {
state.graph.clearItemStates(node, "selected");
});
@ -154,14 +290,37 @@ const highlightNode = (id) => {
}
});
}
<<<<<<< HEAD
=======
const handleCombineAction = () => {
//
state.sliderValue = 30;
sliderChange(30);
//
setTimeout(() => {
highlightNode('840983');
}, 500);
}
>>>>>>> main
onMounted(() => {
getData('2024-01-03')
})
<<<<<<< HEAD
=======
onUnmounted(() => {
//
if (state.autoPlayTimer) {
clearInterval(state.autoPlayTimer);
}
})
>>>>>>> main
</script>
<style scoped>
.graph-box {
<<<<<<< HEAD
width: 100%;
height: 100%;
}
@ -169,4 +328,15 @@ onMounted(() => {
.slider-box {
margin-top: -230px;
}
=======
width: 80%;
height: 80%;
margin-top: -10px;
}
.slider-box {
margin-top: 65px;
}
>>>>>>> main
</style>