This commit is contained in:
		
							parent
							
								
									189ca09a15
								
							
						
					
					
						commit
						c56658ac64
					
				| 
						 | 
					@ -208,6 +208,7 @@ import {
 | 
				
			||||||
  getVideoDeviceDetail,
 | 
					  getVideoDeviceDetail,
 | 
				
			||||||
  qrCodeDownZip,
 | 
					  qrCodeDownZip,
 | 
				
			||||||
} from '@/api/deviceManagement'
 | 
					} from '@/api/deviceManagement'
 | 
				
			||||||
 | 
					import { downloadFile } from '@/utils/download'
 | 
				
			||||||
 | 
					
 | 
				
			||||||
export default {
 | 
					export default {
 | 
				
			||||||
  components: {
 | 
					  components: {
 | 
				
			||||||
| 
						 | 
					@ -339,41 +340,14 @@ export default {
 | 
				
			||||||
    async handleQrCode() {
 | 
					    async handleQrCode() {
 | 
				
			||||||
      console.log('下载二维码')
 | 
					      console.log('下载二维码')
 | 
				
			||||||
      const params = { ...this.queryParams }
 | 
					      const params = { ...this.queryParams }
 | 
				
			||||||
      // const url = '/smart-site/video_equipment/downZip?pageNum'
 | 
					 | 
				
			||||||
      // const url = 'http://192.168.0.58:38080/smart-site/video_equipment/downZip?pageNum' + this.queryParams.pageNum + '&pageSize=' + this.queryParams.pageSize
 | 
					 | 
				
			||||||
      // const fileName = `二维码_${new Date().getTime()}.zip`
 | 
					 | 
				
			||||||
      // this.downLoadFile(url, fileName, null)
 | 
					 | 
				
			||||||
      // const res = await qrCodeDownZip(params)
 | 
					 | 
				
			||||||
      // console.log('🚀 ~ 下载二维码 ~ res:', res)
 | 
					 | 
				
			||||||
      try {
 | 
					      try {
 | 
				
			||||||
        const response = await qrCodeDownZip(params)
 | 
					        const res = await qrCodeDownZip(params)
 | 
				
			||||||
        console.log('🚀 ~ handleQrCode ~ response:', response)
 | 
					        console.log('🚀 ~ handleQrCode ~ res:', res)
 | 
				
			||||||
        // const blob = new Blob([response], { type: 'application/octet-stream' })
 | 
					        downloadFile({
 | 
				
			||||||
        // const url = window.URL.createObjectURL(blob)
 | 
					          fileName: `二维码_${new Date().getTime()}.zip`,
 | 
				
			||||||
        // const link = document.createElement('a')
 | 
					          fileData: res,
 | 
				
			||||||
        // link.href = url
 | 
					          fileType: 'application/zip;charset=utf-8',
 | 
				
			||||||
        // link.setAttribute('download', `二维码_${new Date().getTime()}.zip`)
 | 
					        })
 | 
				
			||||||
        // document.body.appendChild(link)
 | 
					 | 
				
			||||||
        // link.click()
 | 
					 | 
				
			||||||
        // link.remove()
 | 
					 | 
				
			||||||
        // window.URL.revokeObjectURL(url)
 | 
					 | 
				
			||||||
        // 检查响应类型,确保是 Blob 或 ArrayBuffer
 | 
					 | 
				
			||||||
        const blob = new Blob([response.data], { type: 'application/octet-stream' })
 | 
					 | 
				
			||||||
        console.log('🚀 ~ handleQrCode ~ blob:', blob)
 | 
					 | 
				
			||||||
        // 创建下载链接
 | 
					 | 
				
			||||||
        const url = window.URL.createObjectURL(blob)
 | 
					 | 
				
			||||||
        // 创建一个隐藏的 <a> 标签进行下载
 | 
					 | 
				
			||||||
        const a = document.createElement('a')
 | 
					 | 
				
			||||||
        a.href = url
 | 
					 | 
				
			||||||
        a.download = `二维码_${new Date().getTime()}.zip` // 设置下载的文件名
 | 
					 | 
				
			||||||
        document.body.appendChild(a)
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        // 触发点击事件下载文件
 | 
					 | 
				
			||||||
        a.click()
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        // 释放 URL 对象,防止内存泄漏
 | 
					 | 
				
			||||||
        window.URL.revokeObjectURL(url)
 | 
					 | 
				
			||||||
        document.body.removeChild(a)
 | 
					 | 
				
			||||||
      } catch (error) {
 | 
					      } catch (error) {
 | 
				
			||||||
        console.error('下载二维码失败:', error)
 | 
					        console.error('下载二维码失败:', error)
 | 
				
			||||||
      }
 | 
					      }
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in New Issue