index.vue 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209
  1. <template>
  2. <ContentWrap>
  3. <div class="mx-auto">
  4. <!-- 头部导航栏 -->
  5. <div
  6. class="absolute top-0 left-0 right-0 h-50px bg-white border-bottom z-10 flex items-center px-20px"
  7. >
  8. <!-- 左侧标题 -->
  9. <div class="w-200px flex items-center overflow-hidden">
  10. <Icon icon="ep:arrow-left" class="cursor-pointer flex-shrink-0" @click="handleBack" />
  11. <span class="ml-10px text-16px truncate" :title="formData.name || '创建知识库文档'">
  12. {{ formData.name || '创建知识库文档' }}
  13. </span>
  14. </div>
  15. <!-- 步骤条 -->
  16. <div class="flex-1 flex items-center justify-center h-full">
  17. <div class="w-400px flex items-center justify-between h-full">
  18. <div
  19. v-for="(step, index) in steps"
  20. :key="index"
  21. class="flex items-center mx-15px relative h-full"
  22. :class="[
  23. currentStep === index
  24. ? 'text-[#3473ff] border-[#3473ff] border-b-2 border-b-solid'
  25. : 'text-gray-500'
  26. ]"
  27. >
  28. <div
  29. class="w-28px h-28px rounded-full flex items-center justify-center mr-8px border-2 border-solid text-15px"
  30. :class="[
  31. currentStep === index
  32. ? 'bg-[#3473ff] text-white border-[#3473ff]'
  33. : 'border-gray-300 bg-white text-gray-500'
  34. ]"
  35. >
  36. {{ index + 1 }}
  37. </div>
  38. <span class="text-16px font-bold whitespace-nowrap">{{ step.title }}</span>
  39. </div>
  40. </div>
  41. </div>
  42. <!-- 右侧按钮 - 已移除 -->
  43. <div class="w-200px flex items-center justify-end gap-2"> </div>
  44. </div>
  45. <!-- 主体内容 -->
  46. <div class="mt-50px">
  47. <!-- 第一步:上传文档 -->
  48. <div v-if="currentStep === 0" class="mx-auto w-560px">
  49. <UploadStep v-model="formData" ref="uploadDocumentRef" />
  50. </div>
  51. <!-- 第二步:文档分段 -->
  52. <div v-if="currentStep === 1" class="mx-auto w-560px">
  53. <SplitStep v-model="formData" ref="documentSegmentRef" />
  54. </div>
  55. <!-- 第三步:处理并完成 -->
  56. <div v-if="currentStep === 2" class="mx-auto w-560px">
  57. <ProcessStep v-model="formData" ref="processCompleteRef" />
  58. </div>
  59. </div>
  60. </div>
  61. </ContentWrap>
  62. </template>
  63. <script lang="ts" setup>
  64. import { useRoute, useRouter } from 'vue-router'
  65. import { useMessage } from '@/hooks/web/useMessage'
  66. import { useTagsViewStore } from '@/store/modules/tagsView'
  67. import UploadStep from './UploadStep.vue'
  68. import SplitStep from './SplitStep.vue'
  69. import ProcessStep from './ProcessStep.vue'
  70. const router = useRouter()
  71. const { delView } = useTagsViewStore() // 视图操作
  72. const route = useRoute()
  73. const message = useMessage()
  74. // 组件引用
  75. const uploadDocumentRef = ref()
  76. const documentSegmentRef = ref()
  77. const processCompleteRef = ref()
  78. const currentStep = ref(0) // 步骤控制
  79. const steps = [{ title: '上传文档' }, { title: '文档分段' }, { title: '处理并完成' }]
  80. // 表单数据
  81. const formData = ref({
  82. id: undefined,
  83. list: [], // 用于存储上传的文件列表
  84. status: 0 // 0: 草稿, 1: 处理中, 2: 已完成
  85. })
  86. /** 初始化数据 */
  87. const initData = async () => {
  88. const documentId = route.params.id as string
  89. if (documentId) {
  90. // 修改场景
  91. // 这里需要调用API获取文档数据
  92. // formData.value = await DocumentApi.getDocument(documentId)
  93. }
  94. }
  95. /** 切换到下一步 */
  96. const goToNextStep = () => {
  97. if (currentStep.value < steps.length - 1) {
  98. currentStep.value++
  99. }
  100. }
  101. /** 切换到上一步 */
  102. const goToPrevStep = () => {
  103. if (currentStep.value > 0) {
  104. currentStep.value--
  105. }
  106. }
  107. /** 保存操作 */
  108. const handleSave = async () => {
  109. try {
  110. // 更新表单数据
  111. const documentData = {
  112. ...formData.value
  113. }
  114. if (formData.value.id) {
  115. // 修改场景
  116. // await DocumentApi.updateDocument(documentData)
  117. message.success('修改成功')
  118. } else {
  119. // 新增场景
  120. // formData.value.id = await DocumentApi.createDocument(documentData)
  121. message.success('新增成功')
  122. try {
  123. await message.confirm('创建文档成功,是否继续编辑?')
  124. // 用户点击继续编辑,跳转到编辑页面
  125. await nextTick()
  126. // 先删除当前页签
  127. delView(unref(router.currentRoute))
  128. // 跳转到编辑页面
  129. await router.push({
  130. name: 'AiKnowledgeDocumentUpdate',
  131. params: { id: formData.value.id }
  132. })
  133. } catch {
  134. // 先删除当前页签
  135. delView(unref(router.currentRoute))
  136. // 用户点击返回列表
  137. await router.push({ name: 'AiKnowledgeDocument' })
  138. }
  139. }
  140. } catch (error: any) {
  141. console.error('保存失败:', error)
  142. message.warning(error.message || '请完善所有步骤的必填信息')
  143. }
  144. }
  145. /** 返回列表页 */
  146. const handleBack = () => {
  147. // 先删除当前页签
  148. delView(unref(router.currentRoute))
  149. // 跳转到列表页
  150. router.push({ name: 'AiKnowledgeDocument' })
  151. }
  152. /** 初始化 */
  153. onMounted(async () => {
  154. await initData()
  155. })
  156. // 提供parent给子组件使用
  157. provide('parent', getCurrentInstance())
  158. // 添加组件卸载前的清理代码
  159. onBeforeUnmount(() => {
  160. // 清理所有的引用
  161. uploadDocumentRef.value = null
  162. documentSegmentRef.value = null
  163. processCompleteRef.value = null
  164. })
  165. // 暴露方法给子组件使用
  166. defineExpose({
  167. goToNextStep,
  168. goToPrevStep,
  169. handleSave
  170. })
  171. </script>
  172. <style lang="scss" scoped>
  173. .border-bottom {
  174. border-bottom: 1px solid #dcdfe6;
  175. }
  176. .text-primary {
  177. color: #3473ff;
  178. }
  179. .bg-primary {
  180. background-color: #3473ff;
  181. }
  182. .border-primary {
  183. border-color: #3473ff;
  184. }
  185. </style>