Skip to content

Commit 46fb1b1

Browse files
feat: shared
1 parent 2570114 commit 46fb1b1

File tree

10 files changed

+118
-84
lines changed

10 files changed

+118
-84
lines changed

ui/src/stores/modules/document.ts

Lines changed: 9 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,22 @@
11
import { defineStore } from 'pinia'
2-
import documentApi from '@/api/knowledge/document'
32
import { type Ref } from 'vue'
3+
import { loadSharedApi } from '@/utils/dynamics-api/shared-api'
44

55
const useDocumentStore = defineStore('document', {
66
state: () => ({}),
77
actions: {
8-
async asyncGetKnowledgeDocument(id: string, loading?: Ref<boolean>) {
8+
async asyncGetKnowledgeDocument(
9+
id: string,
10+
systemType: 'systemShare' | 'workspace' | 'systemManage' = 'workspace',
11+
loading?: Ref<boolean>,
12+
) {
913
return new Promise((resolve, reject) => {
10-
documentApi
14+
loadSharedApi({ type: 'document', systemType })
1115
.getDocumentList(id, loading)
12-
.then((res) => {
16+
.then((res: any) => {
1317
resolve(res)
1418
})
15-
.catch((error) => {
16-
reject(error)
17-
})
18-
})
19-
},
20-
async asyncPutDocument(knowledgeId: string, data: any, loading?: Ref<boolean>) {
21-
return new Promise((resolve, reject) => {
22-
documentApi
23-
.putMulDocument(knowledgeId, data, loading)
24-
.then((data) => {
25-
resolve(data)
26-
})
27-
.catch((error) => {
19+
.catch((error: any) => {
2820
reject(error)
2921
})
3022
})

ui/src/views/chat-log/component/EditContentDialog.vue

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@ import { useRoute } from 'vue-router'
100100
import type { FormInstance, FormRules } from 'element-plus'
101101
import chatLogApi from '@/api/application/chat-log'
102102
import imageApi from '@/api/image'
103+
import documentApi from '@/api/knowledge/document'
103104
import useStore from '@/stores'
104105
import { t } from '@/locales'
105106
const { application, document, user } = useStore()
@@ -217,7 +218,7 @@ function changeDocument(document_id: string) {
217218
}
218219
219220
function getDocument(knowledge_id: string) {
220-
document.asyncGetKnowledgeDocument(knowledge_id, loading).then((res: any) => {
221+
documentApi.getDocumentList(knowledge_id, loading).then((res: any) => {
221222
documentList.value = res.data
222223
if (localStorage.getItem(id + 'chat_document_id')) {
223224
form.value.document_id = localStorage.getItem(id + 'chat_document_id') as string

ui/src/views/chat-log/index.vue

Lines changed: 27 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
format="YYYY-MM-DD"
2727
value-format="YYYY-MM-DD"
2828
@change="changeDayRangeHandle"
29-
style="width: 240px;"
29+
style="width: 240px"
3030
class="mr-12"
3131
/>
3232
<el-input
@@ -38,25 +38,35 @@
3838
clearable
3939
/>
4040
<div style="display: flex; align-items: center" class="float-right">
41-
<el-button @click="dialogVisible = true"
42-
v-hasPermission="[RoleConst.WORKSPACE_MANAGE.getWorkspaceRole,
43-
RoleConst.USER.getWorkspaceRole,
44-
PermissionConst.APPLICATION_CHAT_LOG_POLICY.getWorkspacePermission]"
41+
<el-button
42+
@click="dialogVisible = true"
43+
v-hasPermission="[
44+
RoleConst.WORKSPACE_MANAGE.getWorkspaceRole,
45+
RoleConst.USER.getWorkspaceRole,
46+
PermissionConst.APPLICATION_CHAT_LOG_POLICY.getWorkspacePermission,
47+
]"
4548
>
46-
{{$t('views.chatLog.buttons.clearStrategy')}}
49+
{{ $t('views.chatLog.buttons.clearStrategy') }}
4750
</el-button>
48-
<el-button @click="exportLog"
49-
v-hasPermission="[RoleConst.WORKSPACE_MANAGE.getWorkspaceRole,
50-
RoleConst.USER.getWorkspaceRole,
51-
PermissionConst.APPLICATION_CHAT_LOG_EXPORT.getWorkspacePermission]"
51+
<el-button
52+
@click="exportLog"
53+
v-hasPermission="[
54+
RoleConst.WORKSPACE_MANAGE.getWorkspaceRole,
55+
RoleConst.USER.getWorkspaceRole,
56+
PermissionConst.APPLICATION_CHAT_LOG_EXPORT.getWorkspacePermission,
57+
]"
5258
>
5359
{{ $t('common.export') }}
5460
</el-button>
55-
<el-button @click="openDocumentDialog" :disabled="multipleSelection.length === 0"
56-
v-hasPermission="[RoleConst.WORKSPACE_MANAGE.getWorkspaceRole,
57-
RoleConst.USER.getWorkspaceRole,
58-
PermissionConst.APPLICATION_CHAT_LOG_EXPORT.getWorkspacePermission]"
59-
>{{ $t('views.chatLog.addToKnowledge') }}
61+
<el-button
62+
@click="openDocumentDialog"
63+
:disabled="multipleSelection.length === 0"
64+
v-hasPermission="[
65+
RoleConst.WORKSPACE_MANAGE.getWorkspaceRole,
66+
RoleConst.USER.getWorkspaceRole,
67+
PermissionConst.APPLICATION_CHAT_LOG_EXPORT.getWorkspacePermission,
68+
]"
69+
>{{ $t('views.chatLog.addToKnowledge') }}
6070
</el-button>
6171
</div>
6272
</div>
@@ -285,6 +295,7 @@ import { cloneDeep } from 'lodash'
285295
import ChatRecordDrawer from './component/ChatRecordDrawer.vue'
286296
import { MsgSuccess, MsgConfirm } from '@/utils/message'
287297
import chatLogApi from '@/api/application/chat-log'
298+
import documentApi from '@/api/knowledge/document'
288299
import { beforeDay, datetimeFormat, nowDate } from '@/utils/time'
289300
import useStore from '@/stores'
290301
import type { Dict } from '@/api/type/common'
@@ -617,7 +628,7 @@ const submitForm = async (formEl: FormInstance | undefined) => {
617628
}
618629
619630
function getDocument(knowledge_id: string) {
620-
document.asyncGetKnowledgeDocument(knowledge_id, documentLoading).then((res: any) => {
631+
documentApi.getDocumentList(knowledge_id, documentLoading).then((res: any) => {
621632
documentList.value = res.data
622633
if (localStorage.getItem(id + 'chat_document_id')) {
623634
form.value.document_id = localStorage.getItem(id + 'chat_document_id') as string

ui/src/views/document/ImportLarkDocument.vue

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -140,17 +140,24 @@
140140
import { ref, reactive, computed, onUnmounted } from 'vue'
141141
import { useRouter, useRoute } from 'vue-router'
142142
import { MsgConfirm, MsgSuccess, MsgWarning } from '@/utils/message'
143-
import { getImgUrl } from '@/utils/utils'
144143
import { t } from '@/locales'
145144
import type Node from 'element-plus/es/components/tree/src/model/node'
146-
import documentApi from '@/api/knowledge/document'
147145
import { loadSharedApi } from '@/utils/dynamics-api/shared-api'
148146
149147
const router = useRouter()
150148
const route = useRoute()
151149
const {
152150
query: { id, folder_token }, // id为knowledgeID,有id的是上传文档 folder_token为飞书文件夹token
153151
} = route
152+
const apiType = computed(() => {
153+
if (route.path.includes('shared')) {
154+
return 'systemShare'
155+
} else if (route.path.includes('resource-management')) {
156+
return 'systemManage'
157+
} else {
158+
return 'workspace'
159+
}
160+
})
154161
const knowledgeId = id as string
155162
const folderToken = folder_token as string
156163
@@ -187,7 +194,7 @@ const props = {
187194
188195
const loadNode = (node: Node, resolve: (nodeData: Tree[]) => void) => {
189196
const token = node.level === 0 ? folderToken : node.data.token // 根节点使用 folder_token,其他节点使用 node.data.token
190-
documentApi
197+
loadSharedApi({ type: 'document', systemType: apiType.value })
191198
.getLarkDocumentList(knowledgeId, token, {}, loading)
192199
.then((res: any) => {
193200
const nodes = res.data.files as Tree[]
@@ -199,7 +206,7 @@ const loadNode = (node: Node, resolve: (nodeData: Tree[]) => void) => {
199206
})
200207
})
201208
202-
.catch((err) => {
209+
.catch((err: any) => {
203210
console.error('Failed to load tree nodes:', err)
204211
})
205212
}
@@ -238,14 +245,14 @@ function submit() {
238245
loading.value = false
239246
return
240247
}
241-
documentApi
248+
loadSharedApi({ type: 'document', systemType: apiType.value })
242249
.importLarkDocument(knowledgeId, newList, loading)
243-
.then((res) => {
250+
.then(() => {
244251
MsgSuccess(t('views.document.tip.importMessage'))
245252
disabled.value = false
246253
router.go(-1)
247254
})
248-
.catch((err) => {
255+
.catch((err: any) => {
249256
console.error('Failed to load tree nodes:', err)
250257
})
251258
.finally(() => {

ui/src/views/document/UploadDocument.vue

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -165,8 +165,8 @@ function submit() {
165165
166166
if (id) {
167167
// 上传文档
168-
document
169-
.asyncPutDocument(id as string, documents)
168+
loadSharedApi({ type: 'document', systemType: apiType.value })
169+
.putMulDocument(id as string, documents)
170170
.then(() => {
171171
MsgSuccess(t('common.submitSuccess'))
172172
clearStore()

ui/src/views/document/component/ImportDocumentDialog.vue

Lines changed: 47 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -92,20 +92,30 @@
9292
</el-dialog>
9393
</template>
9494
<script setup lang="ts">
95-
import { ref, reactive, watch } from 'vue'
95+
import { ref, reactive, watch, computed } from 'vue'
9696
import { useRoute } from 'vue-router'
9797
import type { FormInstance } from 'element-plus'
98-
import documentApi from '@/api/knowledge/document'
9998
import { MsgSuccess } from '@/utils/message'
10099
import { hitHandlingMethod } from '@/enums/document'
100+
import { loadSharedApi } from '@/utils/dynamics-api/shared-api'
101101
import { t } from '@/locales'
102102
const route = useRoute()
103103
const {
104-
params: { id }
104+
params: { id },
105105
} = route as any
106106
107107
const props = defineProps({
108-
title: String
108+
title: String,
109+
})
110+
111+
const apiType = computed(() => {
112+
if (route.path.includes('shared')) {
113+
return 'systemShare'
114+
} else if (route.path.includes('resource-management')) {
115+
return 'systemManage'
116+
} else {
117+
return 'workspace'
118+
}
109119
})
110120
111121
const emit = defineEmits(['refresh'])
@@ -116,7 +126,7 @@ const form = ref<any>({
116126
source_url: '',
117127
selector: '',
118128
hit_handling_method: 'optimization',
119-
directly_return_similarity: 0.9
129+
directly_return_similarity: 0.9,
120130
})
121131
122132
// 文档设置
@@ -131,16 +141,16 @@ const rules = reactive({
131141
{
132142
required: true,
133143
message: t('views.document.form.source_url.requiredMessage'),
134-
trigger: 'blur'
135-
}
144+
trigger: 'blur',
145+
},
136146
],
137147
directly_return_similarity: [
138148
{
139149
required: true,
140150
message: t('views.document.form.similarity.requiredMessage'),
141-
trigger: 'blur'
142-
}
143-
]
151+
trigger: 'blur',
152+
},
153+
],
144154
})
145155
146156
const dialogVisible = ref<boolean>(false)
@@ -151,7 +161,7 @@ watch(dialogVisible, (bool) => {
151161
source_url: '',
152162
selector: '',
153163
hit_handling_method: 'optimization',
154-
directly_return_similarity: 0.9
164+
directly_return_similarity: 0.9,
155165
}
156166
isImport.value = false
157167
documentType.value = ''
@@ -167,7 +177,7 @@ const open = (row: any, list: Array<string>) => {
167177
form.value = {
168178
hit_handling_method: row.hit_handling_method,
169179
directly_return_similarity: row.directly_return_similarity,
170-
...row.meta
180+
...row.meta,
171181
}
172182
isImport.value = false
173183
} else if (list) {
@@ -188,40 +198,46 @@ const submit = async (formEl: FormInstance | undefined) => {
188198
if (isImport.value) {
189199
const obj = {
190200
source_url_list: form.value.source_url.split('\n'),
191-
selector: form.value.selector
201+
selector: form.value.selector,
192202
}
193-
documentApi.postWebDocument(id, obj, loading).then(() => {
194-
MsgSuccess(t('views.document.tip.importMessage'))
195-
emit('refresh')
196-
dialogVisible.value = false
197-
})
203+
loadSharedApi({ type: 'document', systemType: apiType.value })
204+
.postWebDocument(id, obj, loading)
205+
.then(() => {
206+
MsgSuccess(t('views.document.tip.importMessage'))
207+
emit('refresh')
208+
dialogVisible.value = false
209+
})
198210
} else {
199211
if (documentId.value) {
200212
const obj = {
201213
hit_handling_method: form.value.hit_handling_method,
202214
directly_return_similarity: form.value.directly_return_similarity,
203215
meta: {
204216
source_url: form.value.source_url,
205-
selector: form.value.selector
206-
}
217+
selector: form.value.selector,
218+
},
207219
}
208-
documentApi.putDocument(id, documentId.value, obj, loading).then(() => {
209-
MsgSuccess(t('common.settingSuccess'))
210-
emit('refresh')
211-
dialogVisible.value = false
212-
})
220+
loadSharedApi({ type: 'document', systemType: apiType.value })
221+
.putDocument(id, documentId.value, obj, loading)
222+
.then(() => {
223+
MsgSuccess(t('common.settingSuccess'))
224+
emit('refresh')
225+
dialogVisible.value = false
226+
})
213227
} else if (documentList.value.length > 0) {
214228
// 批量设置
215229
const obj = {
216230
hit_handling_method: form.value.hit_handling_method,
217231
directly_return_similarity: form.value.directly_return_similarity,
218-
id_list: documentList.value
232+
id_list: documentList.value,
219233
}
220-
documentApi.putBatchEditHitHandling(id, obj, loading).then(() => {
221-
MsgSuccess(t('common.settingSuccess'))
222-
emit('refresh')
223-
dialogVisible.value = false
224-
})
234+
loadSharedApi({ type: 'document', systemType: apiType.value })
235+
.putBatchEditHitHandling(id, obj, loading)
236+
.then(() => {
237+
MsgSuccess(t('common.settingSuccess'))
238+
emit('refresh')
239+
dialogVisible.value = false
240+
})
225241
}
226242
}
227243
}

ui/src/views/document/component/SelectKnowledgeDialog.vue

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -58,10 +58,7 @@
5858
<script setup lang="ts">
5959
import { ref, watch, computed } from 'vue'
6060
import { useRoute } from 'vue-router'
61-
import documentApi from '@/api/knowledge/document'
6261
import { loadSharedApi } from '@/utils/dynamics-api/shared-api'
63-
64-
import useStore from '@/stores'
6562
const route = useRoute()
6663
const {
6764
params: { id }, // id为knowledgeID
@@ -121,9 +118,9 @@ const open = (list: any) => {
121118
}
122119
123120
const submitHandle = () => {
124-
documentApi
121+
loadSharedApi({ type: 'document', systemType: apiType.value })
125122
.putMigrateMulDocument(id, form.value.selectKnowledge, documentList.value, loading)
126-
.then((res) => {
123+
.then(() => {
127124
emit('refresh')
128125
dialogVisible.value = false
129126
})

ui/src/views/document/index.vue

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -857,8 +857,8 @@ function rowClickHandle(row: any, column: any) {
857857
function creatQuickHandle(val: string) {
858858
loading.value = true
859859
const obj = [{ name: val }]
860-
document
861-
.asyncPutDocument(id, obj)
860+
loadSharedApi({ type: 'document', systemType: apiType.value })
861+
.putMulDocument(id, obj)
862862
.then(() => {
863863
getList()
864864
MsgSuccess(t('common.createSuccess'))

ui/src/views/paragraph/component/SelectDocumentDialog.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ function changeKnowledge(id: string) {
160160
}
161161
162162
function getDocument(id: string) {
163-
document.asyncGetKnowledgeDocument(id, optionLoading).then((res: any) => {
163+
document.asyncGetKnowledgeDocument(id, apiType.value, optionLoading).then((res: any) => {
164164
documentList.value = res.data?.filter((v: any) => v.id !== documentId)
165165
})
166166
}

0 commit comments

Comments
 (0)