feat: shared

This commit is contained in:
wangdan-fit2cloud 2025-06-25 12:55:42 +08:00
parent 2570114edf
commit 46fb1b1b4e
10 changed files with 118 additions and 84 deletions

View File

@ -1,30 +1,22 @@
import { defineStore } from 'pinia' import { defineStore } from 'pinia'
import documentApi from '@/api/knowledge/document'
import { type Ref } from 'vue' import { type Ref } from 'vue'
import { loadSharedApi } from '@/utils/dynamics-api/shared-api'
const useDocumentStore = defineStore('document', { const useDocumentStore = defineStore('document', {
state: () => ({}), state: () => ({}),
actions: { 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) => { return new Promise((resolve, reject) => {
documentApi loadSharedApi({ type: 'document', systemType })
.getDocumentList(id, loading) .getDocumentList(id, loading)
.then((res) => { .then((res: any) => {
resolve(res) resolve(res)
}) })
.catch((error) => { .catch((error: any) => {
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) => {
reject(error) reject(error)
}) })
}) })

View File

@ -100,6 +100,7 @@ import { useRoute } from 'vue-router'
import type { FormInstance, FormRules } from 'element-plus' import type { FormInstance, FormRules } from 'element-plus'
import chatLogApi from '@/api/application/chat-log' import chatLogApi from '@/api/application/chat-log'
import imageApi from '@/api/image' import imageApi from '@/api/image'
import documentApi from '@/api/knowledge/document'
import useStore from '@/stores' import useStore from '@/stores'
import { t } from '@/locales' import { t } from '@/locales'
const { application, document, user } = useStore() const { application, document, user } = useStore()
@ -217,7 +218,7 @@ function changeDocument(document_id: string) {
} }
function getDocument(knowledge_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 documentList.value = res.data
if (localStorage.getItem(id + 'chat_document_id')) { if (localStorage.getItem(id + 'chat_document_id')) {
form.value.document_id = localStorage.getItem(id + 'chat_document_id') as string form.value.document_id = localStorage.getItem(id + 'chat_document_id') as string

View File

@ -26,7 +26,7 @@
format="YYYY-MM-DD" format="YYYY-MM-DD"
value-format="YYYY-MM-DD" value-format="YYYY-MM-DD"
@change="changeDayRangeHandle" @change="changeDayRangeHandle"
style="width: 240px;" style="width: 240px"
class="mr-12" class="mr-12"
/> />
<el-input <el-input
@ -38,25 +38,35 @@
clearable clearable
/> />
<div style="display: flex; align-items: center" class="float-right"> <div style="display: flex; align-items: center" class="float-right">
<el-button @click="dialogVisible = true" <el-button
v-hasPermission="[RoleConst.WORKSPACE_MANAGE.getWorkspaceRole, @click="dialogVisible = true"
RoleConst.USER.getWorkspaceRole, v-hasPermission="[
PermissionConst.APPLICATION_CHAT_LOG_POLICY.getWorkspacePermission]" 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>
<el-button @click="exportLog" <el-button
v-hasPermission="[RoleConst.WORKSPACE_MANAGE.getWorkspaceRole, @click="exportLog"
RoleConst.USER.getWorkspaceRole, v-hasPermission="[
PermissionConst.APPLICATION_CHAT_LOG_EXPORT.getWorkspacePermission]" RoleConst.WORKSPACE_MANAGE.getWorkspaceRole,
RoleConst.USER.getWorkspaceRole,
PermissionConst.APPLICATION_CHAT_LOG_EXPORT.getWorkspacePermission,
]"
> >
{{ $t('common.export') }} {{ $t('common.export') }}
</el-button> </el-button>
<el-button @click="openDocumentDialog" :disabled="multipleSelection.length === 0" <el-button
v-hasPermission="[RoleConst.WORKSPACE_MANAGE.getWorkspaceRole, @click="openDocumentDialog"
RoleConst.USER.getWorkspaceRole, :disabled="multipleSelection.length === 0"
PermissionConst.APPLICATION_CHAT_LOG_EXPORT.getWorkspacePermission]" v-hasPermission="[
>{{ $t('views.chatLog.addToKnowledge') }} RoleConst.WORKSPACE_MANAGE.getWorkspaceRole,
RoleConst.USER.getWorkspaceRole,
PermissionConst.APPLICATION_CHAT_LOG_EXPORT.getWorkspacePermission,
]"
>{{ $t('views.chatLog.addToKnowledge') }}
</el-button> </el-button>
</div> </div>
</div> </div>
@ -285,6 +295,7 @@ import { cloneDeep } from 'lodash'
import ChatRecordDrawer from './component/ChatRecordDrawer.vue' import ChatRecordDrawer from './component/ChatRecordDrawer.vue'
import { MsgSuccess, MsgConfirm } from '@/utils/message' import { MsgSuccess, MsgConfirm } from '@/utils/message'
import chatLogApi from '@/api/application/chat-log' import chatLogApi from '@/api/application/chat-log'
import documentApi from '@/api/knowledge/document'
import { beforeDay, datetimeFormat, nowDate } from '@/utils/time' import { beforeDay, datetimeFormat, nowDate } from '@/utils/time'
import useStore from '@/stores' import useStore from '@/stores'
import type { Dict } from '@/api/type/common' import type { Dict } from '@/api/type/common'
@ -617,7 +628,7 @@ const submitForm = async (formEl: FormInstance | undefined) => {
} }
function getDocument(knowledge_id: string) { 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 documentList.value = res.data
if (localStorage.getItem(id + 'chat_document_id')) { if (localStorage.getItem(id + 'chat_document_id')) {
form.value.document_id = localStorage.getItem(id + 'chat_document_id') as string form.value.document_id = localStorage.getItem(id + 'chat_document_id') as string

View File

@ -140,10 +140,8 @@
import { ref, reactive, computed, onUnmounted } from 'vue' import { ref, reactive, computed, onUnmounted } from 'vue'
import { useRouter, useRoute } from 'vue-router' import { useRouter, useRoute } from 'vue-router'
import { MsgConfirm, MsgSuccess, MsgWarning } from '@/utils/message' import { MsgConfirm, MsgSuccess, MsgWarning } from '@/utils/message'
import { getImgUrl } from '@/utils/utils'
import { t } from '@/locales' import { t } from '@/locales'
import type Node from 'element-plus/es/components/tree/src/model/node' 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' import { loadSharedApi } from '@/utils/dynamics-api/shared-api'
const router = useRouter() const router = useRouter()
@ -151,6 +149,15 @@ const route = useRoute()
const { const {
query: { id, folder_token }, // idknowledgeIDid folder_tokentoken query: { id, folder_token }, // idknowledgeIDid folder_tokentoken
} = route } = 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 knowledgeId = id as string
const folderToken = folder_token as string const folderToken = folder_token as string
@ -187,7 +194,7 @@ const props = {
const loadNode = (node: Node, resolve: (nodeData: Tree[]) => void) => { const loadNode = (node: Node, resolve: (nodeData: Tree[]) => void) => {
const token = node.level === 0 ? folderToken : node.data.token // 使 folder_token使 node.data.token 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) .getLarkDocumentList(knowledgeId, token, {}, loading)
.then((res: any) => { .then((res: any) => {
const nodes = res.data.files as Tree[] 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) console.error('Failed to load tree nodes:', err)
}) })
} }
@ -238,14 +245,14 @@ function submit() {
loading.value = false loading.value = false
return return
} }
documentApi loadSharedApi({ type: 'document', systemType: apiType.value })
.importLarkDocument(knowledgeId, newList, loading) .importLarkDocument(knowledgeId, newList, loading)
.then((res) => { .then(() => {
MsgSuccess(t('views.document.tip.importMessage')) MsgSuccess(t('views.document.tip.importMessage'))
disabled.value = false disabled.value = false
router.go(-1) router.go(-1)
}) })
.catch((err) => { .catch((err: any) => {
console.error('Failed to load tree nodes:', err) console.error('Failed to load tree nodes:', err)
}) })
.finally(() => { .finally(() => {

View File

@ -165,8 +165,8 @@ function submit() {
if (id) { if (id) {
// //
document loadSharedApi({ type: 'document', systemType: apiType.value })
.asyncPutDocument(id as string, documents) .putMulDocument(id as string, documents)
.then(() => { .then(() => {
MsgSuccess(t('common.submitSuccess')) MsgSuccess(t('common.submitSuccess'))
clearStore() clearStore()

View File

@ -92,20 +92,30 @@
</el-dialog> </el-dialog>
</template> </template>
<script setup lang="ts"> <script setup lang="ts">
import { ref, reactive, watch } from 'vue' import { ref, reactive, watch, computed } from 'vue'
import { useRoute } from 'vue-router' import { useRoute } from 'vue-router'
import type { FormInstance } from 'element-plus' import type { FormInstance } from 'element-plus'
import documentApi from '@/api/knowledge/document'
import { MsgSuccess } from '@/utils/message' import { MsgSuccess } from '@/utils/message'
import { hitHandlingMethod } from '@/enums/document' import { hitHandlingMethod } from '@/enums/document'
import { loadSharedApi } from '@/utils/dynamics-api/shared-api'
import { t } from '@/locales' import { t } from '@/locales'
const route = useRoute() const route = useRoute()
const { const {
params: { id } params: { id },
} = route as any } = route as any
const props = defineProps({ 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']) const emit = defineEmits(['refresh'])
@ -116,7 +126,7 @@ const form = ref<any>({
source_url: '', source_url: '',
selector: '', selector: '',
hit_handling_method: 'optimization', hit_handling_method: 'optimization',
directly_return_similarity: 0.9 directly_return_similarity: 0.9,
}) })
// //
@ -131,16 +141,16 @@ const rules = reactive({
{ {
required: true, required: true,
message: t('views.document.form.source_url.requiredMessage'), message: t('views.document.form.source_url.requiredMessage'),
trigger: 'blur' trigger: 'blur',
} },
], ],
directly_return_similarity: [ directly_return_similarity: [
{ {
required: true, required: true,
message: t('views.document.form.similarity.requiredMessage'), message: t('views.document.form.similarity.requiredMessage'),
trigger: 'blur' trigger: 'blur',
} },
] ],
}) })
const dialogVisible = ref<boolean>(false) const dialogVisible = ref<boolean>(false)
@ -151,7 +161,7 @@ watch(dialogVisible, (bool) => {
source_url: '', source_url: '',
selector: '', selector: '',
hit_handling_method: 'optimization', hit_handling_method: 'optimization',
directly_return_similarity: 0.9 directly_return_similarity: 0.9,
} }
isImport.value = false isImport.value = false
documentType.value = '' documentType.value = ''
@ -167,7 +177,7 @@ const open = (row: any, list: Array<string>) => {
form.value = { form.value = {
hit_handling_method: row.hit_handling_method, hit_handling_method: row.hit_handling_method,
directly_return_similarity: row.directly_return_similarity, directly_return_similarity: row.directly_return_similarity,
...row.meta ...row.meta,
} }
isImport.value = false isImport.value = false
} else if (list) { } else if (list) {
@ -188,13 +198,15 @@ const submit = async (formEl: FormInstance | undefined) => {
if (isImport.value) { if (isImport.value) {
const obj = { const obj = {
source_url_list: form.value.source_url.split('\n'), source_url_list: form.value.source_url.split('\n'),
selector: form.value.selector selector: form.value.selector,
} }
documentApi.postWebDocument(id, obj, loading).then(() => { loadSharedApi({ type: 'document', systemType: apiType.value })
MsgSuccess(t('views.document.tip.importMessage')) .postWebDocument(id, obj, loading)
emit('refresh') .then(() => {
dialogVisible.value = false MsgSuccess(t('views.document.tip.importMessage'))
}) emit('refresh')
dialogVisible.value = false
})
} else { } else {
if (documentId.value) { if (documentId.value) {
const obj = { const obj = {
@ -202,26 +214,30 @@ const submit = async (formEl: FormInstance | undefined) => {
directly_return_similarity: form.value.directly_return_similarity, directly_return_similarity: form.value.directly_return_similarity,
meta: { meta: {
source_url: form.value.source_url, source_url: form.value.source_url,
selector: form.value.selector selector: form.value.selector,
} },
} }
documentApi.putDocument(id, documentId.value, obj, loading).then(() => { loadSharedApi({ type: 'document', systemType: apiType.value })
MsgSuccess(t('common.settingSuccess')) .putDocument(id, documentId.value, obj, loading)
emit('refresh') .then(() => {
dialogVisible.value = false MsgSuccess(t('common.settingSuccess'))
}) emit('refresh')
dialogVisible.value = false
})
} else if (documentList.value.length > 0) { } else if (documentList.value.length > 0) {
// //
const obj = { const obj = {
hit_handling_method: form.value.hit_handling_method, hit_handling_method: form.value.hit_handling_method,
directly_return_similarity: form.value.directly_return_similarity, directly_return_similarity: form.value.directly_return_similarity,
id_list: documentList.value id_list: documentList.value,
} }
documentApi.putBatchEditHitHandling(id, obj, loading).then(() => { loadSharedApi({ type: 'document', systemType: apiType.value })
MsgSuccess(t('common.settingSuccess')) .putBatchEditHitHandling(id, obj, loading)
emit('refresh') .then(() => {
dialogVisible.value = false MsgSuccess(t('common.settingSuccess'))
}) emit('refresh')
dialogVisible.value = false
})
} }
} }
} }

View File

@ -58,10 +58,7 @@
<script setup lang="ts"> <script setup lang="ts">
import { ref, watch, computed } from 'vue' import { ref, watch, computed } from 'vue'
import { useRoute } from 'vue-router' import { useRoute } from 'vue-router'
import documentApi from '@/api/knowledge/document'
import { loadSharedApi } from '@/utils/dynamics-api/shared-api' import { loadSharedApi } from '@/utils/dynamics-api/shared-api'
import useStore from '@/stores'
const route = useRoute() const route = useRoute()
const { const {
params: { id }, // idknowledgeID params: { id }, // idknowledgeID
@ -121,9 +118,9 @@ const open = (list: any) => {
} }
const submitHandle = () => { const submitHandle = () => {
documentApi loadSharedApi({ type: 'document', systemType: apiType.value })
.putMigrateMulDocument(id, form.value.selectKnowledge, documentList.value, loading) .putMigrateMulDocument(id, form.value.selectKnowledge, documentList.value, loading)
.then((res) => { .then(() => {
emit('refresh') emit('refresh')
dialogVisible.value = false dialogVisible.value = false
}) })

View File

@ -857,8 +857,8 @@ function rowClickHandle(row: any, column: any) {
function creatQuickHandle(val: string) { function creatQuickHandle(val: string) {
loading.value = true loading.value = true
const obj = [{ name: val }] const obj = [{ name: val }]
document loadSharedApi({ type: 'document', systemType: apiType.value })
.asyncPutDocument(id, obj) .putMulDocument(id, obj)
.then(() => { .then(() => {
getList() getList()
MsgSuccess(t('common.createSuccess')) MsgSuccess(t('common.createSuccess'))

View File

@ -160,7 +160,7 @@ function changeKnowledge(id: string) {
} }
function getDocument(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) documentList.value = res.data?.filter((v: any) => v.id !== documentId)
}) })
} }

View File

@ -109,7 +109,7 @@
</el-dialog> </el-dialog>
</template> </template>
<script setup lang="ts"> <script setup lang="ts">
import { ref, watch, reactive } from 'vue' import { ref, watch, reactive, computed } from 'vue'
import { useRoute } from 'vue-router' import { useRoute } from 'vue-router'
import problemApi from '@/api/knowledge/problem' import problemApi from '@/api/knowledge/problem'
import paragraphApi from '@/api/knowledge/paragraph' import paragraphApi from '@/api/knowledge/paragraph'
@ -123,6 +123,16 @@ const {
params: { id }, // knowledgeId params: { id }, // knowledgeId
} = route as any } = 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 emit = defineEmits(['refresh'])
const dialogVisible = ref<boolean>(false) const dialogVisible = ref<boolean>(false)
@ -214,7 +224,7 @@ function clickDocumentHandle(item: any) {
} }
function getDocument() { function getDocument() {
document.asyncGetKnowledgeDocument(id, loading).then((res: any) => { document.asyncGetKnowledgeDocument(id, apiType.value, loading).then((res: any) => {
cloneDocumentList.value = res.data cloneDocumentList.value = res.data
documentList.value = res.data documentList.value = res.data
currentDocument.value = cloneDocumentList.value?.length > 0 ? cloneDocumentList.value[0].id : '' currentDocument.value = cloneDocumentList.value?.length > 0 ? cloneDocumentList.value[0].id : ''