From 46fb1b1b4e223b1b3d102bf47dd95685f6a3a68c Mon Sep 17 00:00:00 2001 From: wangdan-fit2cloud Date: Wed, 25 Jun 2025 12:55:42 +0800 Subject: [PATCH] feat: shared --- ui/src/stores/modules/document.ts | 26 +++---- .../chat-log/component/EditContentDialog.vue | 3 +- ui/src/views/chat-log/index.vue | 43 ++++++---- ui/src/views/document/ImportLarkDocument.vue | 21 +++-- ui/src/views/document/UploadDocument.vue | 4 +- .../component/ImportDocumentDialog.vue | 78 +++++++++++-------- .../component/SelectKnowledgeDialog.vue | 7 +- ui/src/views/document/index.vue | 4 +- .../component/SelectDocumentDialog.vue | 2 +- .../problem/component/RelateProblemDialog.vue | 14 +++- 10 files changed, 118 insertions(+), 84 deletions(-) diff --git a/ui/src/stores/modules/document.ts b/ui/src/stores/modules/document.ts index ce3ccd78d..65d5ce365 100644 --- a/ui/src/stores/modules/document.ts +++ b/ui/src/stores/modules/document.ts @@ -1,30 +1,22 @@ import { defineStore } from 'pinia' -import documentApi from '@/api/knowledge/document' import { type Ref } from 'vue' +import { loadSharedApi } from '@/utils/dynamics-api/shared-api' const useDocumentStore = defineStore('document', { state: () => ({}), actions: { - async asyncGetKnowledgeDocument(id: string, loading?: Ref) { + async asyncGetKnowledgeDocument( + id: string, + systemType: 'systemShare' | 'workspace' | 'systemManage' = 'workspace', + loading?: Ref, + ) { return new Promise((resolve, reject) => { - documentApi + loadSharedApi({ type: 'document', systemType }) .getDocumentList(id, loading) - .then((res) => { + .then((res: any) => { resolve(res) }) - .catch((error) => { - reject(error) - }) - }) - }, - async asyncPutDocument(knowledgeId: string, data: any, loading?: Ref) { - return new Promise((resolve, reject) => { - documentApi - .putMulDocument(knowledgeId, data, loading) - .then((data) => { - resolve(data) - }) - .catch((error) => { + .catch((error: any) => { reject(error) }) }) diff --git a/ui/src/views/chat-log/component/EditContentDialog.vue b/ui/src/views/chat-log/component/EditContentDialog.vue index 898a8aa85..c0ff29db0 100644 --- a/ui/src/views/chat-log/component/EditContentDialog.vue +++ b/ui/src/views/chat-log/component/EditContentDialog.vue @@ -100,6 +100,7 @@ import { useRoute } from 'vue-router' import type { FormInstance, FormRules } from 'element-plus' import chatLogApi from '@/api/application/chat-log' import imageApi from '@/api/image' +import documentApi from '@/api/knowledge/document' import useStore from '@/stores' import { t } from '@/locales' const { application, document, user } = useStore() @@ -217,7 +218,7 @@ function changeDocument(document_id: string) { } function getDocument(knowledge_id: string) { - document.asyncGetKnowledgeDocument(knowledge_id, loading).then((res: any) => { + documentApi.getDocumentList(knowledge_id, loading).then((res: any) => { documentList.value = res.data if (localStorage.getItem(id + 'chat_document_id')) { form.value.document_id = localStorage.getItem(id + 'chat_document_id') as string diff --git a/ui/src/views/chat-log/index.vue b/ui/src/views/chat-log/index.vue index 801999843..cd9e62e85 100644 --- a/ui/src/views/chat-log/index.vue +++ b/ui/src/views/chat-log/index.vue @@ -26,7 +26,7 @@ format="YYYY-MM-DD" value-format="YYYY-MM-DD" @change="changeDayRangeHandle" - style="width: 240px;" + style="width: 240px" class="mr-12" />
- - {{$t('views.chatLog.buttons.clearStrategy')}} + {{ $t('views.chatLog.buttons.clearStrategy') }} - {{ $t('common.export') }} - {{ $t('views.chatLog.addToKnowledge') }} + {{ $t('views.chatLog.addToKnowledge') }}
@@ -285,6 +295,7 @@ import { cloneDeep } from 'lodash' import ChatRecordDrawer from './component/ChatRecordDrawer.vue' import { MsgSuccess, MsgConfirm } from '@/utils/message' import chatLogApi from '@/api/application/chat-log' +import documentApi from '@/api/knowledge/document' import { beforeDay, datetimeFormat, nowDate } from '@/utils/time' import useStore from '@/stores' import type { Dict } from '@/api/type/common' @@ -617,7 +628,7 @@ const submitForm = async (formEl: FormInstance | undefined) => { } function getDocument(knowledge_id: string) { - document.asyncGetKnowledgeDocument(knowledge_id, documentLoading).then((res: any) => { + documentApi.getDocumentList(knowledge_id, documentLoading).then((res: any) => { documentList.value = res.data if (localStorage.getItem(id + 'chat_document_id')) { form.value.document_id = localStorage.getItem(id + 'chat_document_id') as string diff --git a/ui/src/views/document/ImportLarkDocument.vue b/ui/src/views/document/ImportLarkDocument.vue index 1c4be2302..7f6db49aa 100644 --- a/ui/src/views/document/ImportLarkDocument.vue +++ b/ui/src/views/document/ImportLarkDocument.vue @@ -140,10 +140,8 @@ import { ref, reactive, computed, onUnmounted } from 'vue' import { useRouter, useRoute } from 'vue-router' import { MsgConfirm, MsgSuccess, MsgWarning } from '@/utils/message' -import { getImgUrl } from '@/utils/utils' import { t } from '@/locales' import type Node from 'element-plus/es/components/tree/src/model/node' -import documentApi from '@/api/knowledge/document' import { loadSharedApi } from '@/utils/dynamics-api/shared-api' const router = useRouter() @@ -151,6 +149,15 @@ const route = useRoute() const { query: { id, folder_token }, // id为knowledgeID,有id的是上传文档 folder_token为飞书文件夹token } = route +const apiType = computed(() => { + if (route.path.includes('shared')) { + return 'systemShare' + } else if (route.path.includes('resource-management')) { + return 'systemManage' + } else { + return 'workspace' + } +}) const knowledgeId = id as string const folderToken = folder_token as string @@ -187,7 +194,7 @@ const props = { const loadNode = (node: Node, resolve: (nodeData: Tree[]) => void) => { const token = node.level === 0 ? folderToken : node.data.token // 根节点使用 folder_token,其他节点使用 node.data.token - documentApi + loadSharedApi({ type: 'document', systemType: apiType.value }) .getLarkDocumentList(knowledgeId, token, {}, loading) .then((res: any) => { const nodes = res.data.files as Tree[] @@ -199,7 +206,7 @@ const loadNode = (node: Node, resolve: (nodeData: Tree[]) => void) => { }) }) - .catch((err) => { + .catch((err: any) => { console.error('Failed to load tree nodes:', err) }) } @@ -238,14 +245,14 @@ function submit() { loading.value = false return } - documentApi + loadSharedApi({ type: 'document', systemType: apiType.value }) .importLarkDocument(knowledgeId, newList, loading) - .then((res) => { + .then(() => { MsgSuccess(t('views.document.tip.importMessage')) disabled.value = false router.go(-1) }) - .catch((err) => { + .catch((err: any) => { console.error('Failed to load tree nodes:', err) }) .finally(() => { diff --git a/ui/src/views/document/UploadDocument.vue b/ui/src/views/document/UploadDocument.vue index e3d56d1d6..ac37d419b 100644 --- a/ui/src/views/document/UploadDocument.vue +++ b/ui/src/views/document/UploadDocument.vue @@ -165,8 +165,8 @@ function submit() { if (id) { // 上传文档 - document - .asyncPutDocument(id as string, documents) + loadSharedApi({ type: 'document', systemType: apiType.value }) + .putMulDocument(id as string, documents) .then(() => { MsgSuccess(t('common.submitSuccess')) clearStore() diff --git a/ui/src/views/document/component/ImportDocumentDialog.vue b/ui/src/views/document/component/ImportDocumentDialog.vue index 280a5c9ac..9537e1f15 100644 --- a/ui/src/views/document/component/ImportDocumentDialog.vue +++ b/ui/src/views/document/component/ImportDocumentDialog.vue @@ -92,20 +92,30 @@