-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Optimize upload component file preview
- Loading branch information
Showing
7 changed files
with
127 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
._local { | ||
:global { | ||
// .vds-menu-button, | ||
// .vds-seek-button { | ||
// display: none; | ||
// } | ||
|
||
// .vds-button { | ||
// color: var(--color_text); | ||
// } | ||
// .vds-play-button { | ||
// color: var(--color_bg); | ||
// background-color: var(--color_text); | ||
// } | ||
|
||
// .vds-title-text { | ||
// animation: none; | ||
// } | ||
|
||
.file_wrap { | ||
padding: 11px; | ||
|
||
background: var(--color_bg_nav); | ||
border-radius: 6px; | ||
filter: drop-shadow(0 4px 3px rgb(0 0 0 / 0.07)) drop-shadow(0 2px 2px rgb(0 0 0 / 0.06)); | ||
display: flex; | ||
align-items: center; | ||
|
||
.title { | ||
color: var(--color_title); | ||
font-family: inherit; | ||
font-weight: 400; | ||
font-size: 14px; | ||
overflow: hidden; | ||
word-wrap: break-word; | ||
white-space: nowrap; | ||
text-overflow: ellipsis; | ||
margin-left: 0.5em; | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
import { getFileSrc } from '@/knife' | ||
|
||
import type { IPropsCustomRender } from '../types' | ||
import { useEffect, useState } from 'react' | ||
import { Skeleton } from 'antd' | ||
import { Icon } from '@/widgets' | ||
|
||
import '@vidstack/react/player/styles/default/theme.css' | ||
import '@vidstack/react/player/styles/default/layouts/audio.css' | ||
import styles from './File.less' | ||
import clsx from 'clsx' | ||
|
||
const Index = (props: IPropsCustomRender) => { | ||
const { file, preivewSize, remove } = props | ||
const [loading, setLoading] = useState<boolean>(true) | ||
const [url, setUrl] = useState<string>(file.response || '') | ||
const [title, setTitle] = useState<string>(file.name) | ||
const [ext, setExt] = useState<string>(file.name.split('.').pop() || '') | ||
const [showOpration, setShowOpration] = useState<boolean>(false) | ||
|
||
const src = getFileSrc(url, props.appRoot) | ||
useEffect(() => { | ||
if (file.response) { | ||
const url = getFileSrc(file.response, props.appRoot) | ||
const title = url.split('name=/')[1]?.split('&')[0] || file.name | ||
setUrl(url) | ||
setTitle(title.split('/').pop() || file.name) | ||
setExt(title.split('.').pop() || '') | ||
setLoading(false) | ||
} | ||
}, [file.response]) | ||
|
||
const preview = () => { | ||
window.open(src) | ||
} | ||
|
||
return ( | ||
<div | ||
className={clsx([styles._local, 'upload_custom_wrap', 'flex', 'relative'])} | ||
onMouseEnter={() => setShowOpration(true)} | ||
onMouseLeave={() => setShowOpration(false)} | ||
> | ||
<div className='toolbar' style={{ display: showOpration ? 'flex' : 'none' }}> | ||
<div className='toolbar-button' onClick={preview}> | ||
<Icon name='icon-download' size={16}></Icon> | ||
</div> | ||
<div className='toolbar-button' onClick={remove}> | ||
<Icon name='icon-trash' size={16}></Icon> | ||
</div> | ||
</div> | ||
|
||
<Skeleton | ||
loading={loading || url == ''} | ||
active | ||
paragraph={{ | ||
width: preivewSize?.width || '100%' | ||
}} | ||
> | ||
<div | ||
className={clsx(['file_wrap'])} | ||
style={{ height: '60px', width: preivewSize?.width || '100%' }} | ||
> | ||
<Icon name='icon-file' size={20}></Icon> | ||
<span className='title'> | ||
{ext}: {title} | ||
</span> | ||
</div> | ||
</Skeleton> | ||
</div> | ||
) | ||
} | ||
|
||
export default window.$app.memo(Index) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters