Skip to content

Commit cc377b3

Browse files
author
weilei
committed
feat(examples): 添加文件上传数量限制和状态反馈
1 parent e5c68e2 commit cc377b3

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

examples/src/views/DifyChat/mixins/fileMixin.js

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,29 @@ export default {
44
data() {
55
return {
66
uploadedFiles: [],
7+
maxFileCount: 3,
78
};
89
},
10+
computed: {
11+
fileCountStatus() {
12+
return `${this.uploadedFiles.length}/${this.maxFileCount}个文件`;
13+
},
14+
isFileCountLimit() {
15+
return this.uploadedFiles.length >= this.maxFileCount;
16+
},
17+
},
918
watch: {
1019
uploadedFiles: {
1120
handler(newFiles) {
1221
// 监听上传文件变化,控制header显示隐藏
1322
this.$nextTick(() => {
1423
this.$emit('files-changed', newFiles);
24+
this.$emit('file-status-changed', {
25+
count: newFiles.length,
26+
maxCount: this.maxFileCount,
27+
status: this.fileCountStatus,
28+
isLimit: this.isFileCountLimit,
29+
});
1530
});
1631
},
1732
deep: true,
@@ -28,6 +43,12 @@ export default {
2843
async handleFileChange(file) {
2944
if (!file) return;
3045

46+
// 检查文件数量限制
47+
if (this.uploadedFiles.length >= this.maxFileCount) {
48+
this.$message.warning(`最多只能上传${this.maxFileCount}个文件,请先删除现有文件后再试`);
49+
return;
50+
}
51+
3152
try {
3253
const response = await fileApi.uploadFile(file, this.difyConfig.user);
3354
// 按照 Dify API 规范格式化文件对象

0 commit comments

Comments
 (0)