为小程序报名页面添加了完整的附件上传功能,支持多种文件类型,包含文件验证、进度显示、错误处理等完整功能。
attachmentMediaIds
和avatarMediaId
字段// 核心数据结构
data: {
attachments: [], // 附件列表
maxAttachments: 8, // 最大附件数量
fileTypeConfig: { // 文件类型配置
image: { extensions: ['.jpg', '.jpeg', '.png', '.gif'], maxSize: 50, icon: '🖼️' },
video: { extensions: ['.mp4', '.avi', '.mov'], maxSize: 50, icon: '🎥' },
pdf: { extensions: ['.pdf'], maxSize: 20, icon: '📄' },
// ... 更多类型
}
}
// 核心方法
onChooseAttachment() // 选择文件
uploadAttachment() // 上传文件
validateAttachment() // 验证文件
onDeleteAttachment() // 删除文件
formatFileSize() // 格式化文件大小
input ActivityRegistrationInput {
activityId: ID!
playerInfo: PlayerRegistrationInput!
regionId: ID
projectName: String
description: String
mediaFiles: [MediaFileInput!]
attachmentMediaIds: [String!] # 新增附件ID列表
}
input PlayerRegistrationInput {
name: String!
phone: String!
gender: Int
birthDate: String
education: String
introduction: String
description: String
avatarMediaId: String # 新增头像ID
}
用户选择文件 → 文件验证 → 上传到COS → 获取mediaId → 存储到本地数组
收集表单数据 → 构建GraphQL请求 → 包含attachmentMediaIds → 发送到后端 → 存储到数据库
可在fileTypeConfig
中调整支持的文件类型、大小限制和显示图标。
可通过maxAttachments
调整最大附件数量。
需要配置腾讯云COS的相关参数 (在cosUtil.js中)。
附件上传功能已完整实现,包含:
- ✅ 完整的前端UI和交互
- ✅ robust的文件验证和错误处理
- ✅ 实时的上传进度和状态管理
- ✅ 完整的后端API支持
- ✅ 数据库存储和关联
- ✅ 全面的测试验证
该功能已准备好投入生产使用,为用户提供了完整、安全、易用的附件上传体验。