Commit 637957b3 authored by 田翔's avatar 田翔

fix: 图片预览修复

parent 0ff277c1
...@@ -64,6 +64,7 @@ const FileUpload = (props) => { ...@@ -64,6 +64,7 @@ const FileUpload = (props) => {
const [showList, setShowList] = useState([]) const [showList, setShowList] = useState([])
const [visible, setVisible] = useState(false) const [visible, setVisible] = useState(false)
const [showFile, setShowFile] = useState({ fileType: '', filePath: '' }) const [showFile, setShowFile] = useState({ fileType: '', filePath: '' })
const [imgVisible, setImgVisible] = useState(false)
const showType = fileType === '图片' ? 'picture-card' : 'picture' const showType = fileType === '图片' ? 'picture-card' : 'picture'
...@@ -148,11 +149,6 @@ const FileUpload = (props) => { ...@@ -148,11 +149,6 @@ const FileUpload = (props) => {
let list = presetValue ? presetValue.split(',') : [] let list = presetValue ? presetValue.split(',') : []
list.forEach((item, index) => { list.forEach((item, index) => {
if (item) { // @Tips: 直接过滤掉名字中有异常字符的文件 if (item) { // @Tips: 直接过滤掉名字中有异常字符的文件
let src = item
let fileType = getFileType(item)
if (fileType === 'svg') {
src = btoa(encodeURI(item))
}
let uid = index + '_' + Math.random() let uid = index + '_' + Math.random()
let _obj = { let _obj = {
uid: uid, uid: uid,
...@@ -160,13 +156,13 @@ const FileUpload = (props) => { ...@@ -160,13 +156,13 @@ const FileUpload = (props) => {
name: item.split('\\').reverse()[0], name: item.split('\\').reverse()[0],
type: fileType === '图片' ? 'image/jpeg' : 'file', type: fileType === '图片' ? 'image/jpeg' : 'file',
status: 'done', status: 'done',
url: `${downloadFileUrl}?filePath=${src}${site ? `&_site=${site}` : ''}`, url: `${downloadFileUrl}?filePath=${item}${site ? `&_site=${site}` : ''}`,
sourcePath: src, sourcePath: item.url,
originFileObj: { "uid": uid }, originFileObj: { "uid": uid },
"response": { "code": 0, "msg": "Ok", "data": src, "stackTrace": null }, "response": { "code": 0, "msg": "Ok", "data": item, "stackTrace": null },
"xhr": {}, "xhr": {},
}; };
if (schema.renderTo === 'Image') _obj.thumbUrl = `${downloadFileUrl}?filePath=${src}${site ? `&_site=${site}` : ''}`; if (schema.renderTo === 'Image') _obj.thumbUrl = `${downloadFileUrl}?filePath=${item}${site ? `&_site=${site}` : ''}`;
fileList.push(_obj); fileList.push(_obj);
} }
}) })
...@@ -183,6 +179,8 @@ const FileUpload = (props) => { ...@@ -183,6 +179,8 @@ const FileUpload = (props) => {
} }
}, [presetValue]) }, [presetValue])
console.log(imgVisible, showFile)
return ( return (
<div className={styles.uploadBox}> <div className={styles.uploadBox}>
<Upload <Upload
...@@ -206,12 +204,20 @@ const FileUpload = (props) => { ...@@ -206,12 +204,20 @@ const FileUpload = (props) => {
onCancel={() => setVisible(false)} onCancel={() => setVisible(false)}
bodyStyle={{ height: 650, overflowY: showFile.fileType.includes('xlsx') ? 'none' : "auto" }} bodyStyle={{ height: 650, overflowY: showFile.fileType.includes('xlsx') ? 'none' : "auto" }}
> >
<FileViewer {
className='fileViewer' ['jpg', 'png', 'svg', 'jpeg'].includes(showFile.fileType) ? (
title='123' <div style={{ width: '100%', height: '100%', display: 'flex', justifyContent: 'center', alignItems: 'center' }}>
fileType={showFile.fileType} <img style={{ maxWidth: '100%', maxHeight: '100%' }} src={window.location.origin + showFile.filePath}></img>
filePath={window.location.origin + showFile.filePath} </div>
/> ) : (
<FileViewer
className='fileViewer'
title='123'
fileType={showFile.fileType}
filePath={window.location.origin + showFile.filePath}
/>
)
}
</Drag> </Drag>
</div> </div>
) )
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment