|
|
|
@ -377,6 +377,11 @@ export default { |
|
|
|
|
|
|
|
preUplpadClose() { |
|
|
|
this.$refs.preUploadRefs.handleCloseDialog() |
|
|
|
this.minioPreResult = [] |
|
|
|
this.jsonArrayStore = [] |
|
|
|
this.fileNameStore = [] |
|
|
|
this.fileOriginal = '' |
|
|
|
this.fileJsonString = null // 恢复初始值为null,和你的业务初始状态一致 |
|
|
|
}, |
|
|
|
// handleSuccessResource(data, fileName, jsonArrayToSend) { |
|
|
|
// this.minioPreResult = data |
|
|
|
@ -397,59 +402,54 @@ export default { |
|
|
|
// this.fileJsonString = JSON.stringify(fileJson) |
|
|
|
// }, |
|
|
|
handleSuccessResource(data, fileName, jsonArrayToSend) { |
|
|
|
// 1. 初始化全局数组,确保为数组类型 |
|
|
|
console.log('原始fileJsonString:', this.fileJsonString) |
|
|
|
|
|
|
|
// 初始化全局存储数组 |
|
|
|
if (!Array.isArray(this.minioPreResult)) this.minioPreResult = [] |
|
|
|
if (!Array.isArray(this.jsonArrayStore)) this.jsonArrayStore = [] |
|
|
|
if (!Array.isArray(this.fileNameStore)) this.fileNameStore = [] |
|
|
|
|
|
|
|
// 2. 统一处理入参格式:转为数组,兼容单个值的情况 |
|
|
|
const newMinioData = Array.isArray(data) ? data : [data] // 新minio项数组 |
|
|
|
const newFileNames = Array.isArray(fileName) ? fileName : [fileName] // 新文件名数组 |
|
|
|
const newJsonData = Array.isArray(jsonArrayToSend) ? jsonArrayToSend : [jsonArrayToSend] // 新json项数组 |
|
|
|
// 统一入参为数组格式 |
|
|
|
const newMinioData = Array.isArray(data) ? data : [data] |
|
|
|
const newFileNames = Array.isArray(fileName) ? fileName : [fileName] |
|
|
|
const newJsonData = Array.isArray(jsonArrayToSend) ? jsonArrayToSend : [jsonArrayToSend] |
|
|
|
|
|
|
|
// 3. 按文件名去重,合并三组数据(核心逻辑) |
|
|
|
// 第一步:按fileNameStore过滤新上传数据(原有去重逻辑) |
|
|
|
newMinioData.forEach((minioItem, index) => { |
|
|
|
// 获取当前索引对应的文件名(容错:避免文件名数组长度不足) |
|
|
|
const currentFileName = newFileNames[index]?.trim() || `未知文件_${index}` |
|
|
|
// 获取当前索引对应的json项(容错) |
|
|
|
const currentJsonItem = newJsonData[index] || {} |
|
|
|
|
|
|
|
// 3.1 判断文件名是否重复:检查全局fileNameStore中是否已存在该文件名 |
|
|
|
const isDuplicate = this.fileNameStore.some( |
|
|
|
// 判断文件名是否已在全局存储中存在 |
|
|
|
const isDuplicateInStore = this.fileNameStore.some( |
|
|
|
storedName => storedName.trim() === currentFileName |
|
|
|
) |
|
|
|
|
|
|
|
if (isDuplicate) { |
|
|
|
console.log(`文件名【${currentFileName}】已存在,跳过合并该条数据`) |
|
|
|
if (isDuplicateInStore) { |
|
|
|
console.log(`文件名【${currentFileName}】已在全局存储中存在,跳过合并该条数据`) |
|
|
|
return |
|
|
|
} |
|
|
|
|
|
|
|
// 3.2 不重复则同步追加三组数据(保证索引一一对应) |
|
|
|
// 不重复则追加到全局存储 |
|
|
|
this.minioPreResult.push(minioItem) |
|
|
|
this.jsonArrayStore.push(currentJsonItem) |
|
|
|
this.fileNameStore.push(currentFileName) |
|
|
|
console.log(`文件名【${currentFileName}】合并成功`) |
|
|
|
console.log(`文件名【${currentFileName}】合并到全局存储成功`) |
|
|
|
}) |
|
|
|
|
|
|
|
// 4. 重新拼接全量文件名(去重后的所有文件名用逗号分隔) |
|
|
|
this.fileOriginal = this.fileNameStore.join(',') |
|
|
|
|
|
|
|
// 5. 基于合并后的全量数据生成fileJsonList |
|
|
|
let fileJsonList = [] |
|
|
|
// 基于全局存储生成本次新的fileJsonList |
|
|
|
let newFileJsonList = [] |
|
|
|
this.minioPreResult.forEach((minioItem, index) => { |
|
|
|
const jsonItem = this.jsonArrayStore[index] |
|
|
|
// 容错:无对应json项或无fileJsonString时跳过 |
|
|
|
if (!jsonItem || !jsonItem.fileJsonString) { |
|
|
|
console.warn(`第${index}个文件【${this.fileNameStore[index]}】无有效JSON数据,跳过`) |
|
|
|
return |
|
|
|
} |
|
|
|
|
|
|
|
try { |
|
|
|
// 解析JSON字符串并统一转为数组 |
|
|
|
const parsed = JSON.parse(jsonItem.fileJsonString) |
|
|
|
const fileItems = Array.isArray(parsed) ? parsed : [parsed] |
|
|
|
console.log('minioItem', minioItem) |
|
|
|
// 映射minio属性到每个文件项 |
|
|
|
console.log('当前minioItem:', minioItem) |
|
|
|
|
|
|
|
const mappedItems = fileItems.map(fileItem => ({ |
|
|
|
...fileItem, |
|
|
|
file_path: '/' + (minioItem.filePath || ''), |
|
|
|
@ -457,18 +457,57 @@ export default { |
|
|
|
last_modified: minioItem.lastModified, |
|
|
|
ca_id: minioItem.caId || '', |
|
|
|
encryption_time: minioItem.timestamp || '', |
|
|
|
signature: minioItem.signature || '' |
|
|
|
signature: minioItem.signature || '', |
|
|
|
// 新增:携带文件名,用于和历史fileJsonString对比去重(关键) |
|
|
|
file_name: this.fileNameStore[index]?.trim() || `未知文件_${index}` |
|
|
|
})) |
|
|
|
|
|
|
|
fileJsonList = fileJsonList.concat(mappedItems) |
|
|
|
newFileJsonList = newFileJsonList.concat(mappedItems) |
|
|
|
} catch (error) { |
|
|
|
console.error(`第${index}个文件【${this.fileNameStore[index]}】JSON解析失败:`, error) |
|
|
|
} |
|
|
|
}) |
|
|
|
|
|
|
|
// 6. 生成最终的fileJsonString(此时是去重后的全量数据) |
|
|
|
console.log('按文件名去重后的fileJsonList:', fileJsonList) |
|
|
|
this.fileJsonString = JSON.stringify(fileJsonList) |
|
|
|
// 第二步:合并历史fileJsonString数据并去重(核心逻辑) |
|
|
|
// 1. 解析历史数据:处理fileJsonString为null/空的情况 |
|
|
|
let historyFileJsonList = [] |
|
|
|
if (this.fileJsonString && this.fileJsonString !== 'null' && this.fileJsonString !== '[]') { |
|
|
|
try { |
|
|
|
historyFileJsonList = JSON.parse(this.fileJsonString) |
|
|
|
historyFileJsonList = Array.isArray(historyFileJsonList) ? historyFileJsonList : [] |
|
|
|
} catch (error) { |
|
|
|
console.error('解析历史fileJsonString失败,重置为空数组:', error) |
|
|
|
historyFileJsonList = [] |
|
|
|
} |
|
|
|
} |
|
|
|
console.log('解析后的历史数据:', historyFileJsonList) |
|
|
|
|
|
|
|
// 2. 新老数据合并 + 按文件名去重 |
|
|
|
const mergeAllList = [...historyFileJsonList, ...newFileJsonList] |
|
|
|
const uniqueMap = new Map() |
|
|
|
mergeAllList.forEach(item => { |
|
|
|
// 以file_name为唯一键,无则用file_path兜底 |
|
|
|
const uniqueKey = item.file_name || item.file_path || Math.random().toString(36).substr(2, 8) |
|
|
|
uniqueMap.set(uniqueKey, item) |
|
|
|
}) |
|
|
|
// 转换为最终的去重数组 |
|
|
|
const finalFileJsonList = Array.from(uniqueMap.values()) |
|
|
|
console.log('新老数据合并去重后的最终列表:', finalFileJsonList) |
|
|
|
|
|
|
|
// 第三步:基于最终的finalFileJsonList重新生成fileOriginal(核心修改点) |
|
|
|
// 提取所有非空的文件名,去重后拼接 |
|
|
|
const finalFileNames = finalFileJsonList |
|
|
|
.map(item => item.file_name?.trim()) // 提取文件名并去空格 |
|
|
|
.filter(name => name && name !== '未知文件') // 过滤空值和默认未知文件 |
|
|
|
// 去重(避免重复文件名) |
|
|
|
const uniqueFinalFileNames = [...new Set(finalFileNames)] |
|
|
|
// 拼接为最终的fileOriginal |
|
|
|
this.fileOriginal = uniqueFinalFileNames.join(',') || '' |
|
|
|
console.log('最终拼接的fileOriginal:', this.fileOriginal) |
|
|
|
|
|
|
|
// 第四步:更新fileJsonString |
|
|
|
this.fileJsonString = JSON.stringify(finalFileJsonList) |
|
|
|
console.log('最终更新后的fileJsonString:', this.fileJsonString) |
|
|
|
}, |
|
|
|
handleErrorResource(res) { |
|
|
|
console.log('handleErrorResource', res) |
|
|
|
|