import React, { useState,useCallback } from 'react' import clsx from 'clsx' import { makeStyles, createStyles, Theme } from '@material-ui/core/styles'; import Box from '@material-ui/core/Box'; import DeleteIcon from '@material-ui/icons/Delete'; import Icon from '../../Icon'; import Tooltip from '@material-ui/core/Tooltip'; import Fab from '@material-ui/core/Fab'; import { getConfig } from '../../../storage/ConfigStorage' import ExtIcon from './ExtIcon' const useStyles = makeStyles((theme: Theme) => createStyles({ root: { position: 'relative', margin: 0, fontSize: '1rem' }, thumbsContainer: { display: 'flex', flexDirection: 'row', flexWrap: 'wrap' }, thumb: { position: 'relative', display: 'inline-flex', borderRadius: 3, border: '1px solid #eaeaea', marginBottom: 5, marginRight: 5, width: 100, height: 100, padding: 2, boxSizing: 'border-box', background: '#fcfcfc', cursor: 'pointer' }, disabled:{ opacity: 0.2, background: 'rgba(0, 0, 0, 0.2)', }, active: { opacity: 0.5, background: 'rgba(225, 225, 225, 0.5)', }, thumbInner: { display: 'flex', minWidth: 0, alignItems: 'center', justifyContent: 'center', overflow: 'hidden' }, img: { display: 'block', width: 'auto', height: '100%' }, thumbTool: { display: 'flex', position: 'absolute', right: 2, top: 2 }, thumbIcons: { position: 'absolute', right: 2, top: 2 }, fileThumbsContainer: { display: 'block', marginTop: 10 }, fileThumb: { position: 'relative', display: 'flex', borderBottom: '1px solid #eaeaea', padding: 4, cursor: 'pointer' }, fileThumbInner: { flex: '1', display:'flex', flexWrap:'nowrap', alignItems:'center' }, fileThumbTool: { width: 60, display: 'flex', right: 2, top: 2 }, successIcon: { marginLeft: 5, background: '#fff', borderRadius: '50%' }, })) export type ThumbsProps = { type:string, attaches:any, selected?:any, onSelect?:Function, onRemove?:Function, disabled?:any } const ThumbsPage = (props: ThumbsProps) => { const { localeConfig,attachPrefix} = getConfig(); const { onRemove, attaches, type, onSelect, selected,disabled } = props // 样式 const classes = useStyles() const [hoverd, setHoverd] = useState()// 鼠标经过状态 return (
{ attaches && attaches.length > 0 && attaches.map((attach: any, index: number) => { return (
{ if (onSelect && (!(disabled && disabled[attach.id]))) { // 有设置选中方法,且不为禁止选择 onSelect(attach) } }} onMouseEnter={() => { const newHoverd = hoverd || {} newHoverd[attach.id] = true setHoverd(Object.assign({}, newHoverd)) }} onMouseLeave={() => { const newHoverd = hoverd || {} newHoverd[attach.id] = false setHoverd(Object.assign({}, newHoverd)) }}> {type === 'images' || type === 'image' ?(
):(
{/* 文件 */} {attach.url.substring(attach.url.lastIndexOf('/') + 1, attach.url.length)}
) } { onRemove && hoverd && hoverd[attach.id] && (
{/* 删除 */} { onRemove({ index, attach }) }}>
) } { selected && selected[attach.id] && (
) }
) }) }
) } export default ThumbsPage