feat : 对接专业搜索联想数据源接口,upload.html新增文件类型限制参数(带默认)
This commit is contained in:
@@ -615,8 +615,7 @@
|
||||
<div class="upload-icon">📁</div>
|
||||
<div class="upload-text" id="uploadText">点击选择文件</div>
|
||||
<div class="upload-hint" id="uploadHint">支持图片、文档、文本等格式</div>
|
||||
<input type="file" id="fileInput" class="file-input" multiple
|
||||
accept="image/*,.pdf,.doc,.docx,.xls,.xlsx,.csv,.ppt,.pptx,.txt,.md" />
|
||||
<input type="file" id="fileInput" class="file-input" multiple />
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -663,6 +662,9 @@
|
||||
const sessionId = urlParams.get('sessionId');
|
||||
const uploadApi = urlParams.get('uploadApi');
|
||||
const fileCountParam = urlParams.get('fileCount');
|
||||
const acceptParam = urlParams.get('accept');
|
||||
const DEFAULT_ACCEPT = 'image/*,.pdf,.doc,.docx,.xls,.xlsx,.csv,.ppt,.pptx,.txt,.md';
|
||||
const ACCEPT_TYPES = acceptParam ? acceptParam : DEFAULT_ACCEPT;
|
||||
|
||||
// 配置常量
|
||||
const MAX_FILE_COUNT = fileCountParam ? parseInt(fileCountParam) : 2; // 从URL参数获取,默认为2
|
||||
@@ -671,6 +673,7 @@
|
||||
console.log('Session ID:', sessionId);
|
||||
console.log('Upload API:', uploadApi);
|
||||
console.log('Max file count:', MAX_FILE_COUNT);
|
||||
console.log('允许上传类型:', ACCEPT_TYPES);
|
||||
|
||||
// DOM元素
|
||||
const uploadArea = document.getElementById('uploadArea');
|
||||
@@ -692,6 +695,10 @@
|
||||
const limitWarningInfo = document.getElementById('limitWarningInfo');
|
||||
const limitWarningText = document.getElementById('limitWarningText');
|
||||
|
||||
|
||||
//设置文件类型
|
||||
fileInput.accept = ACCEPT_TYPES;
|
||||
|
||||
// 状态变量
|
||||
let selectedFiles = [];
|
||||
let isUploading = false;
|
||||
@@ -1079,7 +1086,7 @@
|
||||
if (MAX_FILE_COUNT <= 0) {
|
||||
// 如果没有设置文件数量限制,始终可以上传
|
||||
uploadText.textContent = '点击选择文件';
|
||||
uploadHint.innerHTML = '支持图片、文档、文本等格式<br />文件大小不超过10MB';
|
||||
uploadHint.innerHTML = `支持格式: ${ACCEPT_TYPES}<br />文件大小不超过10MB`;
|
||||
fileInput.disabled = false;
|
||||
} else if (selectedFiles.length >= MAX_FILE_COUNT) {
|
||||
uploadText.textContent = `已达到最大文件数量(${MAX_FILE_COUNT}个)`;
|
||||
@@ -1087,8 +1094,7 @@
|
||||
fileInput.disabled = true;
|
||||
} else {
|
||||
uploadText.textContent = '点击选择文件';
|
||||
uploadHint.innerHTML =
|
||||
`支持图片、文档、文本等格式<br />最多${MAX_FILE_COUNT}个文件,每个不超过10MB<br />已上传: ${uploadedCount}/${MAX_FILE_COUNT}`;
|
||||
uploadHint.innerHTML = `支持格式: ${ACCEPT_TYPES}<br />最多${MAX_FILE_COUNT}个文件,每个不超过10MB`;
|
||||
fileInput.disabled = false;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user