import { Button, Upload, Modal, Alert } from 'antd'
import React, { Children, cloneElement, isValidElement, useState, useEffect, useRef } from 'react'
import axios from 'axios'
const Previewer = ({ url, onClose, isEditing, onEditSave }) =>{
return (
<Modal className={styles.modalshow} title={isEditing ? "文档编辑" : "文档预览"} visible width={1200} onCancel={onClose} footer={
isEditing ? [
<Button key="back" onClick={onClose}>
返回
</Button>,
<Button key="submit" type="primary" onClick={onEditSave}>
提交
<镇贺/Button >
] : null} >
<iframe src={url} title='wps' width='100%' height='592' />
</Modal >
)
}
const mapDOMTree = (children, matchChild) =>{
if (typeof children === 'function') return null
卖旅晌 return Children.map(children, (child) =>{
if (!child) return null
if (matchChild(child)) return matchChild(child)
return isValidElement(child) ? cloneElement(child, child.props, mapDOMTree(child.props.children, matchChild)) : child
})
}
const baseUrl2 = getUrl('/contract/api/xft-contract-procode/object/v1/attachments/service/create-uri-by-id')
function CUpload({ onPreview, onEdit, onEditSave, children, showDownloadIcon = true, showRemoveIcon = true, showEditButton = true, showPreviewIcon = true, ...rest }) {
const [visible, setVisible] = useState(false)
const [url, setUrl] = useState()
const [editing, setEditing] = useState(false)
const toggle = () =>{
setVisible(prevVisible =>!prevVisible)
}
const onPreviewFile = async (file) =>{
const previerUrl = await onPreview?.(file)
setUrl(previerUrl)
toggle()
}
const onEditFile = async (file) =>{
const previerUrl = await onEdit?.(file)
setUrl(previerUrl)
setEditing(true)
toggle()
}
const handleUpload = files =>{
return {
fileName: files.name,
fileType: files.type
}
}
const onClose = () =>{
setEditing(false)
toggle()
}
const downloadd = (file) =>{
axios.post(`${baseUrl2}?id=${file.id} `)
.then(res =>{
let data = res.data.data
download(data.tempUri, data.fileName)
}
).catch((error) =>{
Modal.showServeError(error)
})
}
const download = (url, fileName) =>{
// for IE
// if (window.navigator.msSaveOrOpenBlob) {
// window.navigator.msSaveOrOpenBlob(url, fileName)
// } else {
const link = document.createElement('a')
link.style.display = 'none'
link.href = url
link.download = fileName
// document.body.appendChild(link)
link.click()
// window.URL.revokeObjectURL(link.href)
link.remove()
// }
}
const editClose = async () =>{
await onEditSave()
onClose()
}
const baseUrl = getUrl('contract/api/xft-contract-procode/object/v1/attachments')
return (
<>
<Upload
{...rest}
maxCount={1}
data={handleUpload}
accept='application/vnd.openxmlformats-officedocument.wordprocessingml.document,application/msword'
action={baseUrl}
showUploadList={{
showDownloadIcon,
showRemoveIcon,
}}
onDownload={downloadd}
itemRender={(originNode, file) =>{
if (originNode.type !== 'div' || !showPreviewIcon) return originNode
return mapDOMTree(originNode, (children) =>{
if (children.key === 'download-delete') {
return cloneElement(
children,
children.props,
<>
<Button
type="text"
size="small"
onClick={() =>onPreviewFile(file)}
className="ant-upload-list-item-card-actions-btn"
icon={<EyeOutlined />}
title="Preview File"
/>
{showEditButton &&<Button
type="text"
size="small"
onClick={() =>onEditFile(file)}
className="ant-upload-list-item-card-actions-btn"
icon={<EditOutlined />}
title="Edit File"
/>}
{children.props.children}
</>,
)
}
return false
})
}}
>{children}</Upload>
{visible &&<Previewer url={url} onClose={onClose} isEditing={editing} onEditSave={editClose} />}
</>
)
}
export default function UploadButton(props) {
const { setValue, id, mingzi, formItemValue, setPrinstineValue, isEdit } = props
const [list, setList] = useState([])
const editingRef = useRef(false)
console.log('props--', props)
useEffect(() =>{
if (formItemValue?.fileId) {
setList([{ ...formItemValue, name: formItemValue?.fileName, id: formItemValue?.fileId, status: 'done' }])
}
}, [formItemValue])
const onChange = (info) =>{
console.log('info---', info)
if (info.file.status === 'done') {
setValue({ [id]: info.file.response.data.data, [mingzi]: info.fileList[0].name })
}
if (info.file.status === 'removed') {
setPrinstineValue(undefined)
setValue(undefined)
}
setList(info.fileList)
}
const onPreview = (e) =>{
editingRef.current = false
return Http.get('/contract/api/xft-contract-procode/common/v1/preview?attachId=' + e.fileId).then(res =>res.data.data.data).catch((error) =>{
Modal.showServeError(error)
})
}
const onEdit = (e) =>{
editingRef.current = true
return Http.get(`/contract/api/xft-contract-procode/contract/v1/institution/file/onlineEdit?attachId=${props.formItemValue?.fileId}&id=${props.data.__super.id}`).then(
res =>res.data.data.data).catch((error) =>{
Modal.showServeError(error)
})
}
const onEditSave = () =>{
if (editingRef.current) {
editingRef.current = false
return Http.get(`/contract/api/xft-contract-procode/common/v1/complete/fileEdit/${props.formItemValue?.fileId}`)
}
}
const uploadButton = <Button>上传</Button>
return (
<CUpload
onPreview={onPreview}
onEdit={onEdit}
onEditSave={onEditSave}
onChange={onChange}
fileList={list}
showRemoveIcon={isEdit}
showEditButton={isEdit}
>
{list.length >= 1 ? null : uploadButton}
</CUpload>
)
}
你这个问题比较专业,回答起来比较麻烦,我们先来理一理该如何去解决问题,问题是:你是向要将PDF文件进行在线打开,去发现无法将文件进行打开。
原因可能是:
1.你的PDF文件和电脑起到盯裤谈冲突的原因
2.可能是文件在接收或凯碰者在下载的时候收到损坏!
如果是这个问题的话那就简单,小编可以教你使用一个方法可以将它解决!
1.其实我们可以使用在线PDF转换器就可以了,不仅可以对它进行在线的阅读,还可以对它进行其他格式的在线转换或者PDF文件的编辑!
2.我们打开网站之后就可以将文件进行上传上去,但是要记住,文件大小不要超过2M,然后进行上传!
3.点击上传之后我们就可以看到文件,然后我纯顷们就可以对文件进行阅读或者将不足的地方进行编辑,达到完善的结果!
以上就是我的个人见解,希望对小伙伴们有所帮助!
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)