From a1d7e81859f554f3a53680cc35f0f49bf1f77098 Mon Sep 17 00:00:00 2001
From: wwf <1971391498@qq.com>
Date: 星期四, 14 五月 2026 14:37:02 +0800
Subject: [PATCH] 导入项目

---
 src/views/ai/mindmap/index/index.vue |   94 +++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 94 insertions(+), 0 deletions(-)

diff --git a/src/views/ai/mindmap/index/index.vue b/src/views/ai/mindmap/index/index.vue
new file mode 100644
index 0000000..72f0553
--- /dev/null
+++ b/src/views/ai/mindmap/index/index.vue
@@ -0,0 +1,94 @@
+<template>
+  <div class="absolute top-0 left-0 right-0 bottom-0 flex">
+    <!--琛ㄥ崟鍖哄煙-->
+    <Left
+      ref="leftRef"
+      :is-generating="isGenerating"
+      @submit="submit"
+      @direct-generate="directGenerate"
+    />
+    <!--鍙宠竟鐢熸垚鎬濈淮瀵煎浘鍖哄煙-->
+    <Right
+      ref="rightRef"
+      :generatedContent="generatedContent"
+      :isEnd="isEnd"
+      :isGenerating="isGenerating"
+      :isStart="isStart"
+    />
+  </div>
+</template>
+
+<script lang="ts" setup>
+import Left from './components/Left.vue'
+import Right from './components/Right.vue'
+import { AiMindMapApi, AiMindMapGenerateReqVO } from '@/api/ai/mindmap'
+import { MindMapContentExample } from '@/views/ai/utils/constants'
+
+defineOptions({
+  name: 'AiMindMap'
+})
+const ctrl = ref<AbortController>() // 璇锋眰鎺у埗
+const isGenerating = ref(false) // 鏄惁姝e湪鐢熸垚鎬濈淮瀵煎浘
+const isStart = ref(false) // 寮�濮嬬敓鎴愶紝鐢ㄦ潵娓呯┖鎬濈淮瀵煎浘
+const isEnd = ref(true) // 鐢ㄦ潵鍒ゆ柇缁撴潫鐨勬椂鍊欐覆鏌撴�濈淮瀵煎浘
+const message = useMessage() // 娑堟伅鎻愮ず
+
+const generatedContent = ref('') // 鐢熸垚鎬濈淮瀵煎浘缁撴灉
+
+const leftRef = ref<InstanceType<typeof Left>>() // 宸﹁竟缁勪欢
+const rightRef = ref<InstanceType<typeof Right>>() // 鍙宠竟缁勪欢
+
+/** 浣跨敤宸叉湁鍐呭鐩存帴鐢熸垚 **/
+const directGenerate = (existPrompt: string) => {
+  isEnd.value = false // 鍏堣缃负 false 鍐嶈缃负 true锛岃瀛愮粍寤虹殑 watch 鑳藉鐩戝惉鍒�
+  generatedContent.value = existPrompt
+  isEnd.value = true
+}
+
+/** 鍋滄 stream 鐢熸垚 */
+const stopStream = () => {
+  isGenerating.value = false
+  isStart.value = false
+  ctrl.value?.abort()
+}
+
+/** 鎻愪氦鐢熸垚 */
+const submit = (data: AiMindMapGenerateReqVO) => {
+  isGenerating.value = true
+  isStart.value = true
+  isEnd.value = false
+  ctrl.value = new AbortController() // 璇锋眰鎺у埗璧嬪��
+  generatedContent.value = '' // 娓呯┖鐢熸垚鏁版嵁
+  AiMindMapApi.generateMindMap({
+    data,
+    onMessage: async (res) => {
+      const { code, data, msg } = JSON.parse(res.data)
+      if (code !== 0) {
+        message.alert(`鐢熸垚鎬濈淮瀵煎浘寮傚父! ${msg}`)
+        stopStream()
+        return
+      }
+      generatedContent.value = generatedContent.value + data
+      await nextTick()
+      rightRef.value?.scrollBottom()
+    },
+    onClose() {
+      isEnd.value = true
+      leftRef.value?.setGeneratedContent(generatedContent.value)
+      stopStream()
+    },
+    onError(err) {
+      console.error('鐢熸垚鎬濈淮瀵煎浘澶辫触', err)
+      stopStream()
+      // 闇�瑕佹姏鍑哄紓甯革紝绂佹閲嶈瘯
+      throw error
+    },
+    ctrl: ctrl.value
+  })
+}
+
+/** 鍒濆鍖� */
+onMounted(() => {
+  generatedContent.value = MindMapContentExample
+})
+</script>

--
Gitblit v1.8.0