import { Divider, ListItemIcon, MenuItem, Typography, withStyles } from "@material-ui/core"; import Menu from "@material-ui/core/Menu"; import { Archive, Unarchive } from "@material-ui/icons"; import RenameIcon from "@material-ui/icons/BorderColor"; import DownloadIcon from "@material-ui/icons/CloudDownload"; import UploadIcon from "@material-ui/icons/CloudUpload"; import NewFolderIcon from "@material-ui/icons/CreateNewFolder"; import DeleteIcon from "@material-ui/icons/Delete"; import FileCopyIcon from "@material-ui/icons/FileCopy"; import OpenFolderIcon from "@material-ui/icons/FolderOpen"; import MoveIcon from "@material-ui/icons/Input"; import LinkIcon from "@material-ui/icons/InsertLink"; import OpenIcon from "@material-ui/icons/OpenInNew"; import ShareIcon from "@material-ui/icons/Share"; import { FolderUpload, MagnetOn } from "mdi-material-ui"; import PropTypes from "prop-types"; import React, { Component } from "react"; import { connect } from "react-redux"; import { withRouter } from "react-router-dom"; import { openCompressDialog } from "../../actions"; import { changeContextMenu, navitateTo, openCopyDialog, openCreateFolderDialog, openDecompressDialog, openGetSourceDialog, openLoadingDialog, openMoveDialog, openMusicDialog, openRemoteDownloadDialog, openRemoveDialog, openRenameDialog, openShareDialog, openTorrentDownloadDialog, setNavigatorLoadingStatus, setSelectedTarget, showImgPreivew, toggleSnackbar } from "../../actions/index"; import { isCompressFile, isPreviewable, isTorrent } from "../../config"; import Auth from "../../middleware/Auth"; import { allowSharePreview } from "../../utils/index"; import pathHelper from "../../utils/page"; const styles = () => ({ propover: { minWidth: "200px!important" }, divider:{ marginTop:4, marginBottom:4, } }); const mapStateToProps = state => { return { menuType: state.viewUpdate.contextType, menuOpen: state.viewUpdate.contextOpen, isMultiple: state.explorer.selectProps.isMultiple, withFolder: state.explorer.selectProps.withFolder, withFile: state.explorer.selectProps.withFile, path: state.navigator.path, selected: state.explorer.selected, keywords: state.explorer.keywords, }; }; const mapDispatchToProps = dispatch => { return { changeContextMenu: (type, open) => { dispatch(changeContextMenu(type, open)); }, setNavigatorLoadingStatus: status => { dispatch(setNavigatorLoadingStatus(status)); }, setSelectedTarget: targets => { dispatch(setSelectedTarget(targets)); }, navitateTo: path => { dispatch(navitateTo(path)); }, openCreateFolderDialog: () => { dispatch(openCreateFolderDialog()); }, openRenameDialog: () => { dispatch(openRenameDialog()); }, openMoveDialog: () => { dispatch(openMoveDialog()); }, openRemoveDialog: () => { dispatch(openRemoveDialog()); }, openShareDialog: () => { dispatch(openShareDialog()); }, showImgPreivew: first => { dispatch(showImgPreivew(first)); }, openMusicDialog: () => { dispatch(openMusicDialog()); }, toggleSnackbar: (vertical, horizontal, msg, color) => { dispatch(toggleSnackbar(vertical, horizontal, msg, color)); }, openRemoteDownloadDialog: () => { dispatch(openRemoteDownloadDialog()); }, openTorrentDownloadDialog: () => { dispatch(openTorrentDownloadDialog()); }, openGetSourceDialog: () => { dispatch(openGetSourceDialog()); }, openCopyDialog: () => { dispatch(openCopyDialog()); }, openLoadingDialog: text => { dispatch(openLoadingDialog(text)); }, openDecompressDialog: () => { dispatch(openDecompressDialog()); }, openCompressDialog: () => { dispatch(openCompressDialog()); } }; }; class ContextMenuCompoment extends Component { X = 0; Y = 0; state = {}; componentDidMount = () => { window.document.addEventListener("mousemove", this.setPoint); }; setPoint = e => { this.Y = e.clientY; this.X = e.clientX; }; openArchiveDownload = () => { this.props.changeContextMenu("file", false); this.props.openLoadingDialog("打包中..."); }; openDownload = () => { if (!allowSharePreview()) { this.props.toggleSnackbar( "top", "right", "未登录用户无法预览", "warning" ); this.props.changeContextMenu("file", false); return; } this.props.changeContextMenu("file", false); this.props.openLoadingDialog("获取下载地址..."); }; enterFolder = () => { this.props.navitateTo( this.props.path === "/" ? this.props.path + this.props.selected[0].name : this.props.path + "/" + this.props.selected[0].name ); }; clickUpload = id => { this.props.changeContextMenu("empty", false); let uploadButton = document.getElementsByClassName(id)[0]; if (document.body.contains(uploadButton)) { uploadButton.click(); } else { this.props.toggleSnackbar( "top", "right", "上传组件还未加载完成", "warning" ); } }; openPreview = () => { let isShare = pathHelper.isSharePage(this.props.location.pathname); if (isShare) { let user = Auth.GetUser(); if (!Auth.Check() && user && !user.group.shareDownload) { this.props.toggleSnackbar( "top", "right", "请先登录", "warning" ); this.props.changeContextMenu("file", false); return; } } this.props.changeContextMenu("file", false); let previewPath = this.props.selected[0].path === "/" ? this.props.selected[0].path + this.props.selected[0].name : this.props.selected[0].path + "/" + this.props.selected[0].name; switch (isPreviewable(this.props.selected[0].name)) { case "img": this.props.showImgPreivew(this.props.selected[0]); return; case "msDoc": if (isShare) { this.props.history.push( this.props.selected[0].key + "/doc?name=" + encodeURIComponent(this.props.selected[0].name) + "&share_path=" + encodeURIComponent(previewPath) ); return; } this.props.history.push( "/doc?p=" + encodeURIComponent(previewPath) + "&id=" + this.props.selected[0].id ); return; case "audio": this.props.openMusicDialog(); return; case "video": if (isShare) { this.props.history.push( this.props.selected[0].key + "/video?name=" + encodeURIComponent(this.props.selected[0].name) + "&share_path=" + encodeURIComponent(previewPath) ); return; } this.props.history.push( "/video?p=" + encodeURIComponent(previewPath) + "&id=" + this.props.selected[0].id ); return; case "pdf": if (isShare) { this.props.history.push( this.props.selected[0].key + "/pdf?name=" + encodeURIComponent(this.props.selected[0].name) + "&share_path=" + encodeURIComponent(previewPath) ); return; } this.props.history.push( "/pdf?p=" + encodeURIComponent(previewPath) + "&id=" + this.props.selected[0].id ); return; case "edit": if (isShare) { this.props.history.push( this.props.selected[0].key + "/text?name=" + encodeURIComponent(this.props.selected[0].name) + "&share_path=" + encodeURIComponent(previewPath) ); return; } this.props.history.push( "/text?p=" + encodeURIComponent(previewPath) + "&id=" + this.props.selected[0].id ); return; case "code": if (isShare) { this.props.history.push( this.props.selected[0].key + "/code?name=" + encodeURIComponent(this.props.selected[0].name) + "&share_path=" + encodeURIComponent(previewPath) ); return; } this.props.history.push( "/code?p=" + encodeURIComponent(previewPath) + "&id=" + this.props.selected[0].id ); return; default: return; } }; render() { const { classes } = this.props; const user = Auth.GetUser(); const isHomePage = pathHelper.isHomePage(this.props.location.pathname); return (