Browse Source

业务名称判重

master
wenlele 2 years ago
parent
commit
2521366d50
  1. 12
      web/client/src/sections/safetySpecification/containers/specificationLibrary.js
  2. 2
      web/package.json
  3. 60
      web/routes/attachment/index.js

12
web/client/src/sections/safetySpecification/containers/specificationLibrary.js

@ -10,7 +10,8 @@ const { Search } = Input;
import { CreditCardFilled, FilePdfOutlined } from '@ant-design/icons'; import { CreditCardFilled, FilePdfOutlined } from '@ant-design/icons';
import { agent } from 'superagent'; import { agent } from 'superagent';
const CheckboxGroup = Checkbox.Group; const CheckboxGroup = Checkbox.Group;
import JSZip from 'jszip'
import { savAes } from 'file-saver'
function SpecificationLibrary ({ loading, clientHeight, actions, dispatch, }) { function SpecificationLibrary ({ loading, clientHeight, actions, dispatch, }) {
@ -40,6 +41,7 @@ function SpecificationLibrary ({ loading, clientHeight, actions, dispatch, }) {
}) })
} }
return <> return <>
<div style={{ display: 'flex', justifyContent: 'space-between', marginBottom: 20 }}> <div style={{ display: 'flex', justifyContent: 'space-between', marginBottom: 20 }}>
@ -58,7 +60,13 @@ function SpecificationLibrary ({ loading, clientHeight, actions, dispatch, }) {
<Button type="primary" onClick={() => { <Button type="primary" onClick={() => {
setFileModal(true) setFileModal(true)
}}>上传</Button> }}>上传</Button>
<Button type="primary">下载</Button> <Button type="primary" onClick={() => {
// let fileUrlList = fileData?.data?.filter(d => fileId.current.includes(d.id))?.map(s => s.path)
// RouteRequest.post(RouteTable.packBulk, { fileUrl: fileUrlList });
}}>下载</Button>
<Button type="primary" onClick={() => { <Button type="primary" onClick={() => {
if (fileId.current?.length) { if (fileId.current?.length) {
dispatch(safetySpecification.delSpecifications(fileId.current)).then(res => { dispatch(safetySpecification.delSpecifications(fileId.current)).then(res => {

2
web/package.json

@ -82,11 +82,13 @@
"file-saver": "^2.0.5", "file-saver": "^2.0.5",
"fs-attachment": "^1.0.0", "fs-attachment": "^1.0.0",
"fs-web-server-scaffold": "^1.0.6", "fs-web-server-scaffold": "^1.0.6",
"jszip": "^3.10.1",
"koa-better-http-proxy": "^0.2.5", "koa-better-http-proxy": "^0.2.5",
"koa-proxy": "^1.0.0-alpha.3", "koa-proxy": "^1.0.0-alpha.3",
"koa-view": "^2.1.4", "koa-view": "^2.1.4",
"moment": "^2.22.0", "moment": "^2.22.0",
"npm": "^7.20.6", "npm": "^7.20.6",
"path": "^0.12.7",
"react-router-breadcrumbs-hoc": "^4.0.1", "react-router-breadcrumbs-hoc": "^4.0.1",
"simplebar-react": "^3.2.4", "simplebar-react": "^3.2.4",
"superagent": "^6.1.0", "superagent": "^6.1.0",

60
web/routes/attachment/index.js

@ -5,6 +5,7 @@ const path = require('path')
const fs = require('fs'); const fs = require('fs');
const OSS = require('ali-oss'); const OSS = require('ali-oss');
const uuid = require('uuid'); const uuid = require('uuid');
const JSZip = require('jszip');
const UploadPath = { const UploadPath = {
project: ['.txt', '.dwg', '.doc', '.docx', '.xls', '.xlsx', ".csv", '.pdf', '.pptx', '.png', '.jpg', '.svg', '.rar', '.zip', '.jpeg', '.mp4'], project: ['.txt', '.dwg', '.doc', '.docx', '.xls', '.xlsx', ".csv", '.pdf', '.pptx', '.png', '.jpg', '.svg', '.rar', '.zip', '.jpeg', '.mp4'],
@ -229,11 +230,70 @@ module.exports = {
} }
} }
const getFileBlob = (url) => {
return new Promise((resolve, reject) => {
let request = new XMLHttpRequest()
request.open("GET", url, true)
request.responseType = "blob"
request.onload = (res) => {
if (res.target.status == 200) {
resolve(res.target.response)
} else {
reject(res)
}
}
request.send()
})
}
const packBulk = async (ctx) => {
console.log(11111,);
try {
const { fileUrl, folderId } = parse(ctx.req)
const zip = new JSZip()
let result = []
let files = []
console.log(22,fileUrl);
fileUrl.map(a => {
let url = path.join(__dirname, '../../', './client', a);
files.push({ url, name: 111 })
})
for (let i in files) {
let promise = getFileBlob(files[i].url).then((res) => {
let format = files[i].url.substring(files[i].url.lastIndexOf("."), files[i].url.length)
zip.file(files[i].name + format, res, { binary: true })
})
result.push(promise)
console.log(77, promise);
}
console.log(33,);
Promise.all(result).then(() => {
zip.generateAsync({ type: "blob" }).then((res) => {
console.log(55,);
saveAs(res, `${111}.zip`)
})
})
console.log(44,);
ctx.status = 200;
ctx.body = {};
} catch (error) {
ctx.status = 400;
ctx.fs.logger.error(error);
ctx.body = { err: 'download error.' };
}
}
router.use(download_); router.use(download_);
router.post('/_upload/new', upload); router.post('/_upload/new', upload);
router.delete('/_upload/cleanup', remove); router.delete('/_upload/cleanup', remove);
router.post('/_upload/attachments/ali/:p', uploadAliOSS); router.post('/_upload/attachments/ali/:p', uploadAliOSS);
router.get('/_download/attachments/ali', downloadFromAli); router.get('/_download/attachments/ali', downloadFromAli);
router.post('/_upload/attachments/:p', upload_); router.post('/_upload/attachments/:p', upload_);
router.post('/packBulk/:p', packBulk);
} }
}; };

Loading…
Cancel
Save