2024-09-23 15:52:06 +08:00
|
|
|
|
import React, { useEffect, useState, useMemo, useRef } from 'react';
|
|
|
|
|
|
import { Form, Button, Input, Row, Upload, Col, Table, DatePicker, InputNumber, message, Image, Modal, Typography, Select } from 'antd';
|
|
|
|
|
|
import { DeleteOutlined, FileWordOutlined, FilePdfOutlined, FileZipOutlined, FileExcelOutlined } from '@ant-design/icons';
|
|
|
|
|
|
import { formItemLayout, btnItemLayout } from '../../../components/crud/FormLayoutProps';
|
|
|
|
|
|
|
|
|
|
|
|
import apiurl from '../../../service/apiurl';
|
|
|
|
|
|
|
|
|
|
|
|
import NormalSelect from '../../../components/Form/NormalSelect';
|
|
|
|
|
|
|
|
|
|
|
|
// import "./index.less"
|
|
|
|
|
|
import moment from 'moment';
|
|
|
|
|
|
const { RangePicker } = DatePicker
|
|
|
|
|
|
const { Dragger } = Upload;
|
|
|
|
|
|
const url = "http://223.75.53.141:9102/test.by-lyf.tmp"
|
|
|
|
|
|
|
|
|
|
|
|
const opntios=[
|
2024-09-26 17:59:26 +08:00
|
|
|
|
{value:0,label:'党支部工作制度'},
|
|
|
|
|
|
{value:1,label:'行政工作制度'},
|
|
|
|
|
|
{value:2,label:'部门工作制度'},
|
|
|
|
|
|
{value:3,label:'安全管理制度'},
|
|
|
|
|
|
{value:4,label:'工程管理制度'},
|
|
|
|
|
|
{value:5,label:'技术规程'},
|
|
|
|
|
|
{value:6,label:'岗位责任制'}
|
2024-09-23 15:52:06 +08:00
|
|
|
|
]
|
|
|
|
|
|
const ModalForm = ({ mode, record, onEdit, onSave, onSimilarSave }) => {
|
|
|
|
|
|
|
|
|
|
|
|
const [form] = Form.useForm();
|
|
|
|
|
|
const [fileList, setFileList] = useState([]) //上传文件列表
|
|
|
|
|
|
const [fileIds, setFileIds] = useState([])
|
|
|
|
|
|
const [iframeSrc, setIframeSrc] = useState('')
|
|
|
|
|
|
const [pdfViewOPen, setPdfViewOPen] = useState(false)
|
|
|
|
|
|
|
|
|
|
|
|
const [loading, setLoading] = useState(false)
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* @description 文件下载
|
|
|
|
|
|
* @param {String} params 文件fileId
|
|
|
|
|
|
*/
|
|
|
|
|
|
const download = (params) => {
|
|
|
|
|
|
let downloadLink = document.createElement("a");
|
2024-09-26 17:59:26 +08:00
|
|
|
|
downloadLink.href = `http://local.gunshiiot.com:18083/gunshiApp/tsg/projectEvents/file/download/${params}`;
|
2024-09-23 15:52:06 +08:00
|
|
|
|
downloadLink.download = `${params.fileName}`;
|
|
|
|
|
|
downloadLink.style.display = "none";
|
|
|
|
|
|
// 将链接添加到页面中
|
|
|
|
|
|
document.body.appendChild(downloadLink);
|
|
|
|
|
|
|
|
|
|
|
|
// 模拟点击事件,开始下载
|
|
|
|
|
|
downloadLink.click();
|
|
|
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
|
|
|
* @description 上传图片
|
|
|
|
|
|
* @param {string} file 上传的文件
|
|
|
|
|
|
*/
|
|
|
|
|
|
const fileChange = (info) => {
|
|
|
|
|
|
if (info.file.status === "done") {
|
|
|
|
|
|
setLoading(false);
|
|
|
|
|
|
}
|
|
|
|
|
|
if (info.file.status === "uploading") {
|
|
|
|
|
|
setLoading(true);
|
|
|
|
|
|
}
|
|
|
|
|
|
if (info.file.status === "error") {
|
|
|
|
|
|
message.error("文件上传失败")
|
|
|
|
|
|
setLoading(false);
|
|
|
|
|
|
}
|
|
|
|
|
|
let fileIds = info.fileList.map(file => {
|
|
|
|
|
|
return file.response?.data?.fileId
|
|
|
|
|
|
})
|
|
|
|
|
|
setFileIds(fileIds)
|
|
|
|
|
|
setFileList(info.fileList)
|
|
|
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
|
|
|
* @description pdf文件预览
|
|
|
|
|
|
* @param {String} params 文件预览url
|
|
|
|
|
|
*/
|
|
|
|
|
|
const viewPdf = (params) => {
|
|
|
|
|
|
setIframeSrc(params)
|
|
|
|
|
|
setPdfViewOPen(true)
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const onfinish = (values) => {
|
2024-09-27 10:15:58 +08:00
|
|
|
|
let oldFiles = fileList.map(item => (item.response?.data??item))
|
2024-09-26 17:59:26 +08:00
|
|
|
|
debugger
|
2024-09-23 15:52:06 +08:00
|
|
|
|
if (mode === 'edit') {
|
|
|
|
|
|
values.files = oldFiles;
|
|
|
|
|
|
values.id = record.id;
|
2024-09-26 17:59:26 +08:00
|
|
|
|
onEdit(apiurl.zdgl.edit, {...record,...values})
|
2024-09-23 15:52:06 +08:00
|
|
|
|
}
|
|
|
|
|
|
if (mode === 'save') {
|
|
|
|
|
|
values.files = oldFiles
|
2024-09-26 17:59:26 +08:00
|
|
|
|
onSave(apiurl.zdgl.add, values)
|
2024-09-23 15:52:06 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* @description 删除上传的图片
|
|
|
|
|
|
* @param {string} id 删除的id
|
|
|
|
|
|
*/
|
|
|
|
|
|
const deleteFile = (fileId) => {
|
|
|
|
|
|
console.log(fileId);
|
|
|
|
|
|
let filterFile = fileList.filter(item => item.response?.data?.fileId !== fileId);
|
|
|
|
|
|
setFileList(filterFile)
|
|
|
|
|
|
}
|
|
|
|
|
|
useEffect(() => {
|
|
|
|
|
|
if (mode != 'save') {
|
|
|
|
|
|
const imgFile = record?.files?.map(o => ({
|
|
|
|
|
|
name: o.fileName,
|
|
|
|
|
|
response: {
|
|
|
|
|
|
data: {
|
|
|
|
|
|
filePath: o.filePath,
|
|
|
|
|
|
fileId: o.fileId
|
|
|
|
|
|
}
|
|
|
|
|
|
},
|
|
|
|
|
|
}))
|
|
|
|
|
|
setFileList(imgFile)
|
|
|
|
|
|
}
|
|
|
|
|
|
}, [record, mode])
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
|
<>
|
|
|
|
|
|
<Form
|
|
|
|
|
|
form={form}
|
|
|
|
|
|
{...formItemLayout}
|
|
|
|
|
|
onFinish={onfinish}
|
|
|
|
|
|
initialValues={record}
|
|
|
|
|
|
>
|
|
|
|
|
|
<Row>
|
|
|
|
|
|
<Col span={12}>
|
|
|
|
|
|
<Form.Item
|
|
|
|
|
|
label="标题"
|
|
|
|
|
|
name="name"
|
|
|
|
|
|
rules={[{ required: true }]}
|
|
|
|
|
|
>
|
|
|
|
|
|
<Input disabled={mode === 'view'} style={{ width: '100%' }} allowClear />
|
|
|
|
|
|
</Form.Item>
|
|
|
|
|
|
</Col>
|
|
|
|
|
|
<Col span={12}>
|
2024-09-26 17:59:26 +08:00
|
|
|
|
<Form.Item label="制度类型" name="type" rules={[{ required: true }]}>
|
2024-09-27 10:15:58 +08:00
|
|
|
|
<Select allowClear style={{ width: '100%' }} options={opntios} />
|
2024-09-23 15:52:06 +08:00
|
|
|
|
</Form.Item>
|
|
|
|
|
|
</Col>
|
|
|
|
|
|
<Col span={12}>
|
|
|
|
|
|
<Form.Item
|
|
|
|
|
|
label="公布日期"
|
2024-09-26 17:59:26 +08:00
|
|
|
|
name="releaseDate"
|
2024-09-23 15:52:06 +08:00
|
|
|
|
getValueFromEvent={(e, dateString) => dateString}
|
|
|
|
|
|
getValueProps={(value) => ({ value: value ? moment(value) : undefined })}
|
|
|
|
|
|
>
|
2024-09-26 17:59:26 +08:00
|
|
|
|
<DatePicker disabled={mode === 'view'} format={'YYYY-MM-DD HH:mm:ss'} style={{ width: '100%' }} allowClear />
|
2024-09-23 15:52:06 +08:00
|
|
|
|
</Form.Item>
|
|
|
|
|
|
</Col>
|
|
|
|
|
|
<Col span={12}>
|
|
|
|
|
|
<Form.Item
|
|
|
|
|
|
label="发布单位"
|
2024-09-26 17:59:26 +08:00
|
|
|
|
name="fillUnit"
|
2024-09-23 15:52:06 +08:00
|
|
|
|
>
|
|
|
|
|
|
<Input disabled={mode === 'view'} style={{ width: '100%' }} allowClear />
|
|
|
|
|
|
</Form.Item>
|
|
|
|
|
|
</Col>
|
|
|
|
|
|
</Row>
|
|
|
|
|
|
|
|
|
|
|
|
<Row>
|
|
|
|
|
|
<Col span={24}>
|
|
|
|
|
|
<Form.Item
|
|
|
|
|
|
label="附件"
|
2024-09-26 17:59:26 +08:00
|
|
|
|
name="files"
|
2024-09-23 15:52:06 +08:00
|
|
|
|
labelCol={{ span: 3 }}
|
|
|
|
|
|
wrapperCol={{ span: 19 }}
|
|
|
|
|
|
>
|
|
|
|
|
|
{mode !== "view" &&
|
|
|
|
|
|
<Dragger
|
|
|
|
|
|
name='file'
|
|
|
|
|
|
// multiple
|
2024-09-26 17:59:26 +08:00
|
|
|
|
action="/gunshiApp/tsg/SzRegulatoryFramework/file/upload/singleSimple"
|
2024-09-23 15:52:06 +08:00
|
|
|
|
onChange={fileChange}
|
|
|
|
|
|
onDrop={(info) => { console.log(info.dataTransfer.files); }}
|
|
|
|
|
|
fileList={fileList}
|
|
|
|
|
|
disabled={loading}
|
|
|
|
|
|
// onSuccess={handleSuccess}
|
|
|
|
|
|
>
|
|
|
|
|
|
<p className="ant-upload-text">点击或拖拽文件到此区域上传</p>
|
|
|
|
|
|
<p className="ant-upload-hint">
|
|
|
|
|
|
支持扩展名:.doc .docx .pdf .jpg .png .ppt
|
|
|
|
|
|
</p>
|
|
|
|
|
|
</Dragger>
|
|
|
|
|
|
}
|
|
|
|
|
|
<Row gutter={[16]}>
|
|
|
|
|
|
{
|
|
|
|
|
|
fileList.length > 0 && fileList.map(file => {
|
|
|
|
|
|
return (
|
|
|
|
|
|
<Col span={12}>
|
2024-09-27 10:15:58 +08:00
|
|
|
|
<div className="file-item" style={{ width: "75%",marginTop:5 }}>
|
2024-09-23 15:52:06 +08:00
|
|
|
|
<div className='file-description'>
|
|
|
|
|
|
{file.name.indexOf('.docx') > -1 ?
|
|
|
|
|
|
<div
|
|
|
|
|
|
onClick={() => { download(file.response?.data?.fileId) }}
|
|
|
|
|
|
style={{ cursor: 'pointer' }}
|
|
|
|
|
|
>
|
|
|
|
|
|
<FileWordOutlined
|
|
|
|
|
|
style={{ fontSize: 40 }}
|
|
|
|
|
|
/>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
:
|
|
|
|
|
|
file.name.indexOf('.pdf') > -1 ?
|
|
|
|
|
|
<div
|
|
|
|
|
|
onClick={() => { viewPdf(file.response?.data?.fileId) }}
|
|
|
|
|
|
style={{ cursor: 'pointer' }}
|
|
|
|
|
|
>
|
|
|
|
|
|
<FilePdfOutlined style={{ fontSize: 40 }} />
|
|
|
|
|
|
</div>
|
|
|
|
|
|
:
|
|
|
|
|
|
file.name.indexOf('.zip') > -1 ?
|
|
|
|
|
|
<div
|
|
|
|
|
|
onClick={() => { download(file.response?.data?.fileId) }}
|
|
|
|
|
|
style={{ cursor: 'pointer' }}
|
|
|
|
|
|
>
|
|
|
|
|
|
<FileZipOutlined style={{ fontSize: 40 }} />
|
|
|
|
|
|
</div>
|
|
|
|
|
|
:
|
|
|
|
|
|
file.name.indexOf('.xlsx') > -1 ?
|
|
|
|
|
|
<div
|
|
|
|
|
|
onClick={() => { download(file.response?.data?.fileId) }}
|
|
|
|
|
|
style={{ cursor: 'pointer' }}
|
|
|
|
|
|
>
|
|
|
|
|
|
<FileExcelOutlined style={{ fontSize: 40 }} />
|
|
|
|
|
|
</div>
|
|
|
|
|
|
:
|
|
|
|
|
|
<Image width={60} src={url + file.response?.data?.filePath} alt='' />
|
|
|
|
|
|
}
|
|
|
|
|
|
<span>{file.name}</span>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
<div className={mode == "view" ? 'delete-icon disable-icon' : 'delete-icon'} onClick={() => deleteFile(file.response?.data?.fileId)}>
|
|
|
|
|
|
<DeleteOutlined />
|
|
|
|
|
|
</div>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
</Col>
|
|
|
|
|
|
)
|
|
|
|
|
|
})
|
|
|
|
|
|
}
|
|
|
|
|
|
</Row>
|
|
|
|
|
|
</Form.Item>
|
|
|
|
|
|
</Col>
|
|
|
|
|
|
</Row>
|
|
|
|
|
|
{
|
|
|
|
|
|
mode === 'view' ? null : (
|
|
|
|
|
|
<>
|
|
|
|
|
|
<Form.Item {...btnItemLayout}>
|
2024-09-26 17:59:26 +08:00
|
|
|
|
<Button type="primary" htmlType="submit" loading={loading}>
|
2024-09-23 15:52:06 +08:00
|
|
|
|
{mode === 'save' ? '提交' : '修改'}
|
|
|
|
|
|
</Button>
|
|
|
|
|
|
</Form.Item>
|
|
|
|
|
|
</>
|
|
|
|
|
|
)
|
|
|
|
|
|
}
|
|
|
|
|
|
</Form>
|
|
|
|
|
|
<Modal
|
|
|
|
|
|
open={pdfViewOPen}
|
|
|
|
|
|
width={1000}
|
|
|
|
|
|
title=""
|
|
|
|
|
|
footer={null}
|
|
|
|
|
|
style={{ marginTop: "-5%" }}
|
|
|
|
|
|
onCancel={() => {
|
|
|
|
|
|
setPdfViewOPen(false)
|
|
|
|
|
|
}}
|
|
|
|
|
|
>
|
|
|
|
|
|
<iframe
|
|
|
|
|
|
style={{
|
|
|
|
|
|
height: '80vh',
|
|
|
|
|
|
width: '100%',
|
|
|
|
|
|
border: 0,
|
|
|
|
|
|
marginTop: 20,
|
|
|
|
|
|
}}
|
|
|
|
|
|
src={`${process.env.PUBLIC_URL}/static/pdf/web/viewer.html?file=${encodeURIComponent(`/gunshiApp/xyt/projectEvents/file/download/${iframeSrc}`)}`}
|
|
|
|
|
|
/>
|
|
|
|
|
|
</Modal>
|
|
|
|
|
|
</>
|
|
|
|
|
|
);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
export default ModalForm;
|