2023-10-27 09:49:06 +00:00
|
|
|
|
<template>
|
2023-11-02 10:25:09 +00:00
|
|
|
|
<h4 class="title-decoration-1 mb-8">上传文档</h4>
|
2023-11-22 09:04:47 +00:00
|
|
|
|
<el-form
|
|
|
|
|
|
ref="FormRef"
|
|
|
|
|
|
:model="form"
|
|
|
|
|
|
:rules="rules"
|
|
|
|
|
|
label-position="top"
|
|
|
|
|
|
require-asterisk-position="right"
|
|
|
|
|
|
>
|
2024-05-23 10:57:49 +00:00
|
|
|
|
<el-form-item>
|
|
|
|
|
|
<el-radio-group v-model="form.fileType" @change="radioChange">
|
|
|
|
|
|
<el-radio value="txt">文本文件</el-radio>
|
|
|
|
|
|
<el-radio value="QA">QA 问答对</el-radio>
|
|
|
|
|
|
</el-radio-group>
|
|
|
|
|
|
</el-form-item>
|
|
|
|
|
|
<el-form-item prop="fileList" v-if="form.fileType === 'QA'">
|
|
|
|
|
|
<el-upload
|
|
|
|
|
|
:webkitdirectory="false"
|
|
|
|
|
|
class="w-full mb-4"
|
|
|
|
|
|
drag
|
|
|
|
|
|
multiple
|
|
|
|
|
|
v-model:file-list="form.fileList"
|
|
|
|
|
|
action="#"
|
|
|
|
|
|
:auto-upload="false"
|
|
|
|
|
|
:show-file-list="false"
|
|
|
|
|
|
accept=".xlsx, .xls, .csv"
|
|
|
|
|
|
:limit="50"
|
|
|
|
|
|
:on-exceed="onExceed"
|
|
|
|
|
|
:on-change="fileHandleChange"
|
|
|
|
|
|
@click.prevent="handlePreview(false)"
|
|
|
|
|
|
>
|
|
|
|
|
|
<img src="@/assets/upload-icon.svg" alt="" />
|
|
|
|
|
|
<div class="el-upload__text">
|
|
|
|
|
|
<p>
|
|
|
|
|
|
拖拽文件至此上传或
|
|
|
|
|
|
<em class="hover" @click.prevent="handlePreview(false)"> 选择文件 </em>
|
|
|
|
|
|
<em class="hover" @click.prevent="handlePreview(true)"> 选择文件夹 </em>
|
|
|
|
|
|
</p>
|
|
|
|
|
|
<div class="upload__decoration">
|
|
|
|
|
|
<p>当前支持 XLSX / XLS / CSV 格式的文档</p>
|
|
|
|
|
|
<p>每次最多上传50个文件,每个文件不超过 100MB</p>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
</el-upload>
|
|
|
|
|
|
<el-button type="primary" link @click="downloadTemplate('excel')">
|
|
|
|
|
|
下载 Excel 模板
|
|
|
|
|
|
</el-button>
|
|
|
|
|
|
<el-divider direction="vertical" />
|
|
|
|
|
|
<el-button type="primary" link @click="downloadTemplate('csv')"> 下载 CSV 模板 </el-button>
|
|
|
|
|
|
</el-form-item>
|
|
|
|
|
|
<el-form-item prop="fileList" v-else>
|
2023-10-27 09:49:06 +00:00
|
|
|
|
<el-upload
|
2024-04-18 03:09:33 +00:00
|
|
|
|
:webkitdirectory="false"
|
2023-10-27 09:49:06 +00:00
|
|
|
|
class="w-full"
|
|
|
|
|
|
drag
|
|
|
|
|
|
multiple
|
2023-11-02 01:56:14 +00:00
|
|
|
|
v-model:file-list="form.fileList"
|
|
|
|
|
|
action="#"
|
|
|
|
|
|
:auto-upload="false"
|
2023-11-06 11:06:02 +00:00
|
|
|
|
:show-file-list="false"
|
2024-08-28 11:04:50 +00:00
|
|
|
|
accept=".txt, .md, .csv, .log, .docx, .pdf, .html, .PDF"
|
2024-03-04 08:37:30 +00:00
|
|
|
|
:limit="50"
|
2024-03-01 07:58:47 +00:00
|
|
|
|
:on-exceed="onExceed"
|
2024-04-18 03:09:33 +00:00
|
|
|
|
:on-change="fileHandleChange"
|
|
|
|
|
|
@click.prevent="handlePreview(false)"
|
2023-10-27 09:49:06 +00:00
|
|
|
|
>
|
2023-11-06 11:06:02 +00:00
|
|
|
|
<img src="@/assets/upload-icon.svg" alt="" />
|
2023-10-27 09:49:06 +00:00
|
|
|
|
<div class="el-upload__text">
|
|
|
|
|
|
<p>
|
2024-04-18 03:09:33 +00:00
|
|
|
|
拖拽文件至此上传或
|
|
|
|
|
|
<em class="hover" @click.prevent="handlePreview(false)"> 选择文件 </em>
|
|
|
|
|
|
<em class="hover" @click.prevent="handlePreview(true)"> 选择文件夹 </em>
|
2023-10-27 09:49:06 +00:00
|
|
|
|
</p>
|
|
|
|
|
|
<div class="upload__decoration">
|
2024-05-23 06:19:18 +00:00
|
|
|
|
<p>
|
|
|
|
|
|
支持格式:TXT、Markdown、PDF、DOCX、HTML 每次最多上传50个文件,每个文件不超过 100MB
|
|
|
|
|
|
</p>
|
2023-11-06 11:06:02 +00:00
|
|
|
|
<p>若使用【高级分段】建议上传前规范文件的分段标识</p>
|
2023-10-27 09:49:06 +00:00
|
|
|
|
</div>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
</el-upload>
|
|
|
|
|
|
</el-form-item>
|
|
|
|
|
|
</el-form>
|
2023-11-06 11:06:02 +00:00
|
|
|
|
<el-row :gutter="8" v-if="form.fileList?.length">
|
|
|
|
|
|
<template v-for="(item, index) in form.fileList" :key="index">
|
|
|
|
|
|
<el-col :span="12" class="mb-8">
|
|
|
|
|
|
<el-card shadow="never" class="file-List-card">
|
|
|
|
|
|
<div class="flex-between">
|
|
|
|
|
|
<div class="flex">
|
2024-04-10 06:16:56 +00:00
|
|
|
|
<img :src="getImgUrl(item && item?.name)" alt="" width="40" />
|
2023-11-06 11:06:02 +00:00
|
|
|
|
<div class="ml-8">
|
|
|
|
|
|
<p>{{ item && item?.name }}</p>
|
2024-07-01 01:45:59 +00:00
|
|
|
|
<el-text type="info" size="small">{{
|
|
|
|
|
|
filesize(item && item?.size) || '0K'
|
|
|
|
|
|
}}</el-text>
|
2023-11-06 11:06:02 +00:00
|
|
|
|
</div>
|
|
|
|
|
|
</div>
|
2024-04-15 10:46:03 +00:00
|
|
|
|
<el-button text @click="deleteFile(index)">
|
2023-11-06 11:06:02 +00:00
|
|
|
|
<el-icon><Delete /></el-icon>
|
|
|
|
|
|
</el-button>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
</el-card>
|
|
|
|
|
|
</el-col>
|
|
|
|
|
|
</template>
|
|
|
|
|
|
</el-row>
|
2023-10-27 09:49:06 +00:00
|
|
|
|
</template>
|
|
|
|
|
|
<script setup lang="ts">
|
2024-04-18 03:09:33 +00:00
|
|
|
|
import { ref, reactive, onUnmounted, onMounted, computed, watch, nextTick } from 'vue'
|
2024-05-23 10:57:49 +00:00
|
|
|
|
import type { UploadFiles } from 'element-plus'
|
2024-04-10 07:50:57 +00:00
|
|
|
|
import { filesize, getImgUrl, isRightType } from '@/utils/utils'
|
2023-11-06 11:06:02 +00:00
|
|
|
|
import { MsgError } from '@/utils/message'
|
2024-05-23 10:57:49 +00:00
|
|
|
|
import documentApi from '@/api/document'
|
2023-11-10 09:18:00 +00:00
|
|
|
|
import useStore from '@/stores'
|
|
|
|
|
|
const { dataset } = useStore()
|
|
|
|
|
|
const documentsFiles = computed(() => dataset.documentsFiles)
|
2024-05-23 10:57:49 +00:00
|
|
|
|
const documentsType = computed(() => dataset.documentsType)
|
2023-11-10 09:18:00 +00:00
|
|
|
|
const form = ref({
|
2024-05-23 10:57:49 +00:00
|
|
|
|
fileType: 'txt',
|
2023-11-06 11:06:02 +00:00
|
|
|
|
fileList: [] as any
|
2023-10-27 09:49:06 +00:00
|
|
|
|
})
|
|
|
|
|
|
|
2023-11-02 01:56:14 +00:00
|
|
|
|
const rules = reactive({
|
|
|
|
|
|
fileList: [{ required: true, message: '请上传文件', trigger: 'change' }]
|
|
|
|
|
|
})
|
2023-10-27 09:49:06 +00:00
|
|
|
|
const FormRef = ref()
|
|
|
|
|
|
|
2024-01-08 09:53:50 +00:00
|
|
|
|
watch(form.value, (value) => {
|
2024-05-23 10:57:49 +00:00
|
|
|
|
dataset.saveDocumentsType(value.fileType)
|
2024-01-08 09:53:50 +00:00
|
|
|
|
dataset.saveDocumentsFile(value.fileList)
|
|
|
|
|
|
})
|
2024-05-23 10:57:49 +00:00
|
|
|
|
|
|
|
|
|
|
function downloadTemplate(type: string) {
|
|
|
|
|
|
documentApi.exportQATemplate(`${type}模版.${type == 'csv' ? type : 'xlsx'}`, type)
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function radioChange() {
|
|
|
|
|
|
form.value.fileList = []
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2024-04-15 10:46:03 +00:00
|
|
|
|
function deleteFile(index: number) {
|
2023-11-10 09:18:00 +00:00
|
|
|
|
form.value.fileList.splice(index, 1)
|
2023-11-06 11:06:02 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
2024-04-09 07:56:01 +00:00
|
|
|
|
// 上传on-change事件
|
2024-04-18 03:09:33 +00:00
|
|
|
|
const fileHandleChange = (file: any, fileList: UploadFiles) => {
|
2024-05-23 10:57:49 +00:00
|
|
|
|
//1、判断文件大小是否合法,文件限制不能大于100M
|
2024-04-09 07:56:01 +00:00
|
|
|
|
const isLimit = file?.size / 1024 / 1024 < 100
|
|
|
|
|
|
if (!isLimit) {
|
|
|
|
|
|
MsgError('文件大小超过 100MB')
|
|
|
|
|
|
fileList.splice(-1, 1) //移除当前超出大小的文件
|
|
|
|
|
|
return false
|
|
|
|
|
|
}
|
2024-05-23 10:57:49 +00:00
|
|
|
|
if (!isRightType(file?.name, form.value.fileType)) {
|
2024-04-10 07:50:57 +00:00
|
|
|
|
MsgError('文件格式不支持')
|
|
|
|
|
|
fileList.splice(-1, 1)
|
|
|
|
|
|
return false
|
|
|
|
|
|
}
|
2024-04-09 07:56:01 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
2024-03-01 07:58:47 +00:00
|
|
|
|
const onExceed = () => {
|
|
|
|
|
|
MsgError('每次最多上传50个文件')
|
|
|
|
|
|
}
|
2024-04-18 03:09:33 +00:00
|
|
|
|
|
|
|
|
|
|
const handlePreview = (bool: boolean) => {
|
|
|
|
|
|
let inputDom: any = null
|
|
|
|
|
|
nextTick(() => {
|
|
|
|
|
|
if (document.querySelector('.el-upload__input') != null) {
|
|
|
|
|
|
inputDom = document.querySelector('.el-upload__input')
|
|
|
|
|
|
inputDom.webkitdirectory = bool
|
|
|
|
|
|
}
|
|
|
|
|
|
})
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2023-11-22 03:05:06 +00:00
|
|
|
|
/*
|
|
|
|
|
|
表单校验
|
|
|
|
|
|
*/
|
2023-10-27 09:49:06 +00:00
|
|
|
|
function validate() {
|
|
|
|
|
|
if (!FormRef.value) return
|
2023-11-02 01:56:14 +00:00
|
|
|
|
return FormRef.value.validate((valid: any) => {
|
2023-10-27 09:49:06 +00:00
|
|
|
|
return valid
|
|
|
|
|
|
})
|
|
|
|
|
|
}
|
2024-03-01 07:58:47 +00:00
|
|
|
|
|
2023-11-10 09:18:00 +00:00
|
|
|
|
onMounted(() => {
|
2024-05-23 10:57:49 +00:00
|
|
|
|
if (documentsType.value) {
|
|
|
|
|
|
form.value.fileType = documentsType.value
|
|
|
|
|
|
}
|
2023-11-10 09:18:00 +00:00
|
|
|
|
if (documentsFiles.value) {
|
|
|
|
|
|
form.value.fileList = documentsFiles.value
|
|
|
|
|
|
}
|
|
|
|
|
|
})
|
2023-11-14 10:12:55 +00:00
|
|
|
|
onUnmounted(() => {
|
|
|
|
|
|
form.value = {
|
2024-05-23 10:57:49 +00:00
|
|
|
|
fileType: 'txt',
|
2023-11-14 10:12:55 +00:00
|
|
|
|
fileList: []
|
|
|
|
|
|
}
|
|
|
|
|
|
})
|
2023-10-27 09:49:06 +00:00
|
|
|
|
|
|
|
|
|
|
defineExpose({
|
2023-11-02 01:56:14 +00:00
|
|
|
|
validate,
|
|
|
|
|
|
form
|
2023-10-27 09:49:06 +00:00
|
|
|
|
})
|
|
|
|
|
|
</script>
|
|
|
|
|
|
<style scoped lang="scss">
|
|
|
|
|
|
.upload__decoration {
|
|
|
|
|
|
font-size: 12px;
|
|
|
|
|
|
line-height: 20px;
|
|
|
|
|
|
color: var(--el-text-color-secondary);
|
|
|
|
|
|
}
|
2024-04-18 03:09:33 +00:00
|
|
|
|
.el-upload__text {
|
|
|
|
|
|
.hover:hover {
|
|
|
|
|
|
color: var(--el-color-primary-light-5);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2023-10-27 09:49:06 +00:00
|
|
|
|
</style>
|