Skip to content

Commit 10408c5

Browse files
feat: 【知识库】上传文档时,支持选择文件夹(#36)
1 parent 621421c commit 10408c5

File tree

1 file changed

+25
-8
lines changed

1 file changed

+25
-8
lines changed

ui/src/views/dataset/component/UploadComponent.vue

Lines changed: 25 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
>
1010
<el-form-item prop="fileList">
1111
<el-upload
12+
:webkitdirectory="false"
1213
class="w-full"
1314
drag
1415
multiple
@@ -19,18 +20,18 @@
1920
accept=".txt, .md, .csv, .log, .docx, .pdf"
2021
:limit="50"
2122
:on-exceed="onExceed"
22-
:on-change="filehandleChange"
23+
:on-change="fileHandleChange"
24+
@click.prevent="handlePreview(false)"
2325
>
2426
<img src="@/assets/upload-icon.svg" alt="" />
2527
<div class="el-upload__text">
2628
<p>
27-
将文件拖拽至此区域或
28-
<em> 选择文件上传 </em>
29+
拖拽文件至此上传或
30+
<em class="hover" @click.prevent="handlePreview(false)"> 选择文件 </em>
31+
<em class="hover" @click.prevent="handlePreview(true)"> 选择文件夹 </em>
2932
</p>
3033
<div class="upload__decoration">
31-
<p>
32-
支持格式:TXT、Markdown、PDF、DOCX,每次最多上传50个文件,每个文件不超过 100MB
33-
</p>
34+
<p>支持格式:TXT、Markdown、PDF、DOCX,每次最多上传50个文件,每个文件不超过 100MB</p>
3435
<p>若使用【高级分段】建议上传前规范文件的分段标识</p>
3536
</div>
3637
</div>
@@ -59,7 +60,7 @@
5960
</el-row>
6061
</template>
6162
<script setup lang="ts">
62-
import { ref, reactive, onUnmounted, onMounted, computed, watch } from 'vue'
63+
import { ref, reactive, onUnmounted, onMounted, computed, watch, nextTick } from 'vue'
6364
import type { UploadFile, UploadFiles } from 'element-plus'
6465
import { filesize, getImgUrl, isRightType } from '@/utils/utils'
6566
import { MsgError } from '@/utils/message'
@@ -83,7 +84,7 @@ function deleteFile(index: number) {
8384
}
8485
8586
// 上传on-change事件
86-
const filehandleChange = (file: any, fileList: UploadFiles) => {
87+
const fileHandleChange = (file: any, fileList: UploadFiles) => {
8788
//1、判断文件大小是否合法,文件限制不能大于10M
8889
const isLimit = file?.size / 1024 / 1024 < 100
8990
if (!isLimit) {
@@ -101,6 +102,17 @@ const filehandleChange = (file: any, fileList: UploadFiles) => {
101102
const onExceed = () => {
102103
MsgError('每次最多上传50个文件')
103104
}
105+
106+
const handlePreview = (bool: boolean) => {
107+
let inputDom: any = null
108+
nextTick(() => {
109+
if (document.querySelector('.el-upload__input') != null) {
110+
inputDom = document.querySelector('.el-upload__input')
111+
inputDom.webkitdirectory = bool
112+
}
113+
})
114+
}
115+
104116
/*
105117
表单校验
106118
*/
@@ -133,4 +145,9 @@ defineExpose({
133145
line-height: 20px;
134146
color: var(--el-text-color-secondary);
135147
}
148+
.el-upload__text {
149+
.hover:hover {
150+
color: var(--el-color-primary-light-5);
151+
}
152+
}
136153
</style>

0 commit comments

Comments
 (0)