This commit is contained in:
amb
2026-09-01 13:57:34 +08:00
parent dfd38c99a0
commit 4db2d1a411
23 changed files with 2496 additions and 140 deletions
+484 -4
View File
@@ -1,14 +1,494 @@
import { ref, onMounted } from 'vue';
import { useRoute } from 'vue-router';
import { ElMessage, ElMessageBox } from 'element-plus';
import apiClient from '@/api/client';
const route = useRoute();
const kbId = route.params.id;
const kb = ref(null);
const docs = ref([]);
const loading = ref(false);
const uploading = ref(false);
const aiUrl = ref('');
onMounted(async () => {
await loadKb();
await loadDocs();
await loadLink();
});
async function loadKb() {
try {
const { data } = await apiClient.get(`/knowledge-bases/${kbId}`);
kb.value = data;
}
catch { /* ignore */ }
}
async function loadDocs() {
loading.value = true;
try {
const { data } = await apiClient.get(`/documents?kb_id=${kbId}`);
docs.value = data.items;
}
catch { /* ignore */ }
loading.value = false;
}
async function loadLink() {
try {
const { data } = await apiClient.get(`/knowledge-bases/${kbId}/link`);
aiUrl.value = `${window.location.origin}/k/${data.token}`;
}
catch { /* ignore */ }
}
async function handleUpload(options) {
uploading.value = true;
try {
const formData = new FormData();
formData.append('kb_id', kbId);
formData.append('file', options.file);
await apiClient.post('/documents/upload', formData, {
headers: { 'Content-Type': 'multipart/form-data' },
});
ElMessage.success('文档上传成功!');
loadDocs();
}
catch { /* ignore */ }
uploading.value = false;
}
async function handleDeleteDoc(doc) {
try {
await ElMessageBox.confirm(`确定删除文档「${doc.original_filename}」?`, '确认删除', { type: 'warning' });
await apiClient.delete(`/documents/${doc.id}`);
ElMessage.success('已删除。');
loadDocs();
}
catch { /* ignore */ }
}
async function handleReprocess(doc) {
try {
await apiClient.post(`/documents/${doc.id}/reprocess`);
ElMessage.success('重新解析已提交。');
loadDocs();
}
catch { /* ignore */ }
}
async function handleCopyLink() {
try {
await navigator.clipboard.writeText(aiUrl.value);
ElMessage.success('AI 链接已复制!');
}
catch { /* ignore */ }
}
async function handleRegenerate() {
try {
await ElMessageBox.confirm('重新生成链接后,旧链接将立即失效。确定继续?', '确认', { type: 'warning' });
const { data } = await apiClient.post(`/knowledge-bases/${kbId}/regenerate-token`);
aiUrl.value = `${window.location.origin}/k/${data.token}`;
ElMessage.success('链接已重新生成。');
}
catch { /* ignore */ }
}
function formatSize(bytes) {
if (bytes < 1024)
return bytes + ' B';
if (bytes < 1024 * 1024)
return (bytes / 1024).toFixed(1) + ' KB';
return (bytes / (1024 * 1024)).toFixed(1) + ' MB';
}
function statusType(status) {
if (status === 'READY')
return 'success';
if (status === 'FAILED')
return 'danger';
return 'warning';
}
debugger; /* PartiallyEnd: #3632/scriptSetup.vue */
const __VLS_ctx = {};
let __VLS_components;
let __VLS_directives;
__VLS_asFunctionalElement(__VLS_intrinsicElements.div, __VLS_intrinsicElements.div)({});
__VLS_asFunctionalElement(__VLS_intrinsicElements.h1, __VLS_intrinsicElements.h1)({});
__VLS_asFunctionalElement(__VLS_intrinsicElements.p, __VLS_intrinsicElements.p)({});
if (__VLS_ctx.kb) {
__VLS_asFunctionalElement(__VLS_intrinsicElements.div, __VLS_intrinsicElements.div)({});
__VLS_asFunctionalElement(__VLS_intrinsicElements.div, __VLS_intrinsicElements.div)({
...{ style: {} },
});
__VLS_asFunctionalElement(__VLS_intrinsicElements.h1, __VLS_intrinsicElements.h1)({
...{ style: {} },
});
(__VLS_ctx.kb.name);
const __VLS_0 = {}.ElButton;
/** @type {[typeof __VLS_components.ElButton, typeof __VLS_components.elButton, typeof __VLS_components.ElButton, typeof __VLS_components.elButton, ]} */ ;
// @ts-ignore
const __VLS_1 = __VLS_asFunctionalComponent(__VLS_0, new __VLS_0({
...{ 'onClick': {} },
type: "primary",
}));
const __VLS_2 = __VLS_1({
...{ 'onClick': {} },
type: "primary",
}, ...__VLS_functionalComponentArgsRest(__VLS_1));
let __VLS_4;
let __VLS_5;
let __VLS_6;
const __VLS_7 = {
onClick: (__VLS_ctx.handleCopyLink)
};
__VLS_3.slots.default;
var __VLS_3;
const __VLS_8 = {}.ElCard;
/** @type {[typeof __VLS_components.ElCard, typeof __VLS_components.elCard, typeof __VLS_components.ElCard, typeof __VLS_components.elCard, ]} */ ;
// @ts-ignore
const __VLS_9 = __VLS_asFunctionalComponent(__VLS_8, new __VLS_8({
...{ style: {} },
}));
const __VLS_10 = __VLS_9({
...{ style: {} },
}, ...__VLS_functionalComponentArgsRest(__VLS_9));
__VLS_11.slots.default;
const __VLS_12 = {}.ElDescriptions;
/** @type {[typeof __VLS_components.ElDescriptions, typeof __VLS_components.elDescriptions, typeof __VLS_components.ElDescriptions, typeof __VLS_components.elDescriptions, ]} */ ;
// @ts-ignore
const __VLS_13 = __VLS_asFunctionalComponent(__VLS_12, new __VLS_12({
column: (2),
border: true,
}));
const __VLS_14 = __VLS_13({
column: (2),
border: true,
}, ...__VLS_functionalComponentArgsRest(__VLS_13));
__VLS_15.slots.default;
const __VLS_16 = {}.ElDescriptionsItem;
/** @type {[typeof __VLS_components.ElDescriptionsItem, typeof __VLS_components.elDescriptionsItem, typeof __VLS_components.ElDescriptionsItem, typeof __VLS_components.elDescriptionsItem, ]} */ ;
// @ts-ignore
const __VLS_17 = __VLS_asFunctionalComponent(__VLS_16, new __VLS_16({
label: "描述",
}));
const __VLS_18 = __VLS_17({
label: "描述",
}, ...__VLS_functionalComponentArgsRest(__VLS_17));
__VLS_19.slots.default;
(__VLS_ctx.kb.description || '无');
var __VLS_19;
const __VLS_20 = {}.ElDescriptionsItem;
/** @type {[typeof __VLS_components.ElDescriptionsItem, typeof __VLS_components.elDescriptionsItem, typeof __VLS_components.ElDescriptionsItem, typeof __VLS_components.elDescriptionsItem, ]} */ ;
// @ts-ignore
const __VLS_21 = __VLS_asFunctionalComponent(__VLS_20, new __VLS_20({
label: "状态",
}));
const __VLS_22 = __VLS_21({
label: "状态",
}, ...__VLS_functionalComponentArgsRest(__VLS_21));
__VLS_23.slots.default;
const __VLS_24 = {}.ElTag;
/** @type {[typeof __VLS_components.ElTag, typeof __VLS_components.elTag, typeof __VLS_components.ElTag, typeof __VLS_components.elTag, ]} */ ;
// @ts-ignore
const __VLS_25 = __VLS_asFunctionalComponent(__VLS_24, new __VLS_24({
type: (__VLS_ctx.kb.enabled ? 'success' : 'danger'),
}));
const __VLS_26 = __VLS_25({
type: (__VLS_ctx.kb.enabled ? 'success' : 'danger'),
}, ...__VLS_functionalComponentArgsRest(__VLS_25));
__VLS_27.slots.default;
(__VLS_ctx.kb.enabled ? '启用' : '禁用');
var __VLS_27;
var __VLS_23;
const __VLS_28 = {}.ElDescriptionsItem;
/** @type {[typeof __VLS_components.ElDescriptionsItem, typeof __VLS_components.elDescriptionsItem, typeof __VLS_components.ElDescriptionsItem, typeof __VLS_components.elDescriptionsItem, ]} */ ;
// @ts-ignore
const __VLS_29 = __VLS_asFunctionalComponent(__VLS_28, new __VLS_28({
label: "AI 链接",
}));
const __VLS_30 = __VLS_29({
label: "AI 链接",
}, ...__VLS_functionalComponentArgsRest(__VLS_29));
__VLS_31.slots.default;
__VLS_asFunctionalElement(__VLS_intrinsicElements.div, __VLS_intrinsicElements.div)({
...{ style: {} },
});
const __VLS_32 = {}.ElInput;
/** @type {[typeof __VLS_components.ElInput, typeof __VLS_components.elInput, ]} */ ;
// @ts-ignore
const __VLS_33 = __VLS_asFunctionalComponent(__VLS_32, new __VLS_32({
modelValue: (__VLS_ctx.aiUrl),
readonly: true,
size: "small",
...{ style: {} },
}));
const __VLS_34 = __VLS_33({
modelValue: (__VLS_ctx.aiUrl),
readonly: true,
size: "small",
...{ style: {} },
}, ...__VLS_functionalComponentArgsRest(__VLS_33));
const __VLS_36 = {}.ElButton;
/** @type {[typeof __VLS_components.ElButton, typeof __VLS_components.elButton, typeof __VLS_components.ElButton, typeof __VLS_components.elButton, ]} */ ;
// @ts-ignore
const __VLS_37 = __VLS_asFunctionalComponent(__VLS_36, new __VLS_36({
...{ 'onClick': {} },
size: "small",
}));
const __VLS_38 = __VLS_37({
...{ 'onClick': {} },
size: "small",
}, ...__VLS_functionalComponentArgsRest(__VLS_37));
let __VLS_40;
let __VLS_41;
let __VLS_42;
const __VLS_43 = {
onClick: (__VLS_ctx.handleRegenerate)
};
__VLS_39.slots.default;
var __VLS_39;
var __VLS_31;
const __VLS_44 = {}.ElDescriptionsItem;
/** @type {[typeof __VLS_components.ElDescriptionsItem, typeof __VLS_components.elDescriptionsItem, typeof __VLS_components.ElDescriptionsItem, typeof __VLS_components.elDescriptionsItem, ]} */ ;
// @ts-ignore
const __VLS_45 = __VLS_asFunctionalComponent(__VLS_44, new __VLS_44({
label: "文档数",
}));
const __VLS_46 = __VLS_45({
label: "文档数",
}, ...__VLS_functionalComponentArgsRest(__VLS_45));
__VLS_47.slots.default;
(__VLS_ctx.docs.length);
var __VLS_47;
var __VLS_15;
var __VLS_11;
const __VLS_48 = {}.ElCard;
/** @type {[typeof __VLS_components.ElCard, typeof __VLS_components.elCard, typeof __VLS_components.ElCard, typeof __VLS_components.elCard, ]} */ ;
// @ts-ignore
const __VLS_49 = __VLS_asFunctionalComponent(__VLS_48, new __VLS_48({}));
const __VLS_50 = __VLS_49({}, ...__VLS_functionalComponentArgsRest(__VLS_49));
__VLS_51.slots.default;
{
const { header: __VLS_thisSlot } = __VLS_51.slots;
__VLS_asFunctionalElement(__VLS_intrinsicElements.div, __VLS_intrinsicElements.div)({
...{ style: {} },
});
__VLS_asFunctionalElement(__VLS_intrinsicElements.span, __VLS_intrinsicElements.span)({});
const __VLS_52 = {}.ElUpload;
/** @type {[typeof __VLS_components.ElUpload, typeof __VLS_components.elUpload, typeof __VLS_components.ElUpload, typeof __VLS_components.elUpload, ]} */ ;
// @ts-ignore
const __VLS_53 = __VLS_asFunctionalComponent(__VLS_52, new __VLS_52({
showFileList: (false),
httpRequest: (__VLS_ctx.handleUpload),
accept: ".docx,.pdf",
}));
const __VLS_54 = __VLS_53({
showFileList: (false),
httpRequest: (__VLS_ctx.handleUpload),
accept: ".docx,.pdf",
}, ...__VLS_functionalComponentArgsRest(__VLS_53));
__VLS_55.slots.default;
const __VLS_56 = {}.ElButton;
/** @type {[typeof __VLS_components.ElButton, typeof __VLS_components.elButton, typeof __VLS_components.ElButton, typeof __VLS_components.elButton, ]} */ ;
// @ts-ignore
const __VLS_57 = __VLS_asFunctionalComponent(__VLS_56, new __VLS_56({
type: "primary",
loading: (__VLS_ctx.uploading),
}));
const __VLS_58 = __VLS_57({
type: "primary",
loading: (__VLS_ctx.uploading),
}, ...__VLS_functionalComponentArgsRest(__VLS_57));
__VLS_59.slots.default;
var __VLS_59;
var __VLS_55;
}
const __VLS_60 = {}.ElTable;
/** @type {[typeof __VLS_components.ElTable, typeof __VLS_components.elTable, typeof __VLS_components.ElTable, typeof __VLS_components.elTable, ]} */ ;
// @ts-ignore
const __VLS_61 = __VLS_asFunctionalComponent(__VLS_60, new __VLS_60({
data: (__VLS_ctx.docs),
...{ style: {} },
}));
const __VLS_62 = __VLS_61({
data: (__VLS_ctx.docs),
...{ style: {} },
}, ...__VLS_functionalComponentArgsRest(__VLS_61));
__VLS_asFunctionalDirective(__VLS_directives.vLoading)(null, { ...__VLS_directiveBindingRestFields, value: (__VLS_ctx.loading) }, null, null);
__VLS_63.slots.default;
const __VLS_64 = {}.ElTableColumn;
/** @type {[typeof __VLS_components.ElTableColumn, typeof __VLS_components.elTableColumn, ]} */ ;
// @ts-ignore
const __VLS_65 = __VLS_asFunctionalComponent(__VLS_64, new __VLS_64({
prop: "original_filename",
label: "文件名",
minWidth: "200",
showOverflowTooltip: true,
}));
const __VLS_66 = __VLS_65({
prop: "original_filename",
label: "文件名",
minWidth: "200",
showOverflowTooltip: true,
}, ...__VLS_functionalComponentArgsRest(__VLS_65));
const __VLS_68 = {}.ElTableColumn;
/** @type {[typeof __VLS_components.ElTableColumn, typeof __VLS_components.elTableColumn, typeof __VLS_components.ElTableColumn, typeof __VLS_components.elTableColumn, ]} */ ;
// @ts-ignore
const __VLS_69 = __VLS_asFunctionalComponent(__VLS_68, new __VLS_68({
label: "状态",
width: "120",
align: "center",
}));
const __VLS_70 = __VLS_69({
label: "状态",
width: "120",
align: "center",
}, ...__VLS_functionalComponentArgsRest(__VLS_69));
__VLS_71.slots.default;
{
const { default: __VLS_thisSlot } = __VLS_71.slots;
const [{ row }] = __VLS_getSlotParams(__VLS_thisSlot);
const __VLS_72 = {}.ElTag;
/** @type {[typeof __VLS_components.ElTag, typeof __VLS_components.elTag, typeof __VLS_components.ElTag, typeof __VLS_components.elTag, ]} */ ;
// @ts-ignore
const __VLS_73 = __VLS_asFunctionalComponent(__VLS_72, new __VLS_72({
type: (__VLS_ctx.statusType(row.status)),
size: "small",
}));
const __VLS_74 = __VLS_73({
type: (__VLS_ctx.statusType(row.status)),
size: "small",
}, ...__VLS_functionalComponentArgsRest(__VLS_73));
__VLS_75.slots.default;
(row.status);
var __VLS_75;
}
var __VLS_71;
const __VLS_76 = {}.ElTableColumn;
/** @type {[typeof __VLS_components.ElTableColumn, typeof __VLS_components.elTableColumn, typeof __VLS_components.ElTableColumn, typeof __VLS_components.elTableColumn, ]} */ ;
// @ts-ignore
const __VLS_77 = __VLS_asFunctionalComponent(__VLS_76, new __VLS_76({
label: "大小",
width: "100",
align: "center",
}));
const __VLS_78 = __VLS_77({
label: "大小",
width: "100",
align: "center",
}, ...__VLS_functionalComponentArgsRest(__VLS_77));
__VLS_79.slots.default;
{
const { default: __VLS_thisSlot } = __VLS_79.slots;
const [{ row }] = __VLS_getSlotParams(__VLS_thisSlot);
(__VLS_ctx.formatSize(row.file_size));
}
var __VLS_79;
const __VLS_80 = {}.ElTableColumn;
/** @type {[typeof __VLS_components.ElTableColumn, typeof __VLS_components.elTableColumn, ]} */ ;
// @ts-ignore
const __VLS_81 = __VLS_asFunctionalComponent(__VLS_80, new __VLS_80({
prop: "title",
label: "标题",
minWidth: "150",
showOverflowTooltip: true,
}));
const __VLS_82 = __VLS_81({
prop: "title",
label: "标题",
minWidth: "150",
showOverflowTooltip: true,
}, ...__VLS_functionalComponentArgsRest(__VLS_81));
const __VLS_84 = {}.ElTableColumn;
/** @type {[typeof __VLS_components.ElTableColumn, typeof __VLS_components.elTableColumn, ]} */ ;
// @ts-ignore
const __VLS_85 = __VLS_asFunctionalComponent(__VLS_84, new __VLS_84({
prop: "keywords",
label: "关键词",
minWidth: "150",
showOverflowTooltip: true,
}));
const __VLS_86 = __VLS_85({
prop: "keywords",
label: "关键词",
minWidth: "150",
showOverflowTooltip: true,
}, ...__VLS_functionalComponentArgsRest(__VLS_85));
const __VLS_88 = {}.ElTableColumn;
/** @type {[typeof __VLS_components.ElTableColumn, typeof __VLS_components.elTableColumn, typeof __VLS_components.ElTableColumn, typeof __VLS_components.elTableColumn, ]} */ ;
// @ts-ignore
const __VLS_89 = __VLS_asFunctionalComponent(__VLS_88, new __VLS_88({
label: "操作",
width: "200",
align: "center",
}));
const __VLS_90 = __VLS_89({
label: "操作",
width: "200",
align: "center",
}, ...__VLS_functionalComponentArgsRest(__VLS_89));
__VLS_91.slots.default;
{
const { default: __VLS_thisSlot } = __VLS_91.slots;
const [{ row }] = __VLS_getSlotParams(__VLS_thisSlot);
const __VLS_92 = {}.ElButton;
/** @type {[typeof __VLS_components.ElButton, typeof __VLS_components.elButton, typeof __VLS_components.ElButton, typeof __VLS_components.elButton, ]} */ ;
// @ts-ignore
const __VLS_93 = __VLS_asFunctionalComponent(__VLS_92, new __VLS_92({
...{ 'onClick': {} },
size: "small",
}));
const __VLS_94 = __VLS_93({
...{ 'onClick': {} },
size: "small",
}, ...__VLS_functionalComponentArgsRest(__VLS_93));
let __VLS_96;
let __VLS_97;
let __VLS_98;
const __VLS_99 = {
onClick: (...[$event]) => {
if (!(__VLS_ctx.kb))
return;
__VLS_ctx.handleReprocess(row);
}
};
__VLS_95.slots.default;
var __VLS_95;
const __VLS_100 = {}.ElButton;
/** @type {[typeof __VLS_components.ElButton, typeof __VLS_components.elButton, typeof __VLS_components.ElButton, typeof __VLS_components.elButton, ]} */ ;
// @ts-ignore
const __VLS_101 = __VLS_asFunctionalComponent(__VLS_100, new __VLS_100({
...{ 'onClick': {} },
size: "small",
type: "danger",
}));
const __VLS_102 = __VLS_101({
...{ 'onClick': {} },
size: "small",
type: "danger",
}, ...__VLS_functionalComponentArgsRest(__VLS_101));
let __VLS_104;
let __VLS_105;
let __VLS_106;
const __VLS_107 = {
onClick: (...[$event]) => {
if (!(__VLS_ctx.kb))
return;
__VLS_ctx.handleDeleteDoc(row);
}
};
__VLS_103.slots.default;
var __VLS_103;
}
var __VLS_91;
var __VLS_63;
var __VLS_51;
}
var __VLS_dollars;
const __VLS_self = (await import('vue')).defineComponent({
setup() {
return {};
return {
kb: kb,
docs: docs,
loading: loading,
uploading: uploading,
aiUrl: aiUrl,
handleUpload: handleUpload,
handleDeleteDoc: handleDeleteDoc,
handleReprocess: handleReprocess,
handleCopyLink: handleCopyLink,
handleRegenerate: handleRegenerate,
formatSize: formatSize,
statusType: statusType,
};
},
});
export default (await import('vue')).defineComponent({