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/knowledge/document/form/ProcessStep.vue |  146 ++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 146 insertions(+), 0 deletions(-)

diff --git a/src/views/ai/knowledge/document/form/ProcessStep.vue b/src/views/ai/knowledge/document/form/ProcessStep.vue
new file mode 100644
index 0000000..4b290ea
--- /dev/null
+++ b/src/views/ai/knowledge/document/form/ProcessStep.vue
@@ -0,0 +1,146 @@
+<template>
+  <div>
+    <!-- 鏂囦欢澶勭悊鍒楄〃 -->
+    <div class="mt-15px grid grid-cols-1 gap-2">
+      <div
+        v-for="(file, index) in modelValue.list"
+        :key="index"
+        class="flex items-center py-4px px-12px border-l-4 border-l-[#409eff] rounded-sm shadow-sm hover:bg-[#ecf5ff] transition-all duration-300"
+      >
+        <!-- 鏂囦欢鍥炬爣鍜屽悕绉� -->
+        <div class="flex items-center min-w-[200px] mr-10px">
+          <Icon icon="ep:document" class="mr-8px text-[#409eff]" />
+          <span class="text-[13px] text-[#303133] break-all">{{ file.name }}</span>
+        </div>
+
+        <!-- 澶勭悊杩涘害 -->
+        <div class="flex-1">
+          <el-progress
+            :percentage="file.progress || 0"
+            :stroke-width="10"
+            :status="isProcessComplete(file) ? 'success' : ''"
+          />
+        </div>
+
+        <!-- 鍒嗘鏁伴噺 -->
+        <div class="ml-10px text-[13px] text-[#606266]">
+          鍒嗘鏁伴噺锛歿{ file.count ? file.count : '-' }}
+        </div>
+      </div>
+    </div>
+
+    <!-- 搴曢儴瀹屾垚鎸夐挳 -->
+    <div class="flex justify-end mt-20px">
+      <el-button
+        :type="allProcessComplete ? 'success' : 'primary'"
+        :disabled="!allProcessComplete"
+        @click="handleComplete"
+      >
+        瀹屾垚
+      </el-button>
+    </div>
+  </div>
+</template>
+
+<script setup lang="ts">
+import { KnowledgeSegmentApi } from '@/api/ai/knowledge/segment'
+
+const props = defineProps({
+  modelValue: {
+    type: Object,
+    required: true
+  }
+})
+
+const emit = defineEmits(['update:modelValue'])
+const parent = inject('parent') as any
+const pollingTimer = ref<number | null>(null) // 杞瀹氭椂鍣� ID锛岀敤浜庤窡韪拰娓呴櫎杞杩涚▼
+
+/** 鍒ゆ柇鏂囦欢澶勭悊鏄惁瀹屾垚 */
+const isProcessComplete = (file) => {
+  return file.progress === 100
+}
+
+/** 鍒ゆ柇鎵�鏈夋枃浠舵槸鍚﹂兘澶勭悊瀹屾垚 */
+const allProcessComplete = computed(() => {
+  return props.modelValue.list.every((file) => isProcessComplete(file))
+})
+
+/** 瀹屾垚鎸夐挳鐐瑰嚮浜嬩欢澶勭悊 */
+const handleComplete = () => {
+  if (parent?.exposed?.handleBack) {
+    parent.exposed.handleBack()
+  }
+}
+
+/** 鑾峰彇鏂囦欢澶勭悊杩涘害 */
+const getProcessList = async () => {
+  try {
+    // 1. 璋冪敤 API 鑾峰彇澶勭悊杩涘害
+    const documentIds = props.modelValue.list.filter((item) => item.id).map((item) => item.id)
+    if (documentIds.length === 0) {
+      return
+    }
+    const result = await KnowledgeSegmentApi.getKnowledgeSegmentProcessList(documentIds)
+
+    // 2.1鏇存柊杩涘害
+    const updatedList = props.modelValue.list.map((file) => {
+      const processInfo = result.find((item) => item.documentId === file.id)
+      if (processInfo) {
+        // 璁$畻杩涘害鐧惧垎姣旓細宸插祵鍏ユ暟閲� / 鎬绘暟閲� * 100
+        const progress =
+          processInfo.embeddingCount && processInfo.count
+            ? Math.floor((processInfo.embeddingCount / processInfo.count) * 100)
+            : 0
+        return {
+          ...file,
+          progress: progress,
+          count: processInfo.count || 0
+        }
+      }
+      return file
+    })
+
+    // 2.2 鏇存柊鏁版嵁
+    emit('update:modelValue', {
+      ...props.modelValue,
+      list: updatedList
+    })
+
+    // 3. 濡傛灉鏈畬鎴愶紝缁х画杞
+    if (!updatedList.every((file) => isProcessComplete(file))) {
+      pollingTimer.value = window.setTimeout(getProcessList, 3000)
+    }
+  } catch (error) {
+    // 鍑洪敊鍚庝篃缁х画杞
+    console.error('鑾峰彇澶勭悊杩涘害澶辫触:', error)
+    pollingTimer.value = window.setTimeout(getProcessList, 5000)
+  }
+}
+
+/** 缁勪欢鎸傝浇鏃跺紑濮嬭疆璇� */
+onMounted(() => {
+  // 1. 鍒濆鍖栬繘搴︿负 0
+  const initialList = props.modelValue.list.map((file) => ({
+    ...file,
+    progress: 0
+  }))
+
+  emit('update:modelValue', {
+    ...props.modelValue,
+    list: initialList
+  })
+
+  // 2. 寮�濮嬭疆璇㈣幏鍙栬繘搴�
+  getProcessList()
+})
+
+/** 缁勪欢鍗歌浇鍓嶆竻闄よ疆璇� */
+onBeforeUnmount(() => {
+  // 1. 娓呴櫎瀹氭椂鍣�
+  if (pollingTimer.value) {
+    clearTimeout(pollingTimer.value)
+    pollingTimer.value = null
+  }
+})
+</script>

--
Gitblit v1.8.0