feat: ai
This commit is contained in:
@@ -19,9 +19,9 @@ const parent = inject('parent') as any;
|
||||
const pollingTimer = ref<null | number>(null); // 轮询定时器 ID,用于跟踪和清除轮询进程
|
||||
|
||||
/** 判断文件处理是否完成 */
|
||||
const isProcessComplete = (file: any) => {
|
||||
function isProcessComplete(file: any) {
|
||||
return file.progress === 100;
|
||||
};
|
||||
}
|
||||
|
||||
/** 判断所有文件是否都处理完成 */
|
||||
const allProcessComplete = computed(() => {
|
||||
@@ -29,14 +29,14 @@ const allProcessComplete = computed(() => {
|
||||
});
|
||||
|
||||
/** 完成按钮点击事件处理 */
|
||||
const handleComplete = () => {
|
||||
function handleComplete() {
|
||||
if (parent?.exposed?.handleBack) {
|
||||
parent.exposed.handleBack();
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
/** 获取文件处理进度 */
|
||||
const getProcessList = async () => {
|
||||
async function getProcessList() {
|
||||
try {
|
||||
// 1. 调用 API 获取处理进度
|
||||
const documentIds = props.modelValue.list
|
||||
@@ -82,7 +82,7 @@ const getProcessList = async () => {
|
||||
console.error('获取处理进度失败:', error);
|
||||
pollingTimer.value = window.setTimeout(getProcessList, 5000);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
/** 组件挂载时开始轮询 */
|
||||
onMounted(() => {
|
||||
|
||||
@@ -42,12 +42,13 @@ const currentFile = ref<any>(null); // 当前选中的文件
|
||||
const submitLoading = ref(false); // 提交按钮加载状态
|
||||
|
||||
/** 选择文件 */
|
||||
const selectFile = async (index: number) => {
|
||||
async function selectFile(index: number) {
|
||||
currentFile.value = modelData.value.list[index];
|
||||
await splitContentFile(currentFile.value);
|
||||
};
|
||||
}
|
||||
|
||||
/** 获取文件分段内容 */
|
||||
const splitContentFile = async (file: any) => {
|
||||
async function splitContentFile(file: any) {
|
||||
if (!file || !file.url) {
|
||||
message.warning('文件 URL 不存在');
|
||||
return;
|
||||
@@ -65,9 +66,9 @@ const splitContentFile = async (file: any) => {
|
||||
} finally {
|
||||
splitLoading.value = false;
|
||||
}
|
||||
};
|
||||
}
|
||||
/** 处理预览分段 */
|
||||
const handleAutoSegment = async () => {
|
||||
async function handleAutoSegment() {
|
||||
// 如果没有选中文件,默认选中第一个
|
||||
if (
|
||||
!currentFile.value &&
|
||||
@@ -84,18 +85,18 @@ const handleAutoSegment = async () => {
|
||||
|
||||
// 获取分段内容
|
||||
await splitContentFile(currentFile.value);
|
||||
};
|
||||
}
|
||||
|
||||
/** 上一步按钮处理 */
|
||||
const handlePrevStep = () => {
|
||||
function handlePrevStep() {
|
||||
const parentEl = parent || getCurrentInstance()?.parent;
|
||||
if (parentEl && typeof parentEl.exposed?.goToPrevStep === 'function') {
|
||||
parentEl.exposed.goToPrevStep();
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
/** 保存操作 */
|
||||
const handleSave = async () => {
|
||||
async function handleSave() {
|
||||
// 保存前验证
|
||||
if (
|
||||
!currentFile?.value?.segments ||
|
||||
@@ -140,7 +141,7 @@ const handleSave = async () => {
|
||||
// 关闭按钮加载状态
|
||||
submitLoading.value = false;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
/** 初始化 */
|
||||
onMounted(async () => {
|
||||
|
||||
@@ -10,11 +10,11 @@ import { computed, getCurrentInstance, inject, onMounted, ref } from 'vue';
|
||||
|
||||
import { IconifyIcon } from '@vben/icons';
|
||||
import { $t } from '@vben/locales';
|
||||
import { generateAcceptedFileTypes } from '@vben/utils';
|
||||
|
||||
import { Button, Form, message, UploadDragger } from 'ant-design-vue';
|
||||
|
||||
import { useUpload } from '#/components/upload/use-upload';
|
||||
import { generateAcceptedFileTypes } from '#/utils/upload';
|
||||
|
||||
const props = defineProps({
|
||||
modelValue: {
|
||||
@@ -70,14 +70,14 @@ const modelData = computed({
|
||||
set: (val) => emit('update:modelValue', val),
|
||||
});
|
||||
/** 确保 list 属性存在 */
|
||||
const ensureListExists = () => {
|
||||
function ensureListExists() {
|
||||
if (!props.modelValue.list) {
|
||||
emit('update:modelValue', {
|
||||
...props.modelValue,
|
||||
list: [],
|
||||
});
|
||||
}
|
||||
};
|
||||
}
|
||||
/** 是否所有文件都已上传完成 */
|
||||
const isAllUploaded = computed(() => {
|
||||
return (
|
||||
@@ -93,7 +93,7 @@ const isAllUploaded = computed(() => {
|
||||
* @param file 待上传的文件
|
||||
* @returns 是否允许上传
|
||||
*/
|
||||
const beforeUpload = (file: any) => {
|
||||
function beforeUpload(file: any) {
|
||||
// 1.1 检查文件扩展名
|
||||
const fileName = file.name.toLowerCase();
|
||||
const fileExtension = fileName.slice(
|
||||
@@ -112,7 +112,7 @@ const beforeUpload = (file: any) => {
|
||||
// 2. 增加上传中的文件计数
|
||||
uploadingCount.value++;
|
||||
return true;
|
||||
};
|
||||
}
|
||||
async function customRequest(info: UploadRequestOption<any>) {
|
||||
const file = info.file as File;
|
||||
const name = file?.name;
|
||||
@@ -148,7 +148,7 @@ async function customRequest(info: UploadRequestOption<any>) {
|
||||
*
|
||||
* @param index 要移除的文件索引
|
||||
*/
|
||||
const removeFile = (index: number) => {
|
||||
function removeFile(index: number) {
|
||||
// 从列表中移除文件
|
||||
const newList = [...props.modelValue.list];
|
||||
newList.splice(index, 1);
|
||||
@@ -157,10 +157,10 @@ const removeFile = (index: number) => {
|
||||
...props.modelValue,
|
||||
list: newList,
|
||||
});
|
||||
};
|
||||
}
|
||||
|
||||
/** 下一步按钮处理 */
|
||||
const handleNextStep = () => {
|
||||
function handleNextStep() {
|
||||
// 1.1 检查是否有文件上传
|
||||
if (!modelData.value.list || modelData.value.list.length === 0) {
|
||||
message.warning('请上传至少一个文件');
|
||||
@@ -177,7 +177,7 @@ const handleNextStep = () => {
|
||||
if (parentEl && typeof parentEl.exposed?.goToNextStep === 'function') {
|
||||
parentEl.exposed.goToNextStep();
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
/** 初始化 */
|
||||
onMounted(() => {
|
||||
@@ -210,9 +210,9 @@ onMounted(() => {
|
||||
/>
|
||||
<div class="ant-upload-text text-[16px] text-[#606266]">
|
||||
拖拽文件至此,或者
|
||||
<em class="cursor-pointer not-italic text-[#409eff]"
|
||||
>选择文件</em
|
||||
>
|
||||
<em class="cursor-pointer not-italic text-[#409eff]">
|
||||
选择文件
|
||||
</em>
|
||||
</div>
|
||||
<div class="ant-upload-tip mt-10px text-[12px] text-[#909399]">
|
||||
已支持 {{ supportedFileTypes.join('、') }},每个文件不超过
|
||||
|
||||
@@ -56,7 +56,7 @@ provide('parent', getCurrentInstance()); // 提供 parent 给子组件使用
|
||||
const tabs = useTabs();
|
||||
|
||||
/** 返回列表页 */
|
||||
const handleBack = () => {
|
||||
function handleBack() {
|
||||
// 关闭当前页签
|
||||
tabs.closeCurrentTab();
|
||||
// 跳转到列表页,使用路径, 目前后端的路由 name: 'name'+ menuId
|
||||
@@ -66,10 +66,10 @@ const handleBack = () => {
|
||||
knowledgeId: route.query.knowledgeId,
|
||||
},
|
||||
});
|
||||
};
|
||||
}
|
||||
|
||||
/** 初始化数据 */
|
||||
const initData = async () => {
|
||||
async function initData() {
|
||||
if (route.query.knowledgeId) {
|
||||
formData.value.knowledgeId = route.query.knowledgeId as any;
|
||||
}
|
||||
@@ -91,20 +91,20 @@ const initData = async () => {
|
||||
// 进入下一步
|
||||
goToNextStep();
|
||||
}
|
||||
};
|
||||
}
|
||||
/** 切换到下一步 */
|
||||
const goToNextStep = () => {
|
||||
function goToNextStep() {
|
||||
if (currentStep.value < steps.length - 1) {
|
||||
currentStep.value++;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
/** 切换到上一步 */
|
||||
const goToPrevStep = () => {
|
||||
function goToPrevStep() {
|
||||
if (currentStep.value > 0) {
|
||||
currentStep.value--;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
/** 初始化 */
|
||||
onMounted(async () => {
|
||||
|
||||
@@ -17,7 +17,7 @@ import {
|
||||
updateKnowledgeDocumentStatus,
|
||||
} from '#/api/ai/knowledge/document';
|
||||
import { $t } from '#/locales';
|
||||
import { CommonStatusEnum } from '#/utils/constants';
|
||||
import { CommonStatusEnum } from '#/utils';
|
||||
|
||||
import { useGridColumns, useGridFormSchema } from './data';
|
||||
|
||||
|
||||
Reference in New Issue
Block a user