feat: 【知识库】上传文档时,支持选择文件夹(#36)
This commit is contained in:
parent
621421cf50
commit
10408c5711
@ -9,6 +9,7 @@
|
|||||||
>
|
>
|
||||||
<el-form-item prop="fileList">
|
<el-form-item prop="fileList">
|
||||||
<el-upload
|
<el-upload
|
||||||
|
:webkitdirectory="false"
|
||||||
class="w-full"
|
class="w-full"
|
||||||
drag
|
drag
|
||||||
multiple
|
multiple
|
||||||
@ -19,18 +20,18 @@
|
|||||||
accept=".txt, .md, .csv, .log, .docx, .pdf"
|
accept=".txt, .md, .csv, .log, .docx, .pdf"
|
||||||
:limit="50"
|
:limit="50"
|
||||||
:on-exceed="onExceed"
|
:on-exceed="onExceed"
|
||||||
:on-change="filehandleChange"
|
:on-change="fileHandleChange"
|
||||||
|
@click.prevent="handlePreview(false)"
|
||||||
>
|
>
|
||||||
<img src="@/assets/upload-icon.svg" alt="" />
|
<img src="@/assets/upload-icon.svg" alt="" />
|
||||||
<div class="el-upload__text">
|
<div class="el-upload__text">
|
||||||
<p>
|
<p>
|
||||||
将文件拖拽至此区域或
|
拖拽文件至此上传或
|
||||||
<em> 选择文件上传 </em>
|
<em class="hover" @click.prevent="handlePreview(false)"> 选择文件 </em>
|
||||||
|
<em class="hover" @click.prevent="handlePreview(true)"> 选择文件夹 </em>
|
||||||
</p>
|
</p>
|
||||||
<div class="upload__decoration">
|
<div class="upload__decoration">
|
||||||
<p>
|
<p>支持格式:TXT、Markdown、PDF、DOCX,每次最多上传50个文件,每个文件不超过 100MB</p>
|
||||||
支持格式:TXT、Markdown、PDF、DOCX,每次最多上传50个文件,每个文件不超过 100MB
|
|
||||||
</p>
|
|
||||||
<p>若使用【高级分段】建议上传前规范文件的分段标识</p>
|
<p>若使用【高级分段】建议上传前规范文件的分段标识</p>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
@ -59,7 +60,7 @@
|
|||||||
</el-row>
|
</el-row>
|
||||||
</template>
|
</template>
|
||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import { ref, reactive, onUnmounted, onMounted, computed, watch } from 'vue'
|
import { ref, reactive, onUnmounted, onMounted, computed, watch, nextTick } from 'vue'
|
||||||
import type { UploadFile, UploadFiles } from 'element-plus'
|
import type { UploadFile, UploadFiles } from 'element-plus'
|
||||||
import { filesize, getImgUrl, isRightType } from '@/utils/utils'
|
import { filesize, getImgUrl, isRightType } from '@/utils/utils'
|
||||||
import { MsgError } from '@/utils/message'
|
import { MsgError } from '@/utils/message'
|
||||||
@ -83,7 +84,7 @@ function deleteFile(index: number) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// 上传on-change事件
|
// 上传on-change事件
|
||||||
const filehandleChange = (file: any, fileList: UploadFiles) => {
|
const fileHandleChange = (file: any, fileList: UploadFiles) => {
|
||||||
//1、判断文件大小是否合法,文件限制不能大于10M
|
//1、判断文件大小是否合法,文件限制不能大于10M
|
||||||
const isLimit = file?.size / 1024 / 1024 < 100
|
const isLimit = file?.size / 1024 / 1024 < 100
|
||||||
if (!isLimit) {
|
if (!isLimit) {
|
||||||
@ -101,6 +102,17 @@ const filehandleChange = (file: any, fileList: UploadFiles) => {
|
|||||||
const onExceed = () => {
|
const onExceed = () => {
|
||||||
MsgError('每次最多上传50个文件')
|
MsgError('每次最多上传50个文件')
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
表单校验
|
表单校验
|
||||||
*/
|
*/
|
||||||
@ -133,4 +145,9 @@ defineExpose({
|
|||||||
line-height: 20px;
|
line-height: 20px;
|
||||||
color: var(--el-text-color-secondary);
|
color: var(--el-text-color-secondary);
|
||||||
}
|
}
|
||||||
|
.el-upload__text {
|
||||||
|
.hover:hover {
|
||||||
|
color: var(--el-color-primary-light-5);
|
||||||
|
}
|
||||||
|
}
|
||||||
</style>
|
</style>
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user