| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252 |
- <template>
- <section ref="rootRef" class="ai-relation" :class="{ 'ai-block-fullscreen': isFullscreen }">
- <header class="ai-relation__head">
- <span class="ai-relation__label">通用关系图</span>
- <span v-if="total > 1" class="ai-relation__index">{{ index + 1 }} / {{ total }}</span>
- <span v-if="titleText" class="ai-relation__title">{{ titleText }}</span>
- <span v-if="metaText" class="ai-relation__meta">{{ metaText }}</span>
- <span class="ai-relation__spacer"></span>
- <span v-if="model" class="ai-relation__count">
- 节点 {{ model.nodes.length }} · 关系 {{ model.edges.length }}
- </span>
- </header>
- <div v-if="model?.truncated" class="ai-relation__notice">
- {{ model.note || `关系过多,仅展示部分数据(共 ${model.totalEdges} 条)` }}
- </div>
- <div ref="bodyRef" class="ai-relation__body">
- <template v-if="model && renderable">
- <AsyncRelationViewer v-if="visible" ref="viewerRef" :model="model" @toggle-fullscreen="toggleFullscreen" />
- <div v-else class="ai-relation__placeholder">
- <div class="ai-skeleton" :style="{ height: '18px', width: '38%' }"></div>
- <div class="ai-skeleton" :style="{ height: '14px', width: '62%' }"></div>
- <div class="ai-skeleton" :style="{ height: '14px', width: '48%' }"></div>
- </div>
- </template>
- <div v-else class="ai-relation__empty">
- <Icon :icon="model ? 'mdi:account-network-outline' : 'mdi:alert-circle-outline'" :size="18" />
- <span>{{ emptyText }}</span>
- </div>
- </div>
- <div v-if="isFullscreen" class="ai-relation__hint">
- 滚轮缩放 · 拖动画布平移 · 点击节点高亮相邻节点 · 点击关系线高亮两端 · 按 Esc 退出全屏
- </div>
- </section>
- </template>
- <script lang="ts" setup>
- /**
- * AI 聊天里的通用关系图块
- *
- * 数据来自 `execute_python` 工具结果里的 `relationGraph`(模型在 Python 里调用
- * emit_relation_graph 产出)。本组件只负责容器/懒加载/全屏,画布在独立的
- * RelationGraphViewer 中实现,不复用案件图谱组件。
- */
- import { computed, defineAsyncComponent, nextTick, onBeforeUnmount, onMounted, ref } from 'vue';
- import Icon from '@/core/components/Icon/src/Icon.vue';
- import { useBlockFullscreen } from '../../utils/useBlockFullscreen';
- import { parseRelationGraphPayload } from './relationData';
- const AsyncRelationViewer = defineAsyncComponent(() => import('./RelationGraphViewer.vue'));
- const props = withDefaults(
- defineProps<{
- /** 工具结果里的 relationGraph 原始载荷 */
- payload: unknown;
- /** 关系名/表名摘要(header 用) */
- meta?: string;
- /** 多张图时的序号(从 0 开始) */
- index?: number;
- /** 多张图时的总数 */
- total?: number;
- }>(),
- { meta: '', index: 0, total: 1 },
- );
- const rootRef = ref<HTMLElement>();
- const bodyRef = ref<HTMLElement>();
- const viewerRef = ref<any>(null);
- const model = computed(() => parseRelationGraphPayload(props.payload));
- const renderable = computed(() => Boolean(model.value && model.value.nodes.length));
- const titleText = computed(() => model.value?.title || '');
- const metaText = computed(() => props.meta || '');
- const emptyText = computed(() => {
- if (!model.value) return '关系图数据无法解析,暂不能展示';
- if (!model.value.nodes.length && !model.value.edges.length) {
- return model.value.note || '模型没有生成可展示的关系';
- }
- if (!model.value.nodes.length) return '未查询到符合条件的节点';
- return '暂无可展示的关系图数据';
- });
- /* ---------------- 懒加载:首次进入视口才挂载 G6 ---------------- */
- const visible = ref(false);
- let observer: IntersectionObserver | null = null;
- onMounted(() => {
- if (!rootRef.value || typeof IntersectionObserver === 'undefined') {
- visible.value = true;
- return;
- }
- observer = new IntersectionObserver(
- (entries) => {
- if (!entries.some((entry) => entry.isIntersecting)) return;
- visible.value = true;
- observer?.disconnect();
- observer = null;
- },
- { rootMargin: '240px 0px' },
- );
- observer.observe(rootRef.value);
- });
- onBeforeUnmount(() => {
- observer?.disconnect();
- observer = null;
- });
- /* ---------------- 全屏 ---------------- */
- const { isFullscreen, toggle: toggleFullscreen } = useBlockFullscreen(async () => {
- await nextTick();
- await viewerRef.value?.resizeAndFit?.();
- });
- </script>
- <style lang="less" scoped>
- .ai-relation {
- margin: var(--ai-sp-3) 0;
- border: 1px solid var(--ai-border, #e5e7eb);
- border-radius: var(--ai-radius, 8px);
- background: var(--ai-bg, #fff);
- overflow: hidden;
- &.ai-block-fullscreen {
- margin: 0;
- .ai-relation__head {
- flex: 0 0 auto;
- }
- .ai-relation__body {
- flex: 1 1 auto;
- height: auto;
- min-height: 0;
- }
- }
- &__head {
- display: flex;
- align-items: center;
- flex-wrap: wrap;
- gap: var(--ai-sp-2, 8px);
- padding: 6px 8px 6px 12px;
- border-bottom: 1px solid var(--ai-border, #e5e7eb);
- }
- &__label {
- font-size: 11px;
- letter-spacing: 0.04em;
- text-transform: uppercase;
- color: var(--ai-text-2, #64748b);
- }
- &__index {
- font-size: 11px;
- color: var(--ai-text-2, #64748b);
- font-variant-numeric: tabular-nums;
- }
- &__title {
- max-width: 34%;
- overflow: hidden;
- font-size: 12px;
- font-weight: 600;
- color: var(--ai-text, #1f2937);
- white-space: nowrap;
- text-overflow: ellipsis;
- }
- &__meta {
- min-width: 0;
- max-width: 40%;
- overflow: hidden;
- font-size: 12px;
- color: var(--ai-text-2, #64748b);
- white-space: nowrap;
- text-overflow: ellipsis;
- }
- &__spacer {
- flex: 1 1 auto;
- }
- &__count {
- font-size: 11px;
- color: var(--ai-text-2, #64748b);
- font-variant-numeric: tabular-nums;
- white-space: nowrap;
- }
- &__notice {
- padding: 4px 12px;
- overflow: hidden;
- font-size: 11px;
- line-height: 1.6;
- color: #b45309;
- white-space: nowrap;
- text-overflow: ellipsis;
- background: rgba(245, 158, 11, 0.08);
- border-bottom: 1px solid var(--ai-border, #e5e7eb);
- }
- &__body {
- display: flex;
- height: 460px;
- min-height: 0;
- background: var(--ai-bg-subtle, #f7f8fa);
- }
- &__placeholder {
- display: flex;
- flex-direction: column;
- justify-content: center;
- gap: 10px;
- width: 100%;
- padding: 24px;
- margin: 0;
- .ai-skeleton {
- border-radius: 6px;
- }
- }
- &__empty {
- display: flex;
- align-items: center;
- justify-content: center;
- gap: 8px;
- width: 100%;
- min-height: 160px;
- padding: 24px;
- font-size: 12px;
- color: var(--ai-text-2, #64748b);
- }
- &__hint {
- flex: 0 0 auto;
- padding: 4px 12px;
- font-size: 11px;
- color: var(--ai-text-2, #64748b);
- text-align: center;
- border-top: 1px solid var(--ai-border, #e5e7eb);
- background: var(--ai-bg-subtle, #f7f8fa);
- }
- }
- </style>
|