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

fix: 图片预览修复

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