diff --git a/web/client/src/sections/projectRegime/containers/qrCode.js b/web/client/src/sections/projectRegime/containers/qrCode.js index 8fa9b90..57b1a71 100644 --- a/web/client/src/sections/projectRegime/containers/qrCode.js +++ b/web/client/src/sections/projectRegime/containers/qrCode.js @@ -1,6 +1,7 @@ import React, { useEffect, useState } from 'react'; import { connect } from 'react-redux'; -import { Form, Input, Select, Button } from 'antd'; +import { Form, Input, Select, Button, message } from 'antd'; +import JSZip from 'jszip'; import './qrCode.less'; const QrCode = (props) => { @@ -8,6 +9,7 @@ const QrCode = (props) => { const { projectRegime } = actions const [firmList, setFirmList] = useState([]) const [tableList, settableList] = useState([]) + const [downloading, setDownloading] = useState(false) useEffect(() => { dispatch(projectRegime.getProjectList({ justStructure: true })).then(res => { @@ -33,6 +35,44 @@ const QrCode = (props) => { img.onerror = null; } + const batchDownload = () => { + setDownloading(true) + let promiseArr = [], nameArr = [] + tableList.forEach(l => { + promiseArr.push( + window.fetch(`/_file-server/${l.qrCode}`, { + method: 'get', + headers: { + "Accept": "application/json", + "Content-Type": "application/json", + "X-Requested-With": "XMLHttpRequest", + }, + }) + ) + nameArr.push(l.name + '.jpeg') + }) + try { + Promise.all(promiseArr).then(async resArr => { + const zip = new JSZip() + for (let i = 0; i < resArr.length; i++) { + const response = resArr[i] + const blob = await response.blob() + zip.file(nameArr[i], blob) + } + zip.generateAsync({ type: "blob" }).then(blob => { + const url = window.URL.createObjectURL(blob) + downloadFile(url, "点位二维码.zip") + setDownloading(false) + message.success('下载成功') + }); + }) + } catch (error) { + console.log(error) + setDownloading(false) + message.error('下载失败') + } + } + return (