Browse Source

上传修改

dev
wenlele 2 years ago
parent
commit
824c234a86
  1. 9
      api/.vscode/launch.json
  2. 22
      api/app/lib/controllers/means/index.js
  3. 3
      api/app/lib/routes/means/index.js
  4. 8
      web/client/src/sections/means/containers/devOpsStandard.jsx
  5. 9
      web/client/src/sections/means/containers/faultInformation.jsx
  6. 8
      web/client/src/sections/means/containers/projectMeans.jsx
  7. 8
      web/client/src/sections/means/containers/repairFQA.jsx
  8. 38
      web/routes/attachment/index.js

9
api/.vscode/launch.json

@ -33,11 +33,12 @@
"--godUrl https://restapi.amap.com/v3",
"--godKey 21c2d970e1646bb9a795900dd00093ce",
"--mqttVideoServer mqtt://10.8.30.71:30883",
"--qnak XuDgkao6cL0HidoMAPnA5OB10Mc_Ew08mpIfRJK5",
"--qnsk yewcieZLzKZuDfig0wLZ9if9jKp2P_1jd3CMJPSa",
"--qnbkt dev-operational-service",
"--qnak 5XrM4wEB9YU6RQwT64sPzzE6cYFKZgssdP5Kj3uu",
"--qnsk w6j2ixR_i-aelc6I7S3HotKIX-ukMzcKmDfH6-M5",
"--qnbkt anxinyun-test",
"--qndmn http://test.resources.anxinyun.cn",
// "--qndmn http://resources.anxinyun.cn",
"--qndmn http://rhvqdivo5.hn-bkt.clouddn.com",
// "--qndmn http://rhvqdivo5.hn-bkt.clouddn.com",
// click
// "--clickHouseUrl http://10.8.30.71",
// click

22
api/app/lib/controllers/means/index.js

@ -154,6 +154,25 @@ async function delfolderFile (ctx, next) {
}
}
}
async function upload (ctx, next) {
let fkey = null;
try {
const { files } = await parse(ctx.req);
const file = files[0];
const fileInfo = await ctx.app.fs.attachment.upload(file);
fkey = fileInfo.key;
ctx.status = 200;
ctx.body = { uploaded: fkey };
} catch (err) {
ctx.fs.logger.error(`path: ${ctx.path}, error: ${error}`)
ctx.status = 400;
ctx.body = {
"message": '上传失败'
}
}
}
module.exports = {
@ -162,5 +181,6 @@ module.exports = {
delFile,
addFile,
folderFileList,
delfolderFile
delfolderFile,
upload
}

3
api/app/lib/routes/means/index.js

@ -21,4 +21,7 @@ module.exports = function (app, router, opts) {
app.fs.api.logAttr['DEL/file/:id'] = { content: '删除文件夹', visible: true };
router.del('/file/:id', means.delfolderFile);
app.fs.api.logAttr['POSTattachments/:p'] = { content: '上传文件', visible: true };
router.post('/attachments/:p', means.upload);
};

8
web/client/src/sections/means/containers/devOpsStandard.jsx

@ -10,7 +10,7 @@ import './style.less'
const Rest = (props) => {
const { dispatch, actions, user, qiniu, loading, clientHeight, overallProjectId } = props
const { dispatch, actions, user, qiniu, loading, clientHeight, overallProjectId, apiRoot } = props
const { install, means } = actions
const [pomsList, setPomsList] = useState([]); //
const [showPomsList, setShowPomsList] = useState([]); //
@ -392,7 +392,7 @@ const Rest = (props) => {
<div style={{ marginTop: 6 }}>文件<span style={{ color: 'red' }}>*</span></div>
<Upload
style={{ display: 'inline-block' }}
action="/_upload/attachments"
action={`${apiRoot}/attachments/p`}
accept={'.txt, .doc, .docx, .xls, .xlsx, .pdf, .png, .jpg, .rar, .zip'}
limit={1}
maxSize={51200}
@ -400,7 +400,6 @@ const Rest = (props) => {
setUploadData({})
}}
onSuccess={(responseBody, file) => {
setUploadData({
name: file.name,
size: file.size,
@ -559,7 +558,8 @@ function mapStateToProps (state) {
overallProjectId: global.pepProjectId,
// socket: webSocket.socket
clientHeight: global.clientHeight,
qiniu: global.qiniu?.domain
qiniu: global.qiniu?.domain,
apiRoot: global.apiRoot
};
}

9
web/client/src/sections/means/containers/faultInformation.jsx

@ -10,7 +10,7 @@ import './style.less'
const Rest = (props) => {
const { dispatch, actions, user, qiniu, loading, clientHeight, overallProjectId } = props
const { dispatch, actions, user, qiniu, loading, clientHeight, overallProjectId ,apiRoot} = props
const { install, means } = actions
const [pomsList, setPomsList] = useState([]); //
const [showPomsList, setShowPomsList] = useState([]); //
@ -86,6 +86,7 @@ const Rest = (props) => {
}, [fileId])
const fileList = (id) => {
dispatch(means.fileList({ projectId: id, type: 3 })).then((res => {
if (res.success) {
let data = res.payload.data
@ -391,7 +392,7 @@ const Rest = (props) => {
<div style={{ marginTop: 6 }}>文件<span style={{ color: 'red' }}>*</span></div>
<Upload
style={{ display: 'inline-block' }}
action="/_upload/attachments"
action={`${apiRoot}/attachments/p`}
accept={'.txt, .doc, .docx, .xls, .xlsx, .pdf, .png, .jpg, .rar, .zip'}
limit={1}
maxSize={51200}
@ -399,7 +400,6 @@ const Rest = (props) => {
setUploadData({})
}}
onSuccess={(responseBody, file) => {
setUploadData({
name: file.name,
size: file.size,
@ -558,7 +558,8 @@ function mapStateToProps (state) {
overallProjectId: global.pepProjectId,
// socket: webSocket.socket
clientHeight: global.clientHeight,
qiniu: global.qiniu?.domain
qiniu: global.qiniu?.domain,
apiRoot:global.apiRoot
};
}

8
web/client/src/sections/means/containers/projectMeans.jsx

@ -10,7 +10,7 @@ import './style.less'
const Rest = (props) => {
const { dispatch, actions, user, qiniu, loading, clientHeight, overallProjectId } = props
const { dispatch, actions, user, qiniu, loading, clientHeight, overallProjectId ,apiRoot} = props
const { install, means } = actions
const [pomsList, setPomsList] = useState([]); //
const [showPomsList, setShowPomsList] = useState([]); //
@ -392,7 +392,7 @@ const Rest = (props) => {
<div style={{ marginTop: 6 }}>文件<span style={{ color: 'red' }}>*</span></div>
<Upload
style={{ display: 'inline-block' }}
action="/_upload/attachments"
action={`${apiRoot}/attachments/p`}
accept={'.txt, .doc, .docx, .xls, .xlsx, .pdf, .png, .jpg, .rar, .zip'}
limit={1}
maxSize={51200}
@ -400,7 +400,6 @@ const Rest = (props) => {
setUploadData({})
}}
onSuccess={(responseBody, file) => {
setUploadData({
name: file.name,
size: file.size,
@ -559,7 +558,8 @@ function mapStateToProps (state) {
overallProjectId: global.pepProjectId,
// socket: webSocket.socket
clientHeight: global.clientHeight,
qiniu: global.qiniu?.domain
qiniu: global.qiniu?.domain,
apiRoot:global.apiRoot
};
}

8
web/client/src/sections/means/containers/repairFQA.jsx

@ -10,7 +10,7 @@ import './style.less'
const Rest = (props) => {
const { dispatch, actions, user, qiniu, loading, clientHeight, overallProjectId } = props
const { dispatch, actions, user, qiniu, loading, clientHeight, overallProjectId ,apiRoot} = props
const { install, means } = actions
const [pomsList, setPomsList] = useState([]); //
const [showPomsList, setShowPomsList] = useState([]); //
@ -392,7 +392,7 @@ const Rest = (props) => {
<div style={{ marginTop: 6 }}>文件<span style={{ color: 'red' }}>*</span></div>
<Upload
style={{ display: 'inline-block' }}
action="/_upload/attachments"
action={`${apiRoot}/attachments/p`}
accept={'.txt, .doc, .docx, .xls, .xlsx, .pdf, .png, .jpg, .rar, .zip'}
limit={1}
maxSize={51200}
@ -400,7 +400,6 @@ const Rest = (props) => {
setUploadData({})
}}
onSuccess={(responseBody, file) => {
setUploadData({
name: file.name,
size: file.size,
@ -559,7 +558,8 @@ function mapStateToProps (state) {
overallProjectId: global.pepProjectId,
// socket: webSocket.socket
clientHeight: global.clientHeight,
qiniu: global.qiniu?.domain
qiniu: global.qiniu?.domain,
apiRoot:global.apiRoot
};
}

38
web/routes/attachment/index.js

@ -19,7 +19,7 @@ module.exports = {
entry: function (app, router, opts) {
const getApiRoot = async function (ctx) {
const { apiUrl, iotVcmpWeb, pomsMonitor, dcWeb,qiniu } = opts;
const { apiUrl, iotVcmpWeb, pomsMonitor, dcWeb, qiniu } = opts;
ctx.status = 200;
ctx.body = {
@ -27,7 +27,7 @@ module.exports = {
iotVcmpWeb: iotVcmpWeb,
pomsMonitor: pomsMonitor,
dcWeb: dcWeb,
qiniu:qiniu
qiniu: qiniu
};
};
@ -53,32 +53,18 @@ module.exports = {
let upload_ = async function (ctx, next) {
let fkey = null;
try {
// const { p } = ctx.params;
console.log(111,ctx);
const { files } = await parse(ctx.req);
// console.log(files);
const file = files[0];
// const extname = path.extname(file.filename).toLowerCase();
// if (!UploadPath[p]) {
// ctx.status = 400;
// ctx.body = JSON.stringify({ error: '附件存放的文件夹名称无效' });
// return;
// } else if (UploadPath[p].indexOf(extname) < 0) {
// ctx.status = 400;
// ctx.body = JSON.stringify({ error: '文件格式无效' });
// return;
// } else {
const fileInfo = await ctx.app.fs.attachment.upload(file);
fkey = fileInfo.key;
console.log(11,fileInfo);
ctx.body = { uploaded: fkey };
// }
const { files } = await parse(ctx.req);
const file = files[0];
const fileInfo = await ctx.app.fs.attachment.upload(file);
fkey = fileInfo.key;
ctx.body = { uploaded: fkey };
} catch (err) {
ctx.status = 500;
ctx.fs.logger.error(err);
ctx.body = { err: 'upload error.' };
ctx.status = 500;
ctx.fs.logger.error(err);
ctx.body = { err: 'upload error.' };
}
}
}
router.use(download);
router.get('/api/root', getApiRoot);

Loading…
Cancel
Save