Browse Source

文件元数据新建、编辑功能暂交

master
zmh 2 years ago
parent
commit
4d98ee270d
  1. 24
      api/app/lib/controllers/latestMetadata/index.js
  2. 2
      api/app/lib/models/metadata_file.js
  3. BIN
      web/client/assets/files/common/企业信息化项目组0301-0331月报.docx
  4. 52
      web/client/src/components/UploadLocal/index.js
  5. 6
      web/client/src/sections/metadataManagement/actions/metadata.js
  6. 22
      web/client/src/sections/metadataManagement/components/metadataFileModal.js
  7. 41
      web/client/src/sections/metadataManagement/containers/filesTable.js
  8. 2
      web/routes/attachment/index.js

24
api/app/lib/controllers/latestMetadata/index.js

@ -551,7 +551,7 @@ async function getMetadataResourceApplications(ctx) {
//新建文件元数据
async function postMetadataFiles(ctx) {
try {
const { name, catalog, type, size } = ctx.request.body;
const { name, catalog, type, fileName } = ctx.request.body;
const models = ctx.fs.dc.models;
const postOne = await models.MetadataFile.findOne({
where: { name: name, catalog: catalog }
@ -560,7 +560,7 @@ async function postMetadataFiles(ctx) {
ctx.status = 400;
ctx.body = { message: '该资源目录下元数据名称已存在' }
} else {
if (!name || !catalog || !type) {
if (!name || !catalog || !type || !fileName) {
ctx.body = { message: '参数不全,请重新配置' }
ctx.status = 400;
} else {
@ -582,18 +582,24 @@ async function postMetadataFiles(ctx) {
async function putMetadataFiles(ctx) {
try {
const { id } = ctx.params;
const { updateFileName } = ctx.query;
const { catalog, name } = ctx.request.body;
const models = ctx.fs.dc.models;
let metadataFileInfo = await models.MetadataFile.findOne({ where: { id } });
if (metadataFileInfo) {
const putOne = await models.MetadataFile.findOne({ where: { id: { $not: id }, catalog: catalog, name: name } });
if (putOne) {
ctx.status = 400;
ctx.body = { message: '该元数据名称已存在' }
if (updateFileName) {//编辑时,将文件删除,后又取消,则更新文件名为null
await models.MetadataFile.update({ updateAt: moment(), fileName: null }, { where: { id: id } });
ctx.status = 204;
} else {
await models.MetadataFile.update({ updateAt: moment(), ...ctx.request.body }, { where: { id: id } });
ctx.status = 200;
ctx.body = { message: '修改元数据成功' }
const putOne = await models.MetadataFile.findOne({ where: { id: { $not: id }, catalog: catalog, name: name } });
if (putOne) {
ctx.status = 400;
ctx.body = { message: '该元数据名称已存在' }
} else {
await models.MetadataFile.update({ updateAt: moment(), ...ctx.request.body }, { where: { id: id } });
ctx.status = 200;
ctx.body = { message: '修改元数据成功' }
}
}
} else {
ctx.status = 400;

2
api/app/lib/models/metadata_file.js

@ -116,7 +116,7 @@ module.exports = dc => {
},
fileName: {
type: DataTypes.STRING,
allowNull: false,
allowNull: true,
defaultValue: null,
comment: null,
primaryKey: false,

BIN
web/client/assets/files/common/企业信息化项目组0301-0331月报.docx

Binary file not shown.

52
web/client/src/components/UploadLocal/index.js

@ -7,8 +7,7 @@ import moment from 'moment';
import { PlusOutlined, UploadOutlined, CloseOutlined } from '@ant-design/icons';
import { RouteRequest } from '@peace/utils';
import { RouteTable } from '$utils'
const { confirm } = Modal;
class Uploads extends Component {
constructor(props) {
super(props);
@ -107,6 +106,26 @@ class Uploads extends Component {
RouteRequest.delete(RouteTable.cleanUpUploadTrash, { url: file.url });
};
}
handleOk = (that, file, fileList, curPreviewPic, removeFilesList) => {
let nextFileList = [];
fileList.map((f, i) => {
if (f.uid != file.uid) {
nextFileList.push(f);
}
});
that.deleteFile(file);
let nextRemoveFiles = removeFilesList.concat([file.storageUrl]);
if (curPreviewPic == file.url) {
that.setState({
curPreviewPic: ''
});
}
that.props.onChange(nextFileList);
that.setState({
fileList: nextFileList,
removeFilesList: nextRemoveFiles
});
}
render() {
const UploadPath = {
project: ['txt', 'dwg', 'doc', 'docx', 'xls', 'xlsx', 'pdf', 'png', 'jpg', 'rar', 'zip'],
@ -137,7 +156,8 @@ class Uploads extends Component {
onChange,
value,
showUploadList,
onStateChange
onStateChange,
addNew
} = this.props;
const { fileList, curPreviewPic, delPicIng, removeFilesList } = this.state;
const that = this;
@ -225,24 +245,18 @@ class Uploads extends Component {
}
},
onRemove(file) {
let nextFileList = [];
fileList.map((f, i) => {
if (f.uid != file.uid) {
nextFileList.push(f);
}
});
that.deleteFile(file);
let nextRemoveFiles = removeFilesList.concat([file.storageUrl]);
if (curPreviewPic == file.url) {
that.setState({
curPreviewPic: ''
// if (confirm('请确认是否删除此文件?删除后将不可恢复!') === true) {
if (addNew) {
that.handleOk(that, file, fileList, curPreviewPic, removeFilesList);
} else {
confirm({
title: '请确认是否删除此文件?删除后将不可恢复!',
onOk() {
that.handleOk(that, file, fileList, curPreviewPic, removeFilesList);
},
onCancel() { },
});
}
onChange(nextFileList);
that.setState({
fileList: nextFileList,
removeFilesList: nextRemoveFiles
});
},
onPreview(file) {
let filePostfix = file.url.split('.').pop();

6
web/client/src/sections/metadataManagement/actions/metadata.js

@ -207,15 +207,15 @@ export function postMetadataFiles(data) {
});
}
export function putMetadataFiles(id, data) {
export function putMetadataFiles(id, data, updateFileName) {
return dispatch => basicAction({
type: 'put',
data: data,
dispatch,
actionType: 'PUT_METADATA_FILES',
url: ApiTable.putMetadataFiles.replace('{id}', id),
url: ApiTable.putMetadataFiles.replace('{id}', id) + `?updateFileName=${updateFileName || ''}`,
msg: {
option: '修改元数据',
option: updateFileName ? '' : '修改元数据',
}
});
}

22
web/client/src/sections/metadataManagement/components/metadataFileModal.js

@ -1,5 +1,5 @@
import React, { useEffect, useState } from 'react';
import { Modal, Input, Form, Select, InputNumber, Tooltip, Tag } from 'antd';
import { Modal, Input, Form, Select, InputNumber, Tooltip, Tag, message } from 'antd';
import { UploadLocal } from '$components';
const { TextArea } = Input;
const MetadataFileModal = (props) => {
@ -48,10 +48,11 @@ const MetadataFileModal = (props) => {
} else if (m.control === '数字输入框') {
const rules = [{ required: !m.nullable, message: `${m.attributeName}不可空` }]
let maxValue = '';
if (m.length) {
while (m.length > 0) {
let length = m.length;
if (length) {
while (length > 0) {
maxValue += '9'
m.length--;
length--;
}
}
return <Form.Item
@ -110,6 +111,18 @@ const MetadataFileModal = (props) => {
} else {
onCancel(null);
}
} else {
if (!(form.getFieldValue('files') && form.getFieldValue('files').length)) {
message.warning('文件已被删除,可重新编辑上传');
onCancel(null, editData.record.id);
} else {
if (!editData.record.files.length) {
message.warning('文件需确定提交,才进行入库存储');
onCancel(form.getFieldValue('files')[0]);
} else {
onCancel(null);
}
}
}
}
return (
@ -138,6 +151,7 @@ const MetadataFileModal = (props) => {
name='files'
rules={[{ required: true, message: '文件不可为空' }]}>
<UploadLocal
addNew={editData.add || !editData.record.files.length}
isLocal={true}
maxFilesNum={1}
maxFileSize={40}

41
web/client/src/sections/metadataManagement/containers/filesTable.js

@ -57,10 +57,11 @@ const FilesTable = (props) => {
setEditData({
title: '修改文件元数据', record: {
...record, ...record.attributesParam,
files: [{
url: "\\assets\\files\\common\\" + record.name + '.' + record.type, name: record.name
}]
}
files: record.fileName ? [{
url: "\\assets\\files\\common\\" + record.fileName, name: record.fileName.split('_').pop()
}] : []
},
// metadataModels: res.payload.data
});
setModalVisible(true);
}
@ -70,7 +71,7 @@ const FilesTable = (props) => {
dispatch(metadataManagement.delMetadataFiles(record.id)).then(res => {
if (res.success) {
onSearch(); setModalVisible(false);
deleteFile({ url: "\\assets\\files\\common\\" + record.name + '.' + record.type })
deleteFile({ url: "\\assets\\files\\common\\" + record.fileName })
}
});
}
@ -159,7 +160,13 @@ const FilesTable = (props) => {
title: '类型',
dataIndex: 'type',
key: 'type',
width: '10%'
width: '10%',
render: (text, record) => {
if (record.fileName)
return <span>{text}</span>
else
return ''
}
}, {
title: '标签',
dataIndex: 'tags',
@ -175,7 +182,12 @@ const FilesTable = (props) => {
dataIndex: 'size',
key: 'size',
width: '10%',
render: (text) => <span>{getfilesize(text)}</span>
render: (text, record) => {
if (record.fileName)
return <span>{getfilesize(text)}</span>
else
return ''
}
}, {
title: '修改时间',
dataIndex: 'updateAt',
@ -262,6 +274,7 @@ const FilesTable = (props) => {
if (values.files && values.files.length) {
obj.type = values.files[0].name.split('.').pop();
obj.size = values.files[0].size;
obj.fileName = values.files[0].url.split('\\').pop();
}
dispatch(metadataManagement.postMetadataFiles(obj)).then(() => {
onSearch(); setModalVisible(false);
@ -270,7 +283,10 @@ const FilesTable = (props) => {
obj = { catalog: resourceCatalogId, catalogKey: resourceCatalogKey, ...values }
if (values.files && values.files.length) {
obj.type = values.files[0].name.split('.').pop();
obj.size = values.files[0].size;
if (values.files[0].size) {
obj.size = values.files[0].size;
}
obj.fileName = values.files[0].url.split('\\').pop();
}
dispatch(metadataManagement.putMetadataFiles(editData.record.id, obj)).then(res => {
if (res.success) {
@ -345,10 +361,17 @@ const FilesTable = (props) => {
<MetadataFileModal
metadataModels={metadataModels.filter(m => m.modelType === '文件')}
editData={editData}
onCancel={(file) => {
onCancel={(file, updateId) => {
setModalVisible(false)
if (file)
deleteFile(file);
if (updateId) {
dispatch(metadataManagement.putMetadataFiles(updateId, {}, true)).then(res => {
if (res.success) {
onSearch(); setModalVisible(false);
}
});
}
}}
onConfirm={onConfirm} /> : ''
}

2
web/routes/attachment/index.js

@ -90,7 +90,7 @@ module.exports = {
}
const date = new Date().toLocaleDateString();
const time = new Date().getTime();
let fileName = file.filename;
let fileName = time + '_' + file.filename;
let saveFile = path.join(__dirname, '../../', `/client/assets/files/${fileFolder}`, fileName);
const pathUrl = `./client/assets/files/${fileFolder}`;

Loading…
Cancel
Save