mirror of
https://github.com/1Panel-dev/MaxKB.git
synced 2025-12-26 10:12:51 +00:00
feat: shared
This commit is contained in:
parent
2570114edf
commit
46fb1b1b4e
|
|
@ -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<boolean>) {
|
||||
async asyncGetKnowledgeDocument(
|
||||
id: string,
|
||||
systemType: 'systemShare' | 'workspace' | 'systemManage' = 'workspace',
|
||||
loading?: Ref<boolean>,
|
||||
) {
|
||||
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<boolean>) {
|
||||
return new Promise((resolve, reject) => {
|
||||
documentApi
|
||||
.putMulDocument(knowledgeId, data, loading)
|
||||
.then((data) => {
|
||||
resolve(data)
|
||||
})
|
||||
.catch((error) => {
|
||||
.catch((error: any) => {
|
||||
reject(error)
|
||||
})
|
||||
})
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -26,7 +26,7 @@
|
|||
format="YYYY-MM-DD"
|
||||
value-format="YYYY-MM-DD"
|
||||
@change="changeDayRangeHandle"
|
||||
style="width: 240px;"
|
||||
style="width: 240px"
|
||||
class="mr-12"
|
||||
/>
|
||||
<el-input
|
||||
|
|
@ -38,25 +38,35 @@
|
|||
clearable
|
||||
/>
|
||||
<div style="display: flex; align-items: center" class="float-right">
|
||||
<el-button @click="dialogVisible = true"
|
||||
v-hasPermission="[RoleConst.WORKSPACE_MANAGE.getWorkspaceRole,
|
||||
RoleConst.USER.getWorkspaceRole,
|
||||
PermissionConst.APPLICATION_CHAT_LOG_POLICY.getWorkspacePermission]"
|
||||
<el-button
|
||||
@click="dialogVisible = true"
|
||||
v-hasPermission="[
|
||||
RoleConst.WORKSPACE_MANAGE.getWorkspaceRole,
|
||||
RoleConst.USER.getWorkspaceRole,
|
||||
PermissionConst.APPLICATION_CHAT_LOG_POLICY.getWorkspacePermission,
|
||||
]"
|
||||
>
|
||||
{{$t('views.chatLog.buttons.clearStrategy')}}
|
||||
{{ $t('views.chatLog.buttons.clearStrategy') }}
|
||||
</el-button>
|
||||
<el-button @click="exportLog"
|
||||
v-hasPermission="[RoleConst.WORKSPACE_MANAGE.getWorkspaceRole,
|
||||
RoleConst.USER.getWorkspaceRole,
|
||||
PermissionConst.APPLICATION_CHAT_LOG_EXPORT.getWorkspacePermission]"
|
||||
<el-button
|
||||
@click="exportLog"
|
||||
v-hasPermission="[
|
||||
RoleConst.WORKSPACE_MANAGE.getWorkspaceRole,
|
||||
RoleConst.USER.getWorkspaceRole,
|
||||
PermissionConst.APPLICATION_CHAT_LOG_EXPORT.getWorkspacePermission,
|
||||
]"
|
||||
>
|
||||
{{ $t('common.export') }}
|
||||
</el-button>
|
||||
<el-button @click="openDocumentDialog" :disabled="multipleSelection.length === 0"
|
||||
v-hasPermission="[RoleConst.WORKSPACE_MANAGE.getWorkspaceRole,
|
||||
RoleConst.USER.getWorkspaceRole,
|
||||
PermissionConst.APPLICATION_CHAT_LOG_EXPORT.getWorkspacePermission]"
|
||||
>{{ $t('views.chatLog.addToKnowledge') }}
|
||||
<el-button
|
||||
@click="openDocumentDialog"
|
||||
:disabled="multipleSelection.length === 0"
|
||||
v-hasPermission="[
|
||||
RoleConst.WORKSPACE_MANAGE.getWorkspaceRole,
|
||||
RoleConst.USER.getWorkspaceRole,
|
||||
PermissionConst.APPLICATION_CHAT_LOG_EXPORT.getWorkspacePermission,
|
||||
]"
|
||||
>{{ $t('views.chatLog.addToKnowledge') }}
|
||||
</el-button>
|
||||
</div>
|
||||
</div>
|
||||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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(() => {
|
||||
|
|
|
|||
|
|
@ -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()
|
||||
|
|
|
|||
|
|
@ -92,20 +92,30 @@
|
|||
</el-dialog>
|
||||
</template>
|
||||
<script setup lang="ts">
|
||||
import { ref, reactive, watch } from 'vue'
|
||||
import { ref, reactive, watch, computed } from 'vue'
|
||||
import { useRoute } from 'vue-router'
|
||||
import type { FormInstance } from 'element-plus'
|
||||
import documentApi from '@/api/knowledge/document'
|
||||
import { MsgSuccess } from '@/utils/message'
|
||||
import { hitHandlingMethod } from '@/enums/document'
|
||||
import { loadSharedApi } from '@/utils/dynamics-api/shared-api'
|
||||
import { t } from '@/locales'
|
||||
const route = useRoute()
|
||||
const {
|
||||
params: { id }
|
||||
params: { id },
|
||||
} = route as any
|
||||
|
||||
const props = defineProps({
|
||||
title: String
|
||||
title: String,
|
||||
})
|
||||
|
||||
const apiType = computed(() => {
|
||||
if (route.path.includes('shared')) {
|
||||
return 'systemShare'
|
||||
} else if (route.path.includes('resource-management')) {
|
||||
return 'systemManage'
|
||||
} else {
|
||||
return 'workspace'
|
||||
}
|
||||
})
|
||||
|
||||
const emit = defineEmits(['refresh'])
|
||||
|
|
@ -116,7 +126,7 @@ const form = ref<any>({
|
|||
source_url: '',
|
||||
selector: '',
|
||||
hit_handling_method: 'optimization',
|
||||
directly_return_similarity: 0.9
|
||||
directly_return_similarity: 0.9,
|
||||
})
|
||||
|
||||
// 文档设置
|
||||
|
|
@ -131,16 +141,16 @@ const rules = reactive({
|
|||
{
|
||||
required: true,
|
||||
message: t('views.document.form.source_url.requiredMessage'),
|
||||
trigger: 'blur'
|
||||
}
|
||||
trigger: 'blur',
|
||||
},
|
||||
],
|
||||
directly_return_similarity: [
|
||||
{
|
||||
required: true,
|
||||
message: t('views.document.form.similarity.requiredMessage'),
|
||||
trigger: 'blur'
|
||||
}
|
||||
]
|
||||
trigger: 'blur',
|
||||
},
|
||||
],
|
||||
})
|
||||
|
||||
const dialogVisible = ref<boolean>(false)
|
||||
|
|
@ -151,7 +161,7 @@ watch(dialogVisible, (bool) => {
|
|||
source_url: '',
|
||||
selector: '',
|
||||
hit_handling_method: 'optimization',
|
||||
directly_return_similarity: 0.9
|
||||
directly_return_similarity: 0.9,
|
||||
}
|
||||
isImport.value = false
|
||||
documentType.value = ''
|
||||
|
|
@ -167,7 +177,7 @@ const open = (row: any, list: Array<string>) => {
|
|||
form.value = {
|
||||
hit_handling_method: row.hit_handling_method,
|
||||
directly_return_similarity: row.directly_return_similarity,
|
||||
...row.meta
|
||||
...row.meta,
|
||||
}
|
||||
isImport.value = false
|
||||
} else if (list) {
|
||||
|
|
@ -188,13 +198,15 @@ const submit = async (formEl: FormInstance | undefined) => {
|
|||
if (isImport.value) {
|
||||
const obj = {
|
||||
source_url_list: form.value.source_url.split('\n'),
|
||||
selector: form.value.selector
|
||||
selector: form.value.selector,
|
||||
}
|
||||
documentApi.postWebDocument(id, obj, loading).then(() => {
|
||||
MsgSuccess(t('views.document.tip.importMessage'))
|
||||
emit('refresh')
|
||||
dialogVisible.value = false
|
||||
})
|
||||
loadSharedApi({ type: 'document', systemType: apiType.value })
|
||||
.postWebDocument(id, obj, loading)
|
||||
.then(() => {
|
||||
MsgSuccess(t('views.document.tip.importMessage'))
|
||||
emit('refresh')
|
||||
dialogVisible.value = false
|
||||
})
|
||||
} else {
|
||||
if (documentId.value) {
|
||||
const obj = {
|
||||
|
|
@ -202,26 +214,30 @@ const submit = async (formEl: FormInstance | undefined) => {
|
|||
directly_return_similarity: form.value.directly_return_similarity,
|
||||
meta: {
|
||||
source_url: form.value.source_url,
|
||||
selector: form.value.selector
|
||||
}
|
||||
selector: form.value.selector,
|
||||
},
|
||||
}
|
||||
documentApi.putDocument(id, documentId.value, obj, loading).then(() => {
|
||||
MsgSuccess(t('common.settingSuccess'))
|
||||
emit('refresh')
|
||||
dialogVisible.value = false
|
||||
})
|
||||
loadSharedApi({ type: 'document', systemType: apiType.value })
|
||||
.putDocument(id, documentId.value, obj, loading)
|
||||
.then(() => {
|
||||
MsgSuccess(t('common.settingSuccess'))
|
||||
emit('refresh')
|
||||
dialogVisible.value = false
|
||||
})
|
||||
} else if (documentList.value.length > 0) {
|
||||
// 批量设置
|
||||
const obj = {
|
||||
hit_handling_method: form.value.hit_handling_method,
|
||||
directly_return_similarity: form.value.directly_return_similarity,
|
||||
id_list: documentList.value
|
||||
id_list: documentList.value,
|
||||
}
|
||||
documentApi.putBatchEditHitHandling(id, obj, loading).then(() => {
|
||||
MsgSuccess(t('common.settingSuccess'))
|
||||
emit('refresh')
|
||||
dialogVisible.value = false
|
||||
})
|
||||
loadSharedApi({ type: 'document', systemType: apiType.value })
|
||||
.putBatchEditHitHandling(id, obj, loading)
|
||||
.then(() => {
|
||||
MsgSuccess(t('common.settingSuccess'))
|
||||
emit('refresh')
|
||||
dialogVisible.value = false
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -58,10 +58,7 @@
|
|||
<script setup lang="ts">
|
||||
import { ref, watch, computed } from 'vue'
|
||||
import { useRoute } from 'vue-router'
|
||||
import documentApi from '@/api/knowledge/document'
|
||||
import { loadSharedApi } from '@/utils/dynamics-api/shared-api'
|
||||
|
||||
import useStore from '@/stores'
|
||||
const route = useRoute()
|
||||
const {
|
||||
params: { id }, // id为knowledgeID
|
||||
|
|
@ -121,9 +118,9 @@ const open = (list: any) => {
|
|||
}
|
||||
|
||||
const submitHandle = () => {
|
||||
documentApi
|
||||
loadSharedApi({ type: 'document', systemType: apiType.value })
|
||||
.putMigrateMulDocument(id, form.value.selectKnowledge, documentList.value, loading)
|
||||
.then((res) => {
|
||||
.then(() => {
|
||||
emit('refresh')
|
||||
dialogVisible.value = false
|
||||
})
|
||||
|
|
|
|||
|
|
@ -857,8 +857,8 @@ function rowClickHandle(row: any, column: any) {
|
|||
function creatQuickHandle(val: string) {
|
||||
loading.value = true
|
||||
const obj = [{ name: val }]
|
||||
document
|
||||
.asyncPutDocument(id, obj)
|
||||
loadSharedApi({ type: 'document', systemType: apiType.value })
|
||||
.putMulDocument(id, obj)
|
||||
.then(() => {
|
||||
getList()
|
||||
MsgSuccess(t('common.createSuccess'))
|
||||
|
|
|
|||
|
|
@ -160,7 +160,7 @@ function changeKnowledge(id: string) {
|
|||
}
|
||||
|
||||
function getDocument(id: string) {
|
||||
document.asyncGetKnowledgeDocument(id, optionLoading).then((res: any) => {
|
||||
document.asyncGetKnowledgeDocument(id, apiType.value, optionLoading).then((res: any) => {
|
||||
documentList.value = res.data?.filter((v: any) => v.id !== documentId)
|
||||
})
|
||||
}
|
||||
|
|
|
|||
|
|
@ -109,7 +109,7 @@
|
|||
</el-dialog>
|
||||
</template>
|
||||
<script setup lang="ts">
|
||||
import { ref, watch, reactive } from 'vue'
|
||||
import { ref, watch, reactive, computed } from 'vue'
|
||||
import { useRoute } from 'vue-router'
|
||||
import problemApi from '@/api/knowledge/problem'
|
||||
import paragraphApi from '@/api/knowledge/paragraph'
|
||||
|
|
@ -123,6 +123,16 @@ const {
|
|||
params: { id }, // knowledgeId
|
||||
} = route as any
|
||||
|
||||
const apiType = computed(() => {
|
||||
if (route.path.includes('shared')) {
|
||||
return 'systemShare'
|
||||
} else if (route.path.includes('resource-management')) {
|
||||
return 'systemManage'
|
||||
} else {
|
||||
return 'workspace'
|
||||
}
|
||||
})
|
||||
|
||||
const emit = defineEmits(['refresh'])
|
||||
|
||||
const dialogVisible = ref<boolean>(false)
|
||||
|
|
@ -214,7 +224,7 @@ function clickDocumentHandle(item: any) {
|
|||
}
|
||||
|
||||
function getDocument() {
|
||||
document.asyncGetKnowledgeDocument(id, loading).then((res: any) => {
|
||||
document.asyncGetKnowledgeDocument(id, apiType.value, loading).then((res: any) => {
|
||||
cloneDocumentList.value = res.data
|
||||
documentList.value = res.data
|
||||
currentDocument.value = cloneDocumentList.value?.length > 0 ? cloneDocumentList.value[0].id : ''
|
||||
|
|
|
|||
Loading…
Reference in New Issue