feat(pwl):新增AI云文档目录表、AI云文件表
This commit is contained in:
114
src/views/oa/oaCompany/components/Import2.vue
Normal file
114
src/views/oa/oaCompany/components/Import2.vue
Normal file
@@ -0,0 +1,114 @@
|
||||
<!-- 文档导入弹窗 -->
|
||||
<template>
|
||||
<ele-modal
|
||||
:width="520"
|
||||
:footer="null"
|
||||
:title="`批量导入文档`"
|
||||
:visible="visible"
|
||||
@update:visible="updateVisible"
|
||||
>
|
||||
<a-spin :spinning="loading">
|
||||
<a-upload-dragger
|
||||
accept=".pdf,.doc,.docx,.txt,.md,.xls,.xlsx"
|
||||
:show-upload-list="false"
|
||||
:customRequest="doUpload"
|
||||
:multiple="true"
|
||||
style="padding: 24px 0; margin-bottom: 16px"
|
||||
>
|
||||
<p class="ant-upload-drag-icon">
|
||||
<cloud-upload-outlined />
|
||||
</p>
|
||||
<p class="ant-upload-hint">将文件拖到此处,或点击上传</p>
|
||||
<p class="ant-upload-hint" style="font-size: 12px; color: #999;">
|
||||
支持格式:PDF、Word、Excel、TXT、MD 等文档格式
|
||||
</p>
|
||||
</a-upload-dragger>
|
||||
</a-spin>
|
||||
</ele-modal>
|
||||
</template>
|
||||
|
||||
<script lang="ts" setup>
|
||||
import { ref } from 'vue';
|
||||
import { message } from 'ant-design-vue/es';
|
||||
import { CloudUploadOutlined } from '@ant-design/icons-vue';
|
||||
import { debounce } from 'lodash-es';
|
||||
import { uploadFiles } from '@/api/ai/aiCloudFile';
|
||||
|
||||
const emit = defineEmits<{
|
||||
(e: 'done'): void;
|
||||
(e: 'update:visible', visible: boolean): void;
|
||||
}>();
|
||||
|
||||
// 在顶层定义 props - 修改为接收 doc 对象
|
||||
const props = defineProps<{
|
||||
visible: boolean;
|
||||
doc: { // 改为接收完整的 doc 对象
|
||||
id: number;
|
||||
categoryId: string;
|
||||
};
|
||||
}>();
|
||||
|
||||
const loading = ref(false);
|
||||
|
||||
// 新增批量上传方法 - 修改调用参数
|
||||
const handleBatchUpload = debounce(async () => {
|
||||
if (uploadQueue.length === 0) return;
|
||||
|
||||
const files = [...uploadQueue];
|
||||
uploadQueue.length = 0; // 清空队列
|
||||
|
||||
loading.value = true;
|
||||
try {
|
||||
// 修改:传入 doc.id 和 doc.categoryId
|
||||
const msg = await uploadFiles(props.doc.id, props.doc.categoryId, files);
|
||||
message.success(msg || '上传成功');
|
||||
updateVisible(false);
|
||||
emit('done');
|
||||
} catch (e: any) {
|
||||
message.error(e.message || '上传失败');
|
||||
} finally {
|
||||
loading.value = false;
|
||||
}
|
||||
}, 500);
|
||||
|
||||
// 修改后的上传方法
|
||||
const doUpload = ({ file }: { file: File }) => {
|
||||
// 检查文件类型
|
||||
const allowedTypes = [
|
||||
'application/pdf',
|
||||
'application/msword',
|
||||
'application/vnd.openxmlformats-officedocument.wordprocessingml.document',
|
||||
'text/plain',
|
||||
'text/markdown',
|
||||
'application/vnd.ms-excel',
|
||||
'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'
|
||||
];
|
||||
|
||||
const allowedExtensions = ['.pdf', '.doc', '.docx', '.txt', '.md', '.xls', '.xlsx'];
|
||||
const fileExtension = '.' + file.name.split('.').pop()?.toLowerCase();
|
||||
|
||||
if (!allowedTypes.includes(file.type) && !allowedExtensions.includes(fileExtension)) {
|
||||
message.error('只能上传文档文件(PDF、Word、Excel、TXT、MD)');
|
||||
return false;
|
||||
}
|
||||
|
||||
if (file.size / 1024 / 1024 > 100) {
|
||||
message.error('文件大小不能超过 100MB');
|
||||
return false;
|
||||
}
|
||||
|
||||
// 将文件加入队列并触发防抖上传
|
||||
uploadQueue.push(file);
|
||||
handleBatchUpload();
|
||||
|
||||
return false;
|
||||
};
|
||||
|
||||
// 新增文件队列
|
||||
const uploadQueue: File[] = [];
|
||||
|
||||
/* 更新 visible */
|
||||
const updateVisible = (value: boolean) => {
|
||||
emit('update:visible', value);
|
||||
};
|
||||
</script>
|
||||
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user