| | |
| | | <template> |
| | | <div class="h100 overflow-y-auto p-[16px]"> |
| | | <div class="mb-[10px] flex items-center"> |
| | | <el-button style="margin-left: 8px; width: 40px" text @click="handleExitFlow"> |
| | | <el-button style="margin-left: 8px; width: 40px" link @click="handleExitFlow"> |
| | | <el-icon style="font-size: 24px !important"> |
| | | <ArrowLeft /> |
| | | </el-icon> |
| | |
| | | </template> |
| | | </el-upload> |
| | | </el-form-item> |
| | | <el-form-item label="文档识别:"> |
| | | <div |
| | | class="bg-[#f6f5ff] border-[1px] border-solid border-[#0062be] py-[12px] w-[215px] px-[16px] rounded-lg cursor-pointer" |
| | | > |
| | | <el-radio-group v-model="state.categoryForm.DocumentRecognition"> |
| | | <el-radio value="1" size="large"> |
| | | <span class="font-[700] text[14px]">文档智能解析</span> |
| | | </el-radio> |
| | | </el-radio-group> |
| | | <el-tooltip :content="state.demoDesc" placement="top" effect="light" popper-class="set_tooltip_demo"> |
| | | <div class="text-[#878aab] text-[12px] mx-0 mt-[2px] mb-0 set-desc"> |
| | | {{ state.demoDesc }} |
| | | </div> |
| | | </el-tooltip> |
| | | </div> |
| | | </el-form-item> |
| | | </el-form> |
| | | |
| | | <div class="set-form-footer"> |
| | |
| | | <script setup lang="ts"> |
| | | import type { UploadUserFile } from 'element-plus'; |
| | | import { ElMessage } from 'element-plus'; |
| | | import { reactive, ref } from 'vue'; |
| | | import moment from 'moment'; |
| | | import { onMounted, reactive, ref } from 'vue'; |
| | | import { useRoute, useRouter } from 'vue-router'; |
| | | import { add_knowledge_file } from '/@/api/knowledge/group'; |
| | | import mittBus from '/@/utils/mitt'; |
| | | import { convertFileSize } from '/@/utils/util'; |
| | | const uploadFileChange = (rule, value, callback) => { |
| | | if (fileList.value.length === 0) { |
| | | return callback('请选择需要上传的文件'); |
| | |
| | | const state = reactive({ |
| | | detailTitle: '导入数据', |
| | | categoryForm: { |
| | | ImportCategory: '默认类目', |
| | | ImportCategory: '', |
| | | CategoryType: '本地类目', |
| | | DocumentRecognition: '1', |
| | | }, |
| | | // allowType: '.pdf,.doc,.docx,.txt,.md,.pptx,.ppt', |
| | | allowType: 'md', |
| | | allowType: 'md,.doc,.docx', |
| | | limit: 5, |
| | | size: 5, |
| | | demoDesc: '使用阿里云文档智能解析服务据解析文档,抽取文档内容、层级结构等信息。', |
| | | categoryFormRules: { |
| | | importType: [{ required: true, validator: uploadFileChange, trigger: 'change' }], |
| | | }, |
| | | fileInfo: {} as any, |
| | | }); |
| | | const fileList = ref<UploadUserFile[]>([]); |
| | | const categoryFormRef = ref(null); |
| | | const uploadRef = ref(null); |
| | | const router = useRouter(); |
| | | const route = useRoute(); |
| | | //返回 |
| | | const handleExitFlow = () => { |
| | | //是否显示返回 |
| | | router.back(); |
| | | categoryFormRef.value.resetFields(); |
| | | uploadRef.value.clearFiles(); |
| | | fileList.value = []; |
| | | }; |
| | | const flag = ref(true); |
| | | const uploadFile = (file: UploadUserFile) => { |
| | | state.fileInfo = file?.file; |
| | | fileList.value.push(file); |
| | | categoryFormRef.value.validateField(['importType']); //移除上传文件错误提示!这是重点!! |
| | | }; |
| | |
| | | } |
| | | }); |
| | | }; |
| | | |
| | | const groupTypeMap = { |
| | | md: 'markdown', |
| | | doc: 'doc', |
| | | docx: 'docx', |
| | | }; |
| | | |
| | | const getFileSuffix = (name: string): string => { |
| | | if (!name) return ''; |
| | | const suffix = name.split('.').pop() as string; |
| | | return suffix; |
| | | }; |
| | | //确认 |
| | | const onSubmit = async () => { |
| | | let group_id = route.query.group_id; |
| | | const valid = await categoryFormRef.value.validate().catch(() => {}); |
| | | if (!valid) return; |
| | | const group_id = route.query.group_id; |
| | | if (group_id == null || group_id == '' || group_id == undefined) return; |
| | | categoryFormRef.value.validate(async (valid: boolean) => { |
| | | if (valid) { |
| | | const data = new FormData(); |
| | | fileList.value.forEach((item: any) => { |
| | | data.append('file', item.file); |
| | | }); |
| | | data.append('group_id', group_id); |
| | | const res = await add_knowledge_file(data); |
| | | if (res.json_ok) { |
| | | ElMessage.success('导入成功'); |
| | | router.push({ |
| | | name: 'GraphIndex', |
| | | }); |
| | | } else { |
| | | ElMessage.error(res.json_msg); |
| | | } |
| | | } |
| | | const group_name = state.fileInfo?.name; |
| | | const suffix = getFileSuffix(state.fileInfo?.name); |
| | | const group_type = groupTypeMap[suffix] ?? ''; |
| | | const group_time = moment(state.fileInfo?.lastModifiedDate).format('YYYY-MM-DD HH:mm:ss'); |
| | | const group_size = convertFileSize(state.fileInfo?.size); |
| | | const data = new FormData(); |
| | | fileList.value.forEach((item: any) => { |
| | | data.append('file', item.file); |
| | | }); |
| | | data.append('group_id', group_id); |
| | | const res = await add_knowledge_file(data); |
| | | if (res.json_ok) { |
| | | ElMessage.success('导入成功'); |
| | | let obj = { |
| | | id: res.file_id, |
| | | name: group_name, |
| | | type: group_type, |
| | | time: group_time, |
| | | size: group_size, |
| | | }; |
| | | |
| | | mittBus.emit('addGraphObj', obj); |
| | | router.push({ |
| | | name: 'GraphIndex', |
| | | }); |
| | | uploadRef.value.clearFiles(); |
| | | } else { |
| | | ElMessage.error(res.json_msg); |
| | | } |
| | | }; |
| | | onMounted(() => { |
| | | const group_title = route.query.title; |
| | | state.categoryForm.ImportCategory = group_title; |
| | | }); |
| | | </script> |
| | | <style scoped lang="scss"> |
| | | .set-form-height { |