阅行客电子档案
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

900 lines
30 KiB

2 months ago
2 months ago
2 months ago
2 months ago
10 months ago
2 months ago
2 years ago
10 months ago
2 months ago
2 months ago
2 years ago
2 months ago
2 years ago
2 months ago
2 years ago
2 months ago
2 years ago
2 months ago
2 months ago
10 months ago
2 years ago
2 months ago
10 months ago
2 months ago
10 months ago
2 months ago
2 months ago
2 months ago
2 months ago
10 months ago
2 months ago
10 months ago
10 months ago
2 months ago
10 months ago
2 months ago
2 months ago
2 months ago
2 months ago
2 years ago
2 months ago
2 years ago
2 months ago
2 years ago
2 months ago
2 months ago
2 years ago
2 months ago
2 years ago
2 months ago
2 years ago
2 months ago
2 months ago
2 months ago
2 months ago
2 months ago
2 months ago
2 months ago
10 months ago
2 months ago
10 months ago
2 months ago
2 years ago
2 months ago
2 months ago
2 years ago
2 months ago
2 months ago
2 years ago
2 months ago
2 years ago
2 months ago
2 years ago
2 months ago
2 months ago
2 years ago
2 months ago
2 years ago
2 months ago
2 months ago
2 years ago
2 months ago
2 months ago
2 months ago
2 months ago
  1. <template>
  2. <div class="upload-minio">
  3. <el-dialog
  4. title="文件上传列表"
  5. class="minio-file"
  6. :close-on-click-modal="false"
  7. :modal-append-to-body="false"
  8. append-to-body
  9. :visible.sync="uploadMinioVisible"
  10. :before-close="handleCloseDialog"
  11. width="600px"
  12. >
  13. <template #title>
  14. {{ uploadTitle }}
  15. <span style="color: red;font-size: 12px; ">单个文件不可超过10GB</span>
  16. </template>
  17. <div class="uploader-drop" style="margin-bottom: 20px;">
  18. <div class="uploader-btn" @click="triggerFileInput">
  19. <p>{{ !isCatalogUpload ? '点击上传(可多文件上传)' : "点击上传ZIP包(只可单文件上传)" }}</p>
  20. <div style="margin: 20px 0 20px 0;">
  21. <i class="iconfont icon-tianjiawenjian upload-icon" />
  22. <input
  23. ref="fileInput"
  24. type="file"
  25. :accept="isCatalogUpload ? '.zip' : ''"
  26. :multiple="!isCatalogUpload"
  27. :disabled="!isCaValid || isCheckingCa"
  28. class="file-input"
  29. style="display: none;"
  30. @change="handleFileSelect"
  31. >
  32. </div>
  33. </div>
  34. <div class="el-upload__tip">上传限制文件大小最大10GB/</div>
  35. </div>
  36. <div v-if="fileList.length !== 0" style="max-height: 400px; overflow: hidden; overflow-y: scroll;">
  37. <div v-for="(fileItem, index) in fileList" :key="index" class="file-item">
  38. <div class="file-name">
  39. {{ fileItem.file.name }}
  40. <span class="file-size">{{ formatFileSize(fileItem.file.size) }}</span>
  41. <i class="iconfont icon-shanchu" @click="handleDeleteFile(index)" />
  42. </div>
  43. <div v-if="fileItem.uploading" class="progress-wrapper">
  44. <span class="progress-text">上传进度: {{ fileItem.progress }}%</span>
  45. <div class="progress-bar" :style="{ width: fileItem.progress + '%' }" />
  46. </div>
  47. <div v-if="fileItem.merging" class="merge-loading ">
  48. <span>合并中...</span>
  49. </div>
  50. <p v-if="fileItem.errorMsg" class="error">{{ fileItem.errorMsg }}</p>
  51. <p v-if="fileItem.successMsg" class="success">{{ fileItem.successMsg }}</p>
  52. </div>
  53. </div>
  54. <div slot="footer" class="dialog-footer" style="margin-top: 0;">
  55. <el-button type="text" @click="handleCloseDialog">取消</el-button>
  56. <el-button :disabled="fileList.some(item => item.uploading || item.merging) || fileList.length === 0" :loading="btnLoading" type="primary" @click="handleUploadConfirm">保存</el-button>
  57. </div>
  58. </el-dialog>
  59. <!-- 判断是否有重复上传的文件 -->
  60. <el-dialog class="collectUpload-dialog" title="文件上传" :close-on-click-modal="false" :modal-append-to-body="false" append-to-body :visible.sync="repeatFileVisible">
  61. <div class="setting-dialog">
  62. <p style="color:#f00;margin-bottom: 20px;display:block">提示以下所选文件在当前档案文件列表已存在</p>
  63. <div v-for="item in repeatFileData" :key="item.name" class="file-list" style="margin-bottom: 10px;">
  64. <i class="iconfont icon-xiaowenjian" />
  65. {{ item.name }}
  66. </div>
  67. </div>
  68. <div slot="footer" class="dialog-footer">
  69. <el-button type="primary" @click="handleRepeatFile(0)">直接上传</el-button>
  70. <el-button style="width: 85px;" type="primary" @click="handleRepeatFile(1)">去重后上传</el-button>
  71. <el-button type="text" @click="repeatFileVisible = false">取消</el-button>
  72. </div>
  73. </el-dialog>
  74. <!-- 目录上传报错 -->
  75. <el-dialog class="catalog-dialog" title="目录上传-失败列表" :close-on-click-modal="false" :modal-append-to-body="false" append-to-body :visible.sync="catalogErrorVisible">
  76. <div class="setting-dialog">
  77. <div style="margin-bottom: 20px; display:flex; justify-content: flex-start;">
  78. <p style="margin-right: 20px;">总条数 <span style=" font-weight: bold;">{{ resultCatalog && resultCatalog.mountFile.total }} </span> </p>
  79. <p style="margin-right: 20px;">成功 <span style="color:#1AAE93; font-weight: bold;">{{ resultCatalog && resultCatalog.mountFile.successNum }} </span> </p>
  80. <p>失败 <span style="color:#f00; font-weight: bold; ">{{ resultCatalog && resultCatalog.mountFile.failNum }}</span> </p>
  81. </div>
  82. <el-table class="archives-table" :data="catalogInfoData" style="min-width: 100%" height="calc(100vh - 676px)">
  83. <el-table-column type="expand">
  84. <template #default="{ row }">
  85. <el-row style="padding-left: 20px;">
  86. <el-col :span="24" style="line-height: 30px;">
  87. <div v-for="(file, index) in row.children" :key="index"><i class="iconfont icon-xiaowenjian" />{{ file }}</div>
  88. </el-col>
  89. </el-row>
  90. </template>
  91. </el-table-column>
  92. <el-table-column prop="archives" label="档案/电子原文" />
  93. <el-table-column prop="description" label="失败原因" />
  94. </el-table>
  95. </div>
  96. <div slot="footer" class="dialog-footer">
  97. <el-button type="primary" @click="catalogErrorVisible = false">确定</el-button>
  98. </div>
  99. </el-dialog>
  100. </div>
  101. </template>
  102. <script>
  103. import { FetchCheckCaValidity } from '@/api/system/auth2'
  104. import { FetchInitFileCategoryView } from '@/api/collect/collect'
  105. import { mapGetters } from 'vuex'
  106. import axios from 'axios'
  107. import SparkMD5 from 'spark-md5'
  108. import { getToken } from '@/utils/auth'
  109. import { getCurrentTime } from '@/utils/index'
  110. import { catalogUpload } from '@/utils/upload'
  111. export default {
  112. name: 'MinioMultiChunkUpload',
  113. props: {
  114. selectedDocument: {
  115. type: Object,
  116. default: () => ({})
  117. },
  118. arcId: {
  119. type: String,
  120. default: ''
  121. },
  122. selectedCategory: {
  123. type: Object,
  124. default: () => ({})
  125. },
  126. isBatchMount: {
  127. type: String,
  128. default: ''
  129. }
  130. },
  131. computed: {
  132. ...mapGetters([
  133. 'baseApi'
  134. ])
  135. },
  136. data() {
  137. return {
  138. uploadMinioVisible: false, // 弹框显示状态
  139. fileList: [], // 多文件上传列表
  140. CHUNK_SIZE: 5 * 1024 * 1024, // 分片大小 (5MB)
  141. totalMergeStartTime: null, // 整体批量合并开始时间
  142. totalMergeEndTime: null, // 整体批量合并结束时间
  143. allChunksUploaded: false, // 所有文件分片是否上传完成
  144. isCaValid: false, // CA证书是否有效
  145. isCheckingCa: false, // 是否正在校验CA状态
  146. // 新增目录上传相关
  147. isCatalogUpload: false,
  148. uploadTitle: '文件上传',
  149. btnLoading: false,
  150. // 重复文件相关
  151. repeatFileVisible: false,
  152. repeatFileData: [],
  153. originFileData: [],
  154. tempSelectedFiles: null, // 临时存储选择的文件
  155. // 目录上传报错相关
  156. resultCatalog: {
  157. mountFile: {},
  158. failArchives: []
  159. },
  160. catalogErrorVisible: false,
  161. catalogInfoData: []
  162. }
  163. },
  164. mounted() {
  165. this.getCheckCaValidity() // 初始化时自动校验CA证书
  166. },
  167. methods: {
  168. triggerFileInput() {
  169. this.$refs.fileInput.click()
  170. },
  171. handleDeleteFile(index) {
  172. // 校验是否正在上传/合并,避免删除操作冲突
  173. const fileItem = this.fileList[index]
  174. if (fileItem.uploading || fileItem.merging) {
  175. this.showMessage('当前文件正在上传/合并中,无法删除', 'warning')
  176. return
  177. }
  178. // 删除对应索引的文件项
  179. this.fileList.splice(index, 1)
  180. this.showMessage('文件已移除', 'success')
  181. },
  182. // 切换上传类型(普通文件/目录ZIP包)
  183. updateUploadOptions(uploadType) {
  184. this.isCatalogUpload = uploadType !== 1
  185. this.uploadTitle = this.isCatalogUpload ? '原文目录上传' : '文件上传'
  186. this.fileList = []
  187. this.uploadMinioVisible = true
  188. },
  189. formatFileSize(bytes) {
  190. if (bytes === 0) return '0.00MB'
  191. const mb = bytes / (1024 * 1024)
  192. return mb.toFixed(2) + 'MB'
  193. },
  194. /**
  195. * 工具方法格式化时间戳为易读的本地时间带毫秒
  196. */
  197. formatTime(timestamp) {
  198. if (!timestamp) return '无'
  199. return new Date(timestamp).toLocaleString('zh-CN', {
  200. year: 'numeric',
  201. month: '2-digit',
  202. day: '2-digit',
  203. hour: '2-digit',
  204. minute: '2-digit',
  205. second: '2-digit',
  206. millisecond: '3-digit'
  207. })
  208. },
  209. /**
  210. * 工具方法计算两个时间戳的差值并格式化
  211. */
  212. getTimeDiff(start, end) {
  213. if (!start || !end) return '0ms'
  214. const diff = end - start
  215. if (diff < 1000) return `${diff}ms`
  216. if (diff < 60000) return `${(diff / 1000).toFixed(2)}s`
  217. return `${(diff / 60000).toFixed(2)}min`
  218. },
  219. /**
  220. * 工具方法获取图片分辨率
  221. */
  222. getImgPx(base64) {
  223. return new Promise((resolve) => {
  224. const img = new Image()
  225. img.onload = () => {
  226. resolve({ width: img.width, height: img.height })
  227. }
  228. img.src = base64
  229. })
  230. },
  231. /**
  232. * 工具方法将文件转为base64
  233. */
  234. getBase64(file) {
  235. return new Promise((resolve, reject) => {
  236. const reader = new FileReader()
  237. reader.readAsDataURL(file)
  238. reader.onload = () => resolve(reader.result)
  239. reader.onerror = (err) => reject(err)
  240. })
  241. },
  242. /**
  243. * 工具方法显示提示信息
  244. */
  245. showMessage(message, type) {
  246. this.$message({ message, type, offset: 8 })
  247. },
  248. /**
  249. * 重置上传状态
  250. */
  251. resetUploadState() {
  252. this.allChunksUploaded = false
  253. this.btnLoading = false
  254. },
  255. /**
  256. * 校验CA证书有效性
  257. */
  258. async getCheckCaValidity() {
  259. try {
  260. this.isCheckingCa = true
  261. const res = await FetchCheckCaValidity()
  262. this.isCaValid = !!res
  263. if (!this.isCaValid) {
  264. this.showMessage('CA证书不在有效期内,无法进行分片上传', 'error')
  265. }
  266. } catch (err) {
  267. this.isCaValid = false
  268. this.showMessage('CA证书校验失败:' + err.message, 'error')
  269. console.error('CA校验接口异常:', err)
  270. } finally {
  271. this.isCheckingCa = false
  272. }
  273. },
  274. /**
  275. * 获取已存在的文件列表用于重复文件检测
  276. */
  277. async getFileList() {
  278. const params = {
  279. 'categoryId': this.selectedCategory.id,
  280. 'archivesId': this.arcId
  281. }
  282. const res = await FetchInitFileCategoryView(params)
  283. this.originFileData = res.returnlist || []
  284. },
  285. /**
  286. * 多文件选择处理函数选择后打开弹框检测重复文件
  287. */
  288. async handleFileSelect(e) {
  289. // 1. 校验CA状态(原有逻辑不变)
  290. if (this.isCheckingCa) {
  291. this.showMessage('正在校验CA证书,请稍候...', 'warning')
  292. e.target.value = ''
  293. return
  294. }
  295. if (!this.isCaValid) {
  296. this.showMessage('CA证书不在有效期内,无法上传文件', 'error')
  297. e.target.value = ''
  298. return
  299. }
  300. // 2. 获取选择的文件并初始化列表(原有逻辑不变)
  301. const selectedFiles = Array.from(e.target.files)
  302. if (selectedFiles.length === 0) return
  303. // 3. 重复文件检测(原有逻辑不变)
  304. if (!this.isCatalogUpload) {
  305. await this.getFileList()
  306. const existingFileNames = this.originFileData.map(file => file.file_name)
  307. this.repeatFileData = selectedFiles.filter(file => existingFileNames.includes(file.name))
  308. if (this.repeatFileData.length > 0) {
  309. this.repeatFileVisible = true
  310. this.tempSelectedFiles = selectedFiles
  311. e.target.value = ''
  312. return
  313. }
  314. }
  315. // 4. 初始化文件列表(原有逻辑不变)
  316. const newFileList = selectedFiles.map(file => ({
  317. file,
  318. uploading: false,
  319. merging: false,
  320. progress: 0,
  321. errorMsg: '',
  322. successMsg: '',
  323. md5: '',
  324. md5StartTime: null,
  325. md5EndTime: null,
  326. chunkUploadStartTime: null,
  327. chunkUploadEndTime: null,
  328. mergeStartTime: null,
  329. mergeEndTime: null
  330. }))
  331. this.fileList = [...this.fileList, ...newFileList]
  332. e.target.value = ''
  333. // this.handleUploadConfirm()
  334. },
  335. /**
  336. * 处理重复文件选择
  337. * @param {number} type 0-直接上传 1-去重后上传
  338. */
  339. handleRepeatFile(type) {
  340. this.repeatFileVisible = false
  341. if (!this.tempSelectedFiles) return
  342. let filesToUpload = []
  343. if (type === 0) {
  344. // 直接上传所有文件
  345. filesToUpload = this.tempSelectedFiles
  346. } else {
  347. // 去重后上传
  348. const existingFileNames = this.originFileData.map(file => file.file_name)
  349. filesToUpload = this.tempSelectedFiles.filter(file => !existingFileNames.includes(file.name))
  350. if (filesToUpload.length === 0) {
  351. this.showMessage('当前所选文件去重后无可上传的文件', 'error')
  352. this.$emit('close-dialog')
  353. return
  354. }
  355. }
  356. // 初始化去重后的文件列表
  357. const newFileList = filesToUpload.map(file => ({
  358. file,
  359. uploading: false,
  360. merging: false,
  361. progress: 0,
  362. errorMsg: '',
  363. successMsg: '',
  364. md5: '',
  365. md5StartTime: null,
  366. md5EndTime: null,
  367. chunkUploadStartTime: null,
  368. chunkUploadEndTime: null,
  369. mergeStartTime: null,
  370. mergeEndTime: null
  371. }))
  372. this.fileList = newFileList
  373. this.uploadMinioVisible = true
  374. this.tempSelectedFiles = null
  375. // this.handleUploadConfirm()
  376. },
  377. /**
  378. * 计算文件MD5
  379. */
  380. calculateFileMd5(file, fileItem) {
  381. return new Promise((resolve, reject) => {
  382. fileItem.md5StartTime = new Date().getTime()
  383. console.log(`${file.name}】MD5计算开始时间:${this.formatTime(fileItem.md5StartTime)}`)
  384. const spark = new SparkMD5.ArrayBuffer()
  385. const fileReader = new FileReader()
  386. const chunkSize = 2 * 1024 * 1024
  387. let offset = 0
  388. const loadNextChunk = () => {
  389. const blob = file.slice(offset, offset + chunkSize)
  390. fileReader.readAsArrayBuffer(blob)
  391. }
  392. fileReader.onload = (e) => {
  393. spark.append(e.target.result)
  394. offset += chunkSize
  395. if (offset < file.size) {
  396. loadNextChunk()
  397. } else {
  398. fileItem.md5EndTime = new Date().getTime()
  399. console.log(`${file.name}】MD5计算结束时间:${this.formatTime(fileItem.md5EndTime)},耗时:${this.getTimeDiff(fileItem.md5StartTime, fileItem.md5EndTime)}`)
  400. resolve(spark.end())
  401. }
  402. }
  403. fileReader.onerror = (err) => reject(err)
  404. loadNextChunk()
  405. })
  406. },
  407. /**
  408. * 检查分片是否已存在
  409. */
  410. async checkChunkExists(fileMd5, chunkIndex) {
  411. const linkSrc = process.env.NODE_ENV === 'production' ? window.g.ApiUrl : process.env.VUE_APP_BASE_API
  412. const response = await axios.get(`${linkSrc}/api/collect/chunk`, {
  413. params: { fileMd5, chunkIndex },
  414. headers: { 'Authorization': getToken() }
  415. })
  416. if (response.data.code !== 200) {
  417. throw new Error('检查分片失败: ' + response.data.msg)
  418. }
  419. return response.data.data
  420. },
  421. /**
  422. * 上传单个分片
  423. */
  424. async uploadSingleChunk(file, fileMd5, chunkIndex) {
  425. const start = chunkIndex * this.CHUNK_SIZE
  426. const end = Math.min(start + this.CHUNK_SIZE, file.size)
  427. const chunkBlob = file.slice(start, end)
  428. const formData = new FormData()
  429. formData.append('file', chunkBlob, `${fileMd5}_${chunkIndex}`)
  430. formData.append('fileMd5', fileMd5)
  431. formData.append('chunkIndex', chunkIndex)
  432. const linkSrc = process.env.NODE_ENV === 'production' ? window.g.ApiUrl : process.env.VUE_APP_BASE_API
  433. const response = await axios.post(`${linkSrc}/api/collect/chunk`, formData, {
  434. headers: {
  435. 'Content-Type': 'multipart/form-data',
  436. 'Authorization': getToken()
  437. }
  438. })
  439. if (response.data.code !== 200) {
  440. throw new Error(`分片${chunkIndex}上传失败: ` + response.data.msg)
  441. }
  442. },
  443. /**
  444. * 校验所有分片是否存在
  445. */
  446. async checkAllChunksExist(fileMd5, totalChunks) {
  447. for (let i = 0; i < totalChunks; i++) {
  448. const result = await this.checkChunkExists(fileMd5, i)
  449. if (!result.exists) {
  450. console.warn(`${fileMd5}】分片${i}未上传`)
  451. return false
  452. }
  453. }
  454. return true
  455. },
  456. /**
  457. * 单个文件的分片上传流程
  458. */
  459. async uploadFileChunks(fileItem) {
  460. const file = fileItem.file
  461. fileItem.uploading = true
  462. fileItem.progress = 0
  463. fileItem.errorMsg = ''
  464. fileItem.successMsg = ''
  465. try {
  466. // 计算文件MD5
  467. const fileMd5 = await this.calculateFileMd5(file, fileItem)
  468. fileItem.md5 = fileMd5
  469. console.log(`${file.name}】文件MD5:`, fileMd5)
  470. // 计算总分片数
  471. const totalChunks = Math.ceil(file.size / this.CHUNK_SIZE)
  472. console.log(`${file.name}】总分片数:`, totalChunks)
  473. // 分片上传开始时间
  474. fileItem.chunkUploadStartTime = new Date().getTime()
  475. console.log(`${file.name}】分片上传开始时间:${this.formatTime(fileItem.chunkUploadStartTime)}`)
  476. const uploadedChunks = []
  477. for (let i = 0; i < totalChunks; i++) {
  478. // 检查分片是否已存在
  479. const checkResult = await this.checkChunkExists(fileMd5, i)
  480. if (!checkResult.exists) {
  481. // 上传未存在的分片
  482. await this.uploadSingleChunk(file, fileMd5, i)
  483. }
  484. uploadedChunks.push(i)
  485. fileItem.progress = Math.round((uploadedChunks.length / totalChunks) * 100)
  486. }
  487. // 分片上传结束时间
  488. fileItem.chunkUploadEndTime = new Date().getTime()
  489. console.log(`${file.name}】分片上传结束时间:${this.formatTime(fileItem.chunkUploadEndTime)},耗时:${this.getTimeDiff(fileItem.chunkUploadStartTime, fileItem.chunkUploadEndTime)}`)
  490. fileItem.progress = 100
  491. } catch (err) {
  492. const fileName = file.name
  493. if (fileItem.chunkUploadStartTime && !fileItem.chunkUploadEndTime) {
  494. fileItem.chunkUploadEndTime = new Date().getTime()
  495. console.log(`${fileName}】分片上传异常结束时间:${this.formatTime(fileItem.chunkUploadEndTime)},耗时:${this.getTimeDiff(fileItem.chunkUploadStartTime, fileItem.chunkUploadEndTime)}`)
  496. }
  497. fileItem.errorMsg = '分片上传失败: ' + (err.message || '未知错误')
  498. console.error(`${fileName}】分片上传流程异常:`, err.message)
  499. this.allChunksUploaded = false
  500. } finally {
  501. fileItem.uploading = false
  502. }
  503. },
  504. /**
  505. * 批量上传并合并整合目录上传逻辑
  506. */
  507. async handleUploadConfirm() {
  508. if (this.fileList.length === 0) {
  509. this.showMessage('请先选择要上传的文件!', 'warning')
  510. return
  511. }
  512. // 过滤掉已上传/合并失败的文件
  513. const pendingFiles = this.fileList.filter(item => !item.successMsg && !item.errorMsg)
  514. if (pendingFiles.length === 0) {
  515. this.showMessage('暂无待上传的文件!', 'warning')
  516. return
  517. }
  518. this.btnLoading = true
  519. // 1. 串行上传所有文件的分片
  520. this.allChunksUploaded = true
  521. for (const fileItem of pendingFiles) {
  522. await this.uploadFileChunks(fileItem)
  523. if (fileItem.errorMsg) {
  524. this.allChunksUploaded = false
  525. }
  526. }
  527. // 2. 分片上传完成后执行合并
  528. if (!this.allChunksUploaded) {
  529. this.btnLoading = false
  530. this.showMessage('部分文件分片上传失败,无法执行合并', 'error')
  531. return
  532. }
  533. const validFiles = this.fileList.filter(item => !item.errorMsg && item.progress === 100)
  534. if (validFiles.length === 0) {
  535. this.btnLoading = false
  536. this.showMessage('无有效分片上传完成的文件!', 'error')
  537. return
  538. }
  539. this.totalMergeStartTime = new Date().getTime()
  540. console.log(`【整体合并】所有文件分片上传完成,开始合并,合并开始时间:${this.formatTime(this.totalMergeStartTime)}`)
  541. const nowDate = getCurrentTime()
  542. validFiles.forEach(fileItem => {
  543. fileItem.merging = true
  544. fileItem.mergeStartTime = new Date().getTime()
  545. console.log(`【文件${fileItem.file.name}】合并开始时间:${this.formatTime(fileItem.mergeStartTime)}`)
  546. })
  547. try {
  548. const processFiles = validFiles.map(async(fileItem) => {
  549. const file = fileItem.file
  550. const json = {}
  551. const jsonArray = []
  552. const jsonString = {}
  553. // 获取图片分辨率
  554. if (file.type.startsWith('image')) {
  555. const fileBase64 = await this.getBase64(file)
  556. const imgRes = await this.getImgPx(fileBase64)
  557. jsonString.file_dpi = `${imgRes.width}px*${imgRes.height}px`
  558. } else {
  559. jsonString.file_dpi = ''
  560. }
  561. // 构建文件信息
  562. jsonString.file_name = file.name
  563. jsonString.file_size = file.size
  564. jsonString.file_type = file.name.split('.').pop() || ''
  565. jsonString.last_modified = file.lastModified
  566. jsonString.file_path = ''
  567. jsonString.sequence = null
  568. jsonString.archive_id = this.arcId
  569. jsonString.create_time = nowDate
  570. jsonString.id = null
  571. jsonString.file_thumbnail = ''
  572. jsonArray.push(jsonString)
  573. // 校验分片完整性
  574. const totalChunks = Math.ceil(file.size / this.CHUNK_SIZE)
  575. const chunksExist = await this.checkAllChunksExist(fileItem.md5, totalChunks)
  576. if (!chunksExist) {
  577. throw new Error(`${file.name}】部分分片未上传完成,无法合并`)
  578. }
  579. // 构建合并参数
  580. json.categoryId = this.selectedCategory.id
  581. json.archivesId = this.arcId
  582. json.identifier = fileItem.md5
  583. json.filename = file.name
  584. json.totalChunks = totalChunks
  585. json.totalSize = file.size
  586. json.fileJsonString = JSON.stringify(jsonArray)
  587. return json
  588. })
  589. const jsonArray = await Promise.all(processFiles)
  590. // 调用合并接口
  591. const linkSrc = process.env.NODE_ENV === 'production' ? window.g.ApiUrl : process.env.VUE_APP_BASE_API
  592. const response = await axios.post(`${linkSrc}/api/collect/merge`, jsonArray, {
  593. headers: {
  594. 'Authorization': getToken(),
  595. 'Content-Type': 'application/json'
  596. }
  597. })
  598. this.totalMergeEndTime = new Date().getTime()
  599. const totalMergeDuration = this.getTimeDiff(this.totalMergeStartTime, this.totalMergeEndTime)
  600. if (response.data.code === 200) {
  601. // 处理目录上传逻辑
  602. if (this.isCatalogUpload && response.data.data.length === 1 && response.data.data[0] !== '') {
  603. // 调用目录上传接口
  604. catalogUpload(`${linkSrc}/api/collect/catalogUpload`,
  605. response.data.data[0],
  606. this.selectedCategory.fondsId
  607. ).then(res => {
  608. this.btnLoading = false
  609. if (res.data.code === 200) {
  610. this.resultCatalog = res.data.data
  611. if (this.resultCatalog.mountFile.total === this.resultCatalog.mountFile.successNum) {
  612. this.showMessage('目录上传操作成功', 'success')
  613. this.uploadMinioVisible = false
  614. this.fileList = []
  615. this.$emit('close-dialog')
  616. } else {
  617. this.catalogInfoData = []
  618. this.resultCatalog.failArchives.forEach(item => {
  619. const parts = item.split(':')
  620. if (parts.length === 2) {
  621. const field = parts[0]
  622. let fileStr = parts[1]
  623. fileStr = fileStr.replace(/\[|\]/g, '')
  624. const fileArray = fileStr.split(',').map(file => file.trim())
  625. const match = field.match(/^([\w-·]+)(.*)$/)
  626. let archives = ''
  627. let description = ''
  628. if (match) {
  629. archives = match[1]
  630. description = match[2]
  631. }
  632. this.catalogInfoData.push({
  633. archives,
  634. description,
  635. children: fileArray
  636. })
  637. }
  638. })
  639. this.catalogErrorVisible = true
  640. this.$emit('close-dialog')
  641. }
  642. } else {
  643. this.showMessage(`目录上传失败: ${res.data.message}`, 'error')
  644. }
  645. })
  646. } else {
  647. // 普通文件上传成功
  648. this.showMessage('所有文件上传并合并成功', 'success')
  649. validFiles.forEach((fileItem) => {
  650. fileItem.mergeEndTime = new Date().getTime()
  651. const mergeDuration = this.getTimeDiff(fileItem.mergeStartTime, fileItem.mergeEndTime)
  652. console.log(`【文件${fileItem.file.name}】合并结束时间:${this.formatTime(fileItem.mergeEndTime)},合并耗时:${mergeDuration}`)
  653. fileItem.successMsg = '上传成功!'
  654. fileItem.merging = false
  655. })
  656. console.log(`【整体合并】所有文件合并完成,整体合并耗时:${totalMergeDuration}`)
  657. this.$emit('onUploadSuccess', response.data.data, validFiles.map(f => f.file.name), jsonArray)
  658. this.uploadMinioVisible = false
  659. this.fileList = []
  660. this.$emit('close-dialog')
  661. }
  662. } else {
  663. throw new Error(response.data.msg || '合并失败')
  664. }
  665. } catch (err) {
  666. this.btnLoading = false
  667. this.totalMergeEndTime = new Date().getTime()
  668. const totalMergeDuration = this.getTimeDiff(this.totalMergeStartTime, this.totalMergeEndTime)
  669. console.log(`【整体合并】合并失败,耗时:${totalMergeDuration},异常信息:`, err)
  670. this.showMessage(`文件合并失败: ${err.message}`, 'error')
  671. validFiles.forEach(fileItem => {
  672. fileItem.merging = false
  673. fileItem.errorMsg = fileItem.errorMsg || `合并失败: ${err.message}`
  674. })
  675. this.$emit('onUploadError', err)
  676. } finally {
  677. this.resetUploadState()
  678. }
  679. },
  680. /**
  681. * 关闭弹框时清空文件列表
  682. */
  683. handleCloseDialog() {
  684. this.uploadMinioVisible = false
  685. this.fileList = []
  686. this.resetUploadState()
  687. this.repeatFileData = []
  688. this.tempSelectedFiles = null
  689. }
  690. }
  691. }
  692. </script>
  693. <style scoped>
  694. .upload-minio {
  695. position: relative;
  696. margin-top: 10px;
  697. }
  698. .uploader-drop{
  699. display: flex;
  700. flex-direction: column;
  701. justify-content: center;
  702. text-align: center;
  703. height: 180px;
  704. border: none;
  705. background-color: #f5f5f5;
  706. .uploader-btn{
  707. border: none;
  708. i{
  709. font-size: 32px;
  710. color: #1F55EB;
  711. }
  712. &:hover{
  713. background-color: transparent;
  714. }
  715. }
  716. .el-upload__tip{
  717. font-size: 12px;
  718. color: #A6ADB6;
  719. }
  720. }
  721. .file-input {
  722. position: absolute;
  723. left: 0;
  724. top: 0;
  725. width: 100px;
  726. height: 36px;
  727. padding: 5px;
  728. opacity: 0;
  729. cursor: pointer;
  730. z-index: 10;
  731. }
  732. .file-item {
  733. width: 100%;
  734. border: 1px dashed #409eff;
  735. padding: 10px;
  736. border-radius: 4px;
  737. margin-bottom: 10px;
  738. }
  739. .file-name {
  740. position: relative;
  741. font-weight: 500;
  742. color: #333;
  743. margin-bottom: 8px;
  744. }
  745. .icon-shanchu{
  746. position: absolute;
  747. right: -7px;
  748. top: 0;
  749. font-size: 20px;
  750. color: #1F55EB;
  751. cursor: pointer;
  752. &:hover {
  753. color: #ff4444;
  754. transform: scale(1.1);
  755. transition: all 0.2s ease;
  756. }
  757. }
  758. .progress-wrapper {
  759. display: flex;
  760. flex-direction: column;
  761. gap: 5px;
  762. }
  763. .progress-bar {
  764. height: 10px;
  765. background-color: #42b983;
  766. transition: width 0.3s ease;
  767. border-radius: 10px;
  768. }
  769. .progress-text {
  770. font-size: 14px;
  771. color: #666;
  772. }
  773. .merge-loading {
  774. color: #1890ff;
  775. font-size: 14px;
  776. }
  777. .success {
  778. color: #00C851;
  779. font-size: 14px;
  780. margin: 5px 0 0 0;
  781. }
  782. .error {
  783. color: #ff4444;
  784. font-size: 14px;
  785. margin: 5px 0 0 0;
  786. }
  787. .minio-file{
  788. .el-dialog{
  789. .el-dialog__body{
  790. padding: 15px 0 30px 0 !important;
  791. }
  792. }
  793. }
  794. .file-size {
  795. color: #666;
  796. font-weight: normal;
  797. font-size: 12px;
  798. margin-left: 8px;
  799. }
  800. /* 重复文件弹窗样式 */
  801. .collectUpload-dialog .file-list {
  802. display: flex;
  803. align-items: center;
  804. gap: 8px;
  805. }
  806. /* 目录上传失败弹窗样式 */
  807. .catalog-dialog .archives-table {
  808. --el-table-header-text-color: #666;
  809. --el-table-row-hover-bg-color: #f5f7fa;
  810. }
  811. </style>