feat:【antd】【ai】知识库的 knowledge document 优化(编辑)

This commit is contained in:
YunaiV
2025-11-14 09:43:47 +08:00
parent 132ce52e36
commit 33c066f0f0
4 changed files with 28 additions and 24 deletions

View File

@@ -16,14 +16,13 @@ import { Card } from 'ant-design-vue';
import { getKnowledgeDocument } from '#/api/ai/knowledge/document'; import { getKnowledgeDocument } from '#/api/ai/knowledge/document';
import ProcessStep from './ProcessStep.vue'; import ProcessStep from './modules/process-step.vue';
import SplitStep from './SplitStep.vue'; import SplitStep from './modules/split-step.vue';
import UploadStep from './UploadStep.vue'; import UploadStep from './modules/upload-step.vue';
const route = useRoute(); const route = useRoute();
const router = useRouter(); const router = useRouter();
// 组件引用
const uploadDocumentRef = ref(); const uploadDocumentRef = ref();
const documentSegmentRef = ref(); const documentSegmentRef = ref();
const processCompleteRef = ref(); const processCompleteRef = ref();
@@ -59,9 +58,9 @@ const tabs = useTabs();
function handleBack() { function handleBack() {
// 关闭当前页签 // 关闭当前页签
tabs.closeCurrentTab(); tabs.closeCurrentTab();
// 跳转到列表页,使用路径, 目前后端的路由 name 'name'+ menuId // 跳转到列表页
router.push({ router.push({
path: `/ai/knowledge/document`, name: 'AiKnowledgeDocument',
query: { query: {
knowledgeId: route.query.knowledgeId, knowledgeId: route.query.knowledgeId,
}, },
@@ -92,6 +91,7 @@ async function initData() {
goToNextStep(); goToNextStep();
} }
} }
/** 切换到下一步 */ /** 切换到下一步 */
function goToNextStep() { function goToNextStep() {
if (currentStep.value < steps.length - 1) { if (currentStep.value < steps.length - 1) {
@@ -106,11 +106,6 @@ function goToPrevStep() {
} }
} }
/** 初始化 */
onMounted(async () => {
await initData();
});
/** 添加组件卸载前的清理代码 */ /** 添加组件卸载前的清理代码 */
onBeforeUnmount(() => { onBeforeUnmount(() => {
// 清理所有的引用 // 清理所有的引用
@@ -118,12 +113,18 @@ onBeforeUnmount(() => {
documentSegmentRef.value = null; documentSegmentRef.value = null;
processCompleteRef.value = null; processCompleteRef.value = null;
}); });
/** 暴露方法给子组件使用 */ /** 暴露方法给子组件使用 */
defineExpose({ defineExpose({
goToNextStep, goToNextStep,
goToPrevStep, goToPrevStep,
handleBack, handleBack,
}); });
/** 初始化 */
onMounted(async () => {
await initData();
});
</script> </script>
<template> <template>
@@ -168,13 +169,14 @@ defineExpose({
> >
{{ index + 1 }} {{ index + 1 }}
</div> </div>
<span class="whitespace-nowrap text-base font-bold">{{ <span class="whitespace-nowrap text-base font-bold">
step.title {{ step.title }}
}}</span> </span>
</div> </div>
</div> </div>
</div> </div>
</div> </div>
<!-- 主体内容 --> <!-- 主体内容 -->
<Card :body-style="{ padding: '10px' }" class="mb-4"> <Card :body-style="{ padding: '10px' }" class="mb-4">
<div class="mt-12"> <div class="mt-12">

View File

@@ -67,6 +67,7 @@ async function splitContentFile(file: any) {
splitLoading.value = false; splitLoading.value = false;
} }
} }
/** 处理预览分段 */ /** 处理预览分段 */
async function handleAutoSegment() { async function handleAutoSegment() {
// //
@@ -228,7 +229,7 @@ onMounted(async () => {
> >
{{ file.name }} {{ file.name }}
<span v-if="file.segments" class="ml-1 text-sm text-gray-500"> <span v-if="file.segments" class="ml-1 text-sm text-gray-500">
({{ file.segments.length }}个分片) ({{ file.segments.length }} 个分片)
</span> </span>
</Menu.Item> </Menu.Item>
</Menu> </Menu>

View File

@@ -30,7 +30,6 @@ const { uploadUrl, httpRequest } = useUpload(); // 使用上传组件的钩子
const fileList = ref<UploadProps['fileList']>([]); // const fileList = ref<UploadProps['fileList']>([]); //
const uploadingCount = ref(0); // const uploadingCount = ref(0); //
//
const supportedFileTypes = [ const supportedFileTypes = [
'TXT', 'TXT',
'MARKDOWN', 'MARKDOWN',
@@ -50,16 +49,14 @@ const supportedFileTypes = [
'PPT', 'PPT',
'MD', 'MD',
'HTM', 'HTM',
]; ]; //
const allowedExtensions = new Set( const allowedExtensions = new Set(
supportedFileTypes.map((ext) => ext.toLowerCase()), supportedFileTypes.map((ext) => ext.toLowerCase()),
); // ); //
const maxFileSize = 15; // (MB) const maxFileSize = 15; // (MB)
// accept
const acceptedFileTypes = computed(() => const acceptedFileTypes = computed(() =>
generateAcceptedFileTypes(supportedFileTypes), generateAcceptedFileTypes(supportedFileTypes),
); ); // accept
/** 表单数据 */ /** 表单数据 */
const modelData = computed({ const modelData = computed({
@@ -68,6 +65,7 @@ const modelData = computed({
}, },
set: (val) => emit('update:modelValue', val), set: (val) => emit('update:modelValue', val),
}); });
/** 确保 list 属性存在 */ /** 确保 list 属性存在 */
function ensureListExists() { function ensureListExists() {
if (!props.modelValue.list) { if (!props.modelValue.list) {
@@ -77,6 +75,7 @@ function ensureListExists() {
}); });
} }
} }
/** 是否所有文件都已上传完成 */ /** 是否所有文件都已上传完成 */
const isAllUploaded = computed(() => { const isAllUploaded = computed(() => {
return ( return (
@@ -112,7 +111,8 @@ function beforeUpload(file: any) {
uploadingCount.value++; uploadingCount.value++;
return true; return true;
} }
async function customRequest(info: UploadRequestOption<any>) {
async function customRequest(info: UploadRequestOption) {
const file = info.file as File; const file = info.file as File;
const name = file?.name; const name = file?.name;
try { try {
@@ -142,6 +142,7 @@ async function customRequest(info: UploadRequestOption<any>) {
uploadingCount.value = Math.max(0, uploadingCount.value - 1); uploadingCount.value = Math.max(0, uploadingCount.value - 1);
} }
} }
/** /**
* 从列表中移除文件 * 从列表中移除文件
* *
@@ -231,9 +232,9 @@ onMounted(() => {
> >
<div class="flex items-center"> <div class="flex items-center">
<IconifyIcon icon="lucide:file-text" class="mr-2 text-blue-500" /> <IconifyIcon icon="lucide:file-text" class="mr-2 text-blue-500" />
<span class="break-all text-sm text-gray-600">{{ <span class="break-all text-sm text-gray-600">
file.name {{ file.name }}
}}</span> </span>
</div> </div>
<Button <Button
danger danger