From 16827a37cabb7d4f28d0995228fddfb9cc9cf9d0 Mon Sep 17 00:00:00 2001 From: HFO4 <912394456@qq.com> Date: Tue, 3 Dec 2019 17:13:20 +0800 Subject: [PATCH] =?UTF-8?q?Feat:=20=E5=A4=8D=E5=88=B6=E6=A8=A1=E6=80=81?= =?UTF-8?q?=E6=A1=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/actions/index.js | 6 + src/component/FileManager/ContextMenu.js | 21 +++- src/component/FileManager/Modals.js | 9 ++ src/component/Modals/Copy.js | 145 +++++++++++++++++++++++ src/index.js | 3 +- src/reducers/index.js | 10 ++ 6 files changed, 191 insertions(+), 3 deletions(-) create mode 100644 src/component/Modals/Copy.js diff --git a/src/actions/index.js b/src/actions/index.js index 4d54825..ec16262 100644 --- a/src/actions/index.js +++ b/src/actions/index.js @@ -165,6 +165,12 @@ export const openGetSourceDialog = () => { }; }; +export const openCopyDialog = () => { + return { + type: "OPEN_COPY_DIALOG" + }; +}; + export const closeAllModals = () => { return { type: "CLOSE_ALL_MODALS" diff --git a/src/component/FileManager/ContextMenu.js b/src/component/FileManager/ContextMenu.js index f9f23c0..ff4beec 100644 --- a/src/component/FileManager/ContextMenu.js +++ b/src/component/FileManager/ContextMenu.js @@ -16,6 +16,7 @@ import { openRemoteDownloadDialog, openTorrentDownloadDialog, openGetSourceDialog, + openCopyDialog } from "../../actions/index" import {isPreviewable,isTorrent} from "../../config" import {allowSharePreview} from "../../untils/index" @@ -23,6 +24,7 @@ import UploadIcon from '@material-ui/icons/CloudUpload' import DownloadIcon from '@material-ui/icons/CloudDownload' import NewFolderIcon from '@material-ui/icons/CreateNewFolder' import OpenFolderIcon from '@material-ui/icons/FolderOpen' +import FileCopyIcon from '@material-ui/icons/FileCopy'; import ShareIcon from '@material-ui/icons/Share' import RenameIcon from '@material-ui/icons/BorderColor' import MoveIcon from '@material-ui/icons/Input' @@ -97,6 +99,9 @@ const mapDispatchToProps = dispatch => { }, openGetSourceDialog:()=>{ dispatch(openGetSourceDialog()) + }, + openCopyDialog:()=>{ + dispatch(openCopyDialog()) } } } @@ -236,15 +241,18 @@ class ContextMenuCompoment extends Component { {this.props.menuType!=="empty"&& {(!this.props.isMultiple && this.props.withFolder)&& + <> 进入 + + } {(!this.props.isMultiple&&this.props.withFile&&isPreviewable(this.props.selected[0].name))&& -
+ <> this.openPreview()}> @@ -252,8 +260,9 @@ class ContextMenuCompoment extends Component { 打开 -
+ } + {(!this.props.isMultiple&&this.props.withFile)&& this.openDownload()}> @@ -292,12 +301,20 @@ class ContextMenuCompoment extends Component { } {(!this.props.isMultiple&&pathHelper.isHomePage(this.props.location.pathname))&& + <> this.props.openRenameDialog() }> 重命名 + this.props.openCopyDialog() }> + + + + 复制 + + } {pathHelper.isHomePage(this.props.location.pathname)&&
this.props.openMoveDialog() }> diff --git a/src/component/FileManager/Modals.js b/src/component/FileManager/Modals.js index 8b4f7ed..145d584 100644 --- a/src/component/FileManager/Modals.js +++ b/src/component/FileManager/Modals.js @@ -26,6 +26,7 @@ import { FormControlLabel, } from '@material-ui/core'; import Loading from "../Modals/Loading" +import CopyDialog from "../Modals/Copy" const styles = theme => ({ wrapper: { @@ -537,6 +538,14 @@ class ModalsCompoment extends Component { + + ({ + contentFix: { + padding: "10px 24px 0px 24px" + }, + wrapper: { + margin: theme.spacing(1), + position: "relative" + }, + buttonProgress: { + color: theme.palette.secondary.light, + position: "absolute", + top: "50%", + left: "50%", + marginTop: -12, + marginLeft: -12 + } +})); + +export default function CopyDialog(props) { + const [selectedPath, setSelectedPath] = useState(""); + const [selectedPathName, setSelectedPathName] = useState(""); + + const dispatch = useDispatch(); + const ToggleSnackbar = useCallback( + (vertical, horizontal, msg, color) => + dispatch(toggleSnackbar(vertical, horizontal, msg, color)), + [dispatch] + ); + const SetModalsLoading = useCallback( + status => { + dispatch(setModalsLoading(status)); + }, + [dispatch] + ); + const RefreshFileList = useCallback(() => { + dispatch(refreshFileList()); + }, [dispatch]); + + const setMoveTarget = folder => { + let path = + folder.path === "/" + ? folder.path + folder.name + : folder.path + "/" + folder.name; + setSelectedPath(path); + setSelectedPathName(folder.name); + }; + + const submitMove = e => { + if (e != null) { + e.preventDefault(); + } + SetModalsLoading(true); + let dirs = [], + items = []; + // eslint-disable-next-line + + if (props.selected[0].type === "dir") { + dirs.push(props.selected[0].name); + } else { + items.push(props.selected[0].name); + } + + API.post("/object/copy", { + src_dir: props.selected[0].path, + src: { + dirs: dirs, + items: items + }, + dst: selectedPath === "//" ? "/" : selectedPath + }) + .then(response => { + props.onClose(); + RefreshFileList(); + SetModalsLoading(false); + }) + .catch(error => { + ToggleSnackbar("top", "right", error.message, "error"); + SetModalsLoading(false); + }); + }; + + const classes = useStyles(); + + return ( + + 复制到 + + + {selectedPath !== "" && ( + + + 复制到 {selectedPathName} + + + )} + + +
+ +
+
+
+ ); +} diff --git a/src/index.js b/src/index.js index b1b0401..b3bfa53 100644 --- a/src/index.js +++ b/src/index.js @@ -81,7 +81,8 @@ const defaultStatus = InitSiteConfig({ remoteDownload: false, torrentDownload: false, getSource: false, - resave: false + copy:false, + resave: false, }, snackbar: { toggle: false, diff --git a/src/reducers/index.js b/src/reducers/index.js index 523d980..70ab5ce 100644 --- a/src/reducers/index.js +++ b/src/reducers/index.js @@ -322,6 +322,15 @@ const cloudreveApp = (state = [], action) => { contextOpen:false, }), }); + case 'OPEN_COPY_DIALOG': + return Object.assign({}, state, { + viewUpdate: Object.assign({}, state.viewUpdate, { + modals: Object.assign({}, state.viewUpdate.modals, { + copy:true, + }), + contextOpen:false, + }), + }); case 'CLOSE_ALL_MODALS': return Object.assign({}, state, { viewUpdate: Object.assign({}, state.viewUpdate, { @@ -336,6 +345,7 @@ const cloudreveApp = (state = [], action) => { torrentDownload:false, getSource:false, resave:false, + copy:false, }), }), });