import React, { useState, useCallback} from 'react' import { makeStyles, createStyles, Theme, useTheme } from '@material-ui/core/styles'; import Box from '@material-ui/core/Box'; import SwipeableViews from 'react-swipeable-views'; import Dialog, { DialogProps } from '@material-ui/core/Dialog'; import DialogContent from '@material-ui/core/DialogContent'; import MuiDialogTitle from '@material-ui/core/DialogTitle'; import { CloseButton } from '../button'; import { getConfig } from '../../../storage/ConfigStorage' import DialogActions from '@material-ui/core/DialogActions'; import { TabPanel, StyleTab, StyleTabs } from '../tabs/StyleTabs'; import Single from './Single' import Remote from './Remote' import Url from './url' import Multi from './Multi' import * as UploadType from './UploadType' import TextInput from '../form/TextInput' const useStylesTitle = makeStyles((theme: Theme) => createStyles({ root: { margin: 0, background: '#f5f5f5', paddingTop: theme.spacing(1), paddingBottom: theme.spacing(1), paddingLeft: theme.spacing(2), paddingRight: theme.spacing(2), borderBottom: '1px solid #dedede', fontSize: '1rem' }, closeButton: { position: 'absolute', right: theme.spacing(1), top: 5 }, })) const DialogTitle = (props: any) => { const classes = useStylesTitle() const { children, onClose } = props; return ( {children} {onClose ? ( { onClose(e) }}> ) : null} ); }; const useStyles = makeStyles((theme: Theme) => createStyles({ root: { margin: 0, fontSize: '1rem' }, closeButton: { position: 'absolute', right: theme.spacing(1), top: 5 }, content: { display: 'flex', flexDirection: 'column', padding: 0, }, contentHeader: { display: 'flex', flexDirection: 'column', borderRadius: 0, background: `-webkit-linear-gradient(#f9f9f9, #f0f0f0); -o-linear-gradient(#f9f9f9, #f0f0f0); -moz-linear-gradient(#f9f9f9, #f0f0f0); linear-gradient(#f9f9f9, #f0f0f0)`, height: 38 }, contentContainer: { flex: 1, padding: 0, }, thumbImage: { position: 'relative', width: 100, height: 100, }, thumbButton: { position: 'absolute', top: 0, left: 0, width: '100%', height: '100%', display: 'block', textAlign: 'center', verticalAlign: 'middile' }, submit: { margin: theme.spacing(3, 0, 2), }, footerInputs: { display: 'inline-flex', }, footerInput: { margin: theme.spacing(0, 1, 0, 0) } })) const UploadDialog = (props: any) => { const { open, success, onClose, type, attaches, url, fromEditor } = props; const { localeConfig } = getConfig(); const classes = useStyles() const theme = useTheme(); const [fullWidth, setFullWidth] = useState(false); const [maxWidth, setMaxWidth] = useState('md'); const [value, setValue] = useState(0); // 图片尺寸,编辑器使用 const [imgOptions, setImgOptions] = useState({ width:'', height:'', alt:'' }) function handleChange(event: React.ChangeEvent<{}>, newValue: number) { if (newValue === 1) { setFullWidth(true) } else { setFullWidth(false) } setValue(newValue); } function handleChangeIndex(index: number) { if (index === 1) { setFullWidth(true) } else { setFullWidth(false) } setValue(index); } // 上传模式 const mode = UploadType.getUploadMode(type) return ( {type === 'image' || type === 'images' ? localeConfig.words.chooseImage : localeConfig.words.chooseFile} {/* 本地上传 */} {/* 远程文件 */} {/* 文件链接 */} {// 单图/单文件上传 (mode === UploadType.UploadModes.SINGLE) && ( { // 返回附件对象,返回编辑页面 success({ attach,imgOptions }) } }} />)} {// 多图/多文件上传 (mode === UploadType.UploadModes.MULTI) && ( { // 上传成功,返回编辑页面 success({ attaches, imgOptions }) } }} />) } {/* 远程 */} { // 已选择,返回编辑页面 success({ attaches, imgOptions }) } }} /> {/* 链接地址 */} { { success({ url ,imgOptions}) } }} />} {fromEditor && ( { imgOptions.alt = event.target.value setImgOptions(Object.assign({},imgOptions)) }} /> { imgOptions.width = event.target.value setImgOptions(Object.assign({},imgOptions)) }} /> { imgOptions.height = event.target.value setImgOptions(Object.assign({},imgOptions)) }} /> )} ); } export default UploadDialog