Skip to content

Commit b45095f

Browse files
feat: knowledge
1 parent 896fb5f commit b45095f

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

52 files changed

+4602
-68
lines changed

ui/src/api/knowledge/document.ts

Lines changed: 420 additions & 0 deletions
Large diffs are not rendered by default.

ui/src/api/knowledge/knowledge.ts

Lines changed: 60 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ const getKnowledgeByFolder: (
2121
}
2222

2323
/**
24-
* 知识库列表
24+
* 知识库分页列表
2525
* @param 参数
2626
* param {
2727
"folder_id": "string",
@@ -43,7 +43,66 @@ const getKnowledgeList: (
4343
)
4444
}
4545

46+
/**
47+
* 获取全部知识库
48+
* @param 参数
49+
*/
50+
// const getAllDataset: (loading?: Ref<boolean>) => Promise<Result<any[]>> = (loading) => {
51+
// return get(`${prefix}`, undefined, loading)
52+
// }
53+
54+
/**
55+
* 同步知识库
56+
* @param 参数 knowledge_id
57+
* @query 参数 sync_type // 同步类型->replace:替换同步,complete:完整同步
58+
*/
59+
const putSyncWebKnowledge: (
60+
wordspace_id: string,
61+
knowledge_id: string,
62+
sync_type: string,
63+
loading?: Ref<boolean>,
64+
) => Promise<Result<any>> = (wordspace_id, knowledge_id, sync_type, loading) => {
65+
return put(
66+
`${prefix}/${wordspace_id}/knowledge/${knowledge_id}/sync`,
67+
undefined,
68+
{ sync_type },
69+
loading,
70+
)
71+
}
72+
73+
/**
74+
* 向量化知识库
75+
* @param 参数 knowledge_id
76+
*/
77+
const putReEmbeddingDataset: (
78+
wordspace_id: string,
79+
knowledge_id: string,
80+
loading?: Ref<boolean>,
81+
) => Promise<Result<any>> = (wordspace_id, knowledge_id, loading) => {
82+
return put(
83+
`${prefix}/${wordspace_id}/knowledge/${knowledge_id}/embedding`,
84+
undefined,
85+
undefined,
86+
loading,
87+
)
88+
}
89+
90+
/**
91+
* 知识库详情
92+
* @param 参数 knowledge_id
93+
*/
94+
const getKnowledgeDetail: (
95+
wordspace_id: string,
96+
knowledge_id: string,
97+
loading?: Ref<boolean>,
98+
) => Promise<Result<any>> = (wordspace_id, knowledge_id, loading) => {
99+
return get(`${prefix}/${wordspace_id}/knowledge/${knowledge_id}`, undefined, loading)
100+
}
101+
46102
export default {
47103
getKnowledgeByFolder,
48104
getKnowledgeList,
105+
putReEmbeddingDataset,
106+
putSyncWebKnowledge,
107+
getKnowledgeDetail,
49108
}

ui/src/api/type/knowledge.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
interface knowledgeData {
2+
name: String
3+
desc: String
4+
documents?: Array<any>
5+
type?: String
6+
embedding_mode_id?: String
7+
}
8+
9+
export type { knowledgeData }
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
import { h } from 'vue'
2+
export default {
3+
'app-document': {
4+
iconReader: () => {
5+
return h('i', [
6+
h(
7+
'svg',
8+
{
9+
viewBox: '0 0 20 20',
10+
version: '1.1',
11+
xmlns: 'http://www.w3.org/2000/svg',
12+
},
13+
[
14+
h('path', {
15+
d: 'M13.3333 2.50016H4.16667V17.5002H15.8333V5.01641H13.75C13.6395 5.01641 13.5335 4.97251 13.4554 4.89437C13.3772 4.81623 13.3333 4.71025 13.3333 4.59975V2.50016ZM3.33333 0.833496H14.2379C14.3474 0.833465 14.4558 0.855013 14.557 0.896908C14.6582 0.938804 14.7501 1.00023 14.8275 1.07766L17.2563 3.50725C17.4124 3.66356 17.5001 3.87548 17.5 4.09641V18.3335C17.5 18.5545 17.4122 18.7665 17.2559 18.9228C17.0996 19.079 16.8877 19.1668 16.6667 19.1668H3.33333C3.11232 19.1668 2.90036 19.079 2.74408 18.9228C2.5878 18.7665 2.5 18.5545 2.5 18.3335V1.66683C2.5 1.44582 2.5878 1.23385 2.74408 1.07757C2.90036 0.921293 3.11232 0.833496 3.33333 0.833496ZM6.66667 8.3335H13.3333C13.4438 8.3335 13.5498 8.3774 13.628 8.45554C13.7061 8.53368 13.75 8.63966 13.75 8.75016V9.5835C13.75 9.694 13.7061 9.79998 13.628 9.87812C13.5498 9.95626 13.4438 10.0002 13.3333 10.0002H6.66667C6.55616 10.0002 6.45018 9.95626 6.37204 9.87812C6.2939 9.79998 6.25 9.694 6.25 9.5835V8.75016C6.25 8.63966 6.2939 8.53368 6.37204 8.45554C6.45018 8.3774 6.55616 8.3335 6.66667 8.3335ZM6.66667 12.5002H10.4167C10.4714 12.5002 10.5256 12.5109 10.5761 12.5319C10.6267 12.5528 10.6726 12.5835 10.7113 12.6222C10.75 12.6609 10.7807 12.7068 10.8016 12.7574C10.8226 12.8079 10.8333 12.8621 10.8333 12.9168V13.7502C10.8333 13.8049 10.8226 13.8591 10.8016 13.9096C10.7807 13.9602 10.75 14.0061 10.7113 14.0448C10.6726 14.0835 10.6267 14.1142 10.5761 14.1351C10.5256 14.1561 10.4714 14.1668 10.4167 14.1668H6.66667C6.55616 14.1668 6.45018 14.1229 6.37204 14.0448C6.2939 13.9667 6.25 13.8607 6.25 13.7502V12.9168C6.25 12.8063 6.2939 12.7003 6.37204 12.6222C6.45018 12.5441 6.55616 12.5002 6.66667 12.5002Z',
16+
fill: 'currentColor',
17+
}),
18+
],
19+
),
20+
])
21+
},
22+
},
23+
'app-document-active': {
24+
iconReader: () => {
25+
return h('i', [
26+
h(
27+
'svg',
28+
{
29+
viewBox: '0 0 20 20',
30+
version: '1.1',
31+
xmlns: 'http://www.w3.org/2000/svg',
32+
},
33+
[
34+
h('path', {
35+
d: 'M3.3335 2.08333C3.3335 1.6231 3.70659 1.25 4.16683 1.25H12.3842C12.4959 1.25 12.603 1.29489 12.6813 1.37459L16.5473 5.30784C16.6239 5.38576 16.6668 5.49065 16.6668 5.59992V17.9167C16.6668 18.3769 16.2937 18.75 15.8335 18.75H4.16683C3.70659 18.75 3.3335 18.3769 3.3335 17.9167V2.08333Z',
36+
fill: 'currentColor',
37+
}),
38+
h('path', {
39+
d: 'M12.5 1.2666C12.568 1.28633 12.6306 1.32327 12.6812 1.37472L16.5472 5.30797C16.5788 5.34017 16.6047 5.37698 16.6242 5.4168H13.4459C12.9235 5.4168 12.5 4.99328 12.5 4.47085V1.2666Z',
40+
fill: '#2B5FD9',
41+
}),
42+
h('path', {
43+
d: 'M6.71305 7.72705C6.48293 7.72705 6.29639 7.9136 6.29639 8.14372V8.82554C6.29639 9.05565 6.48294 9.2422 6.71305 9.2422H13.2871C13.5172 9.2422 13.7038 9.05565 13.7038 8.82554V8.14372C13.7038 7.9136 13.5172 7.72705 13.2871 7.72705H6.71305Z',
44+
fill: 'white',
45+
}),
46+
h('path', {
47+
d: 'M6.71305 11.5149C6.48293 11.5149 6.29639 11.7015 6.29639 11.9316V12.6134C6.29639 12.8435 6.48294 13.0301 6.71305 13.0301H9.58342C9.81354 13.0301 10.0001 12.8435 10.0001 12.6134V11.9316C10.0001 11.7015 9.81354 11.5149 9.58342 11.5149H6.71305Z',
48+
fill: 'white',
49+
}),
50+
],
51+
),
52+
])
53+
},
54+
},
55+
}
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
import { h } from 'vue'
2+
export default {
3+
'app-vectorization': {
4+
iconReader: () => {
5+
return h('i', [
6+
h(
7+
'svg',
8+
{
9+
style: { height: '100%', width: '100%' },
10+
viewBox: '0 0 1024 1024',
11+
version: '1.1',
12+
xmlns: 'http://www.w3.org/2000/svg',
13+
},
14+
[
15+
h('path', {
16+
d: 'M512 170.666667a85.333333 85.333333 0 0 1 85.333333-85.333334h256a85.333333 85.333333 0 0 1 85.333334 85.333334v256a85.333333 85.333333 0 0 1-85.333334 85.333333h-256a85.333333 85.333333 0 0 1-85.333333-85.333333V170.666667z m85.333333 0v256h256V170.666667h-256zM85.333333 597.333333a85.333333 85.333333 0 0 1 85.333334-85.333333h256a85.333333 85.333333 0 0 1 85.333333 85.333333v256a85.333333 85.333333 0 0 1-85.333333 85.333334H170.666667a85.333333 85.333333 0 0 1-85.333334-85.333334v-256z m85.333334 0v256h256v-256H170.666667zM128 298.666667a213.333333 213.333333 0 0 1 213.333333-213.333334h85.333334v85.333334H341.333333a128 128 0 0 0-128 128h57.514667a12.8 12.8 0 0 1 9.728 21.12l-100.181333 116.906666a12.8 12.8 0 0 1-19.456 0l-100.181334-116.906666A12.8 12.8 0 0 1 70.485333 298.666667H128zM896 725.333333a213.333333 213.333333 0 0 1-213.333333 213.333334h-85.333334v-85.333334h85.333334a128 128 0 0 0 128-128v-21.333333h-57.514667a12.8 12.8 0 0 1-9.728-21.12l100.181333-116.906667a12.8 12.8 0 0 1 19.456 0l100.181334 116.906667a12.8 12.8 0 0 1-9.728 21.12H896v21.333333z',
17+
fill: 'currentColor',
18+
}),
19+
],
20+
),
21+
])
22+
},
23+
},
24+
'app-all-menu-active': {
25+
iconReader: () => {
26+
return h('i', [
27+
h(
28+
'svg',
29+
{
30+
style: { height: '100%', width: '100%' },
31+
viewBox: '0 0 20 20',
32+
version: '1.1',
33+
xmlns: 'http://www.w3.org/2000/svg',
34+
},
35+
[
36+
h('path', {
37+
d: 'M8.33317 1.6665H2.49984C2.0396 1.6665 1.6665 2.0396 1.6665 2.49984V8.33317C1.6665 8.79341 2.0396 9.1665 2.49984 9.1665H8.33317C8.79341 9.1665 9.1665 8.79341 9.1665 8.33317V2.49984C9.1665 2.0396 8.79341 1.6665 8.33317 1.6665Z',
38+
fill: 'currentColor',
39+
}),
40+
h('path', {
41+
d: 'M8.33317 10.8332H2.49984C2.0396 10.8332 1.6665 11.2063 1.6665 11.6665V17.4998C1.6665 17.9601 2.0396 18.3332 2.49984 18.3332H8.33317C8.79341 18.3332 9.1665 17.9601 9.1665 17.4998V11.6665C9.1665 11.2063 8.79341 10.8332 8.33317 10.8332Z',
42+
fill: 'currentColor',
43+
}),
44+
h('path', {
45+
d: 'M17.4998 1.6665H11.6665C11.2063 1.6665 10.8332 2.0396 10.8332 2.49984V8.33317C10.8332 8.79341 11.2063 9.1665 11.6665 9.1665H17.4998C17.9601 9.1665 18.3332 8.79341 18.3332 8.33317V2.49984C18.3332 2.0396 17.9601 1.6665 17.4998 1.6665Z',
46+
fill: 'currentColor',
47+
}),
48+
h('path', {
49+
d: 'M17.4508 10.8332H11.7155C11.2282 10.8332 10.8332 11.2282 10.8332 11.7155V17.4508C10.8332 17.9381 11.2282 18.3332 11.7155 18.3332H17.4508C17.9381 18.3332 18.3332 17.9381 18.3332 17.4508V11.7155C18.3332 11.2282 17.9381 10.8332 17.4508 10.8332Z',
50+
fill: 'currentColor',
51+
}),
52+
],
53+
),
54+
])
55+
},
56+
},
57+
}
Lines changed: 159 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,159 @@
1+
<template>
2+
<div class="app-table" :class="quickCreate ? 'table-quick-append' : ''">
3+
<el-table :max-height="tableHeight" v-bind="$attrs" ref="appTableRef">
4+
<template #append v-if="quickCreate">
5+
<div v-if="showInput">
6+
<el-input
7+
ref="quickInputRef"
8+
v-model="inputValue"
9+
:placeholder="`${$t('common.inputPlaceholder')} ${quickCreateName}`"
10+
class="w-500 mr-12"
11+
autofocus
12+
:maxlength="quickCreateMaxlength || '-'"
13+
:show-word-limit="quickCreateMaxlength ? true : false"
14+
@keydown.enter="submitHandle"
15+
clearable
16+
/>
17+
18+
<el-button type="primary" @click="submitHandle" :disabled="loading">{{$t('common.create')}}</el-button>
19+
<el-button @click="showInput = false" :disabled="loading">{{$t('common.cancel')}}</el-button>
20+
</div>
21+
<div v-else @click="quickCreateHandle" class="w-full">
22+
<el-button type="primary" link class="quich-button">
23+
<el-icon><Plus /></el-icon>
24+
<span class="ml-4">{{ quickCreatePlaceholder }}</span>
25+
</el-button>
26+
</div>
27+
</template>
28+
<slot></slot>
29+
</el-table>
30+
<div class="app-table__pagination mt-16" v-if="$slots.pagination || paginationConfig">
31+
<slot name="pagination">
32+
<el-pagination
33+
v-model:current-page="paginationConfig.current_page"
34+
v-model:page-size="paginationConfig.page_size"
35+
:page-sizes="pageSizes"
36+
:total="paginationConfig.total"
37+
layout="total, prev, pager, next, sizes"
38+
@size-change="handleSizeChange"
39+
@current-change="handleCurrentChange"
40+
/>
41+
</slot>
42+
</div>
43+
</div>
44+
</template>
45+
<script setup lang="ts">
46+
import { ref, nextTick, watch, computed, onMounted } from 'vue'
47+
import { MsgError } from '@/utils/message'
48+
import { t } from '@/locales'
49+
defineOptions({ name: 'AppTable' })
50+
51+
import useStore from '@/stores'
52+
const { common } = useStore()
53+
54+
const props = defineProps({
55+
paginationConfig: {
56+
type: Object,
57+
default: () => {}
58+
},
59+
quickCreate: {
60+
type: Boolean,
61+
default: false
62+
},
63+
quickCreateName: {
64+
type: String,
65+
default: t('components.quickCreateName')
66+
},
67+
quickCreatePlaceholder: {
68+
type: String,
69+
default: t('components.quickCreatePlaceholder')
70+
},
71+
quickCreateMaxlength: {
72+
type: Number,
73+
default: () => 0
74+
},
75+
storeKey: String
76+
})
77+
const emit = defineEmits(['changePage', 'sizeChange', 'creatQuick'])
78+
79+
const paginationConfig = computed(() => props.paginationConfig)
80+
81+
const pageSizes = [10, 20, 50, 100]
82+
83+
const quickInputRef = ref()
84+
const appTableRef = ref()
85+
86+
const loading = ref(false)
87+
const showInput = ref(false)
88+
const inputValue = ref('')
89+
const tableHeight = ref(0)
90+
91+
watch(showInput, (bool) => {
92+
if (!bool) {
93+
inputValue.value = ''
94+
}
95+
})
96+
97+
function submitHandle() {
98+
if (inputValue.value) {
99+
loading.value = true
100+
emit('creatQuick', inputValue.value)
101+
setTimeout(() => {
102+
showInput.value = false
103+
loading.value = false
104+
}, 200)
105+
} else {
106+
MsgError(`${props.quickCreateName} ${t('dynamicsForm.tip.requiredMessage')}`)
107+
}
108+
}
109+
110+
function quickCreateHandle() {
111+
showInput.value = true
112+
nextTick(() => {
113+
quickInputRef.value?.focus()
114+
})
115+
}
116+
117+
function handleSizeChange() {
118+
emit('sizeChange')
119+
if (props.storeKey) {
120+
common.savePage(props.storeKey, props.paginationConfig)
121+
}
122+
}
123+
function handleCurrentChange() {
124+
emit('changePage')
125+
if (props.storeKey) {
126+
common.savePage(props.storeKey, props.paginationConfig)
127+
}
128+
}
129+
130+
function clearSelection() {
131+
appTableRef.value?.clearSelection()
132+
}
133+
defineExpose({
134+
clearSelection
135+
})
136+
137+
onMounted(() => {
138+
tableHeight.value = window.innerHeight - 300
139+
window.onresize = () => {
140+
return (() => {
141+
tableHeight.value = window.innerHeight - 300
142+
})()
143+
}
144+
})
145+
</script>
146+
147+
<style lang="scss" scoped>
148+
.app-table {
149+
&__pagination {
150+
display: flex;
151+
justify-content: flex-end;
152+
}
153+
.quich-button {
154+
&:hover {
155+
color: var(--el-button-text-color);
156+
}
157+
}
158+
}
159+
</style>
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
<template>
2+
<el-button class="back-button cursor mr-4" text @click="jump">
3+
<el-icon :size="20">
4+
<Back />
5+
</el-icon>
6+
</el-button>
7+
</template>
8+
9+
<script setup lang="ts">
10+
import { useRouter, type RouteLocationRaw } from 'vue-router'
11+
defineOptions({ name: 'BackButton' })
12+
const router = useRouter()
13+
const props = defineProps({
14+
to: String
15+
})
16+
17+
const emit = defineEmits(['click'])
18+
/* 上一层路由 */
19+
const back: any = router.options.history.state.back
20+
function jump() {
21+
if (props.to === '-1') {
22+
back ? router.push(back) : router.go(-1)
23+
} else if (props.to) {
24+
router.push(props.to as RouteLocationRaw)
25+
} else {
26+
emit('click')
27+
}
28+
}
29+
</script>
30+
31+
<style lang="scss"></style>

0 commit comments

Comments
 (0)