+
+
+ 将文件拖到此处,或点击上传
+
+ 仅允许导入xlsx、xls格式文件,支持批量选择多个文件
+
+ 文件名格式:动量原始股(全部A股)_20250424.xlsx,其中20250424为交易日期
+
+
+
+
+ 更新已存在数据
+
+
+
+ 已选择文件
+
+
+
+
+
+ 待处理
+ 成功
+ 失败
+
+
+
+
+ 删除
+
+
+
+
+
+
@@ -422,6 +481,14 @@ export default {
},
fileList: [],
+ // ========================= 批量上传相关 =========================
+ batchUpload: {
+ open: false,
+ updateSupport: false,
+ loading: false
+ },
+ batchFileList: [],
+
// ========================= 分析状态相关 =========================
analysisStatus: {
isAnalyzed: false, // 当前选择日期是否已分析
@@ -817,6 +884,130 @@ export default {
} else if (this.upload.type === 'stockHighLow') {
this.getStockHighLowList()
}
+ },
+
+ // ========================= 批量导入方法 =========================
+
+ /** 打开批量导入对话框 */
+ handleBatchImport() {
+ this.batchUpload.open = true
+ this.batchUpload.updateSupport = false
+ this.batchFileList = []
+ // 清除已选文件
+ this.$nextTick(() => {
+ if (this.$refs.batchUploadRef) {
+ this.$refs.batchUploadRef.clearFiles()
+ }
+ })
+ },
+
+ /** 批量文件选择变化 */
+ handleBatchFileChange(file, fileList) {
+ // 处理文件列表,解析交易日期
+ this.batchFileList = fileList.map(item => {
+ const tradeDate = this.parseTradeDateFromFileName(item.name)
+ return {
+ name: item.name,
+ raw: item.raw,
+ tradeDate: tradeDate,
+ status: 'pending'
+ }
+ })
+ },
+
+ /** 从文件名解析交易日期 */
+ parseTradeDateFromFileName(fileName) {
+ // 匹配文件名中的日期格式,例如:动量原始股(全部A股)_20250424.xlsx
+ const match = fileName.match(/_([0-9]{8})\.xlsx?$/i)
+ if (match && match[1]) {
+ const dateStr = match[1]
+ // 格式化日期为 yyyy-MM-dd
+ return `${dateStr.substring(0, 4)}-${dateStr.substring(4, 6)}-${dateStr.substring(6, 8)}`
+ }
+ return '解析失败'
+ },
+
+ /** 删除批量导入文件 */
+ removeBatchFile(index) {
+ this.batchFileList.splice(index, 1)
+ // 同步更新上传组件的文件列表
+ if (this.$refs.batchUploadRef) {
+ this.$refs.batchUploadRef.clearFiles()
+ // 重新添加剩余文件
+ this.batchFileList.forEach(item => {
+ this.$refs.batchUploadRef.handleStart({ raw: item.raw, name: item.name })
+ })
+ }
+ },
+
+ /** 提交批量上传 */
+ submitBatchUpload() {
+ if (this.batchFileList.length === 0) {
+ this.$message.error('请选择要上传的文件')
+ return
+ }
+
+ // 检查是否有解析失败的文件
+ const invalidFiles = this.batchFileList.filter(item => item.tradeDate === '解析失败')
+ if (invalidFiles.length > 0) {
+ this.$message.error('部分文件的交易日期解析失败,请检查文件名格式')
+ return
+ }
+
+ this.batchUpload.loading = true
+
+ // 按顺序处理每个文件
+ const processFile = async (index) => {
+ if (index >= this.batchFileList.length) {
+ // 所有文件处理完成
+ this.batchUpload.loading = false
+ this.batchUpload.open = false
+ this.$message.success('批量导入完成')
+ // 刷新数据列表
+ this.getDailyTradeList()
+ return
+ }
+
+ const fileItem = this.batchFileList[index]
+ try {
+ await this.processBatchFile(fileItem)
+ // 处理下一个文件
+ processFile(index + 1)
+ } catch (error) {
+ this.batchUpload.loading = false
+ this.$message.error('批量导入过程中发生错误:' + (error.message || '未知错误'))
+ }
+ }
+
+ // 开始处理第一个文件
+ processFile(0)
+ },
+
+ /** 处理单个批量文件的导入 */
+ processBatchFile(fileItem) {
+ return new Promise((resolve, reject) => {
+ const formData = new FormData()
+ formData.append('file', fileItem.raw)
+ formData.append('updateSupport', this.batchUpload.updateSupport)
+ formData.append('tradeDate', fileItem.tradeDate)
+
+ request({
+ url: IMPORT_URLS.stockDailyTrade,
+ method: 'post',
+ data: formData,
+ headers: {
+ 'Content-Type': 'multipart/form-data'
+ }
+ }).then(response => {
+ // 更新文件状态为成功
+ fileItem.status = 'success'
+ resolve()
+ }).catch(error => {
+ // 更新文件状态为失败
+ fileItem.status = 'error'
+ resolve() // 继续处理下一个文件,即使当前文件失败
+ })
+ })
}
}
}