import React, { Component } from "react"; import { connect } from "react-redux"; import { sizeToString } from "../../untils"; import { openMusicDialog, openResaveDialog, setSelectedTarget, showImgPreivew, toggleSnackbar } from "../../actions"; import { isPreviewable } from "../../config"; import { withStyles, Button, Typography } from "@material-ui/core"; import Divider from "@material-ui/core/Divider"; import TypeIcon from "../FileManager/TypeIcon"; import Auth from "../../middleware/Auth"; import API from "../../middleware/Api"; import { withRouter } from "react-router-dom"; import Creator from "./Creator"; import pathHelper from "../../untils/page"; const styles = theme => ({ layout: { width: "auto", marginTop: "90px", marginLeft: theme.spacing(3), marginRight: theme.spacing(3), [theme.breakpoints.up(1100 + theme.spacing(3) * 2)]: { width: 1100, marginTop: "90px", marginLeft: "auto", marginRight: "auto" }, [theme.breakpoints.down("sm")]: { marginTop: 0, marginLeft: 0, marginRight: 0 }, justifyContent: "center", display: "flex" }, player: { borderRadius: "4px" }, fileCotainer: { width: "200px", margin: "0 auto" }, buttonCotainer: { width: "400px", margin: "0 auto", textAlign: "center", marginTop: "20px" }, paper: { padding: theme.spacing(2) }, icon: { borderRadius: "10%", marginTop: 2 }, box: { width: "100%", maxWidth: 440, backgroundColor: theme.palette.background.paper, borderRadius: 12, boxShadow: "0 8px 16px rgba(29,39,55,.25)", [theme.breakpoints.down("sm")]: { height: "calc(100vh - 56px)", borderRadius: 0, maxWidth: 1000 }, display: "flex", flexDirection: "column" }, boxContent: { padding: 24, display: "flex", flex: "1" }, fileName: { marginLeft: 20 }, fileSize: { color: theme.palette.text.disabled, fontSize: 14 }, boxFooter: { display: "flex", padding: "20px 16px", justifyContent: "space-between" }, downloadButton: { marginLeft: 8 } }); const mapStateToProps = state => { return {}; }; const mapDispatchToProps = dispatch => { return { toggleSnackbar: (vertical, horizontal, msg, color) => { dispatch(toggleSnackbar(vertical, horizontal, msg, color)); }, openMusicDialog: () => { dispatch(openMusicDialog()); }, setSelectedTarget: targets => { dispatch(setSelectedTarget(targets)); }, showImgPreivew: first => { dispatch(showImgPreivew(first)); }, openResave: (key) => { dispatch(openResaveDialog(key)); }, }; }; const Modals = React.lazy(() => import("../FileManager/Modals")); const ImgPreview = React.lazy(() => import("../FileManager/ImgPreview")); class SharedFileCompoment extends Component { state = { anchorEl: null, open: false, purchaseCallback: null, loading: false }; downloaded = false; preview = () => { if (pathHelper.isSharePage(this.props.location.pathname)) { let user = Auth.GetUser(); if (!Auth.Check() && user && !user.group.shareDownload) { this.props.toggleSnackbar( "top", "right", "请先登录", "warning" ); return; } } switch (isPreviewable(this.props.share.source.name)) { case "img": this.props.showImgPreivew({ key: this.props.share.key, name: this.props.share.source.name }); return; case "msDoc": this.props.history.push( this.props.share.key + "/doc?name=" + encodeURIComponent(this.props.share.source.name) ); return; case "audio": this.props.setSelectedTarget([ { key: this.props.share.key, type: "share" } ]); this.props.openMusicDialog(); return; case "video": this.props.history.push( this.props.share.key + "/video?name=" + encodeURIComponent(this.props.share.source.name) ); return; case "edit": this.props.history.push(this.props.share.key + "/text?name=" + encodeURIComponent(this.props.share.source.name)); return default: this.props.toggleSnackbar( "top", "right", "此文件无法预览", "warning" ); return; } }; componentWillUnmount() { this.props.setSelectedTarget([]); } scoreHandle = callback => event => { callback(event); }; download = e => { this.setState({ loading: true }); API.put("/share/download/" + this.props.share.key) .then(response => { this.downloaded = true; window.location.assign(response.data); }) .catch(error => { this.props.toggleSnackbar( "top", "right", error.message, "warning" ); }) .finally(() => { this.setState({ loading: false }); }); }; render() { const { classes } = this.props; const user = Auth.GetUser(); const isLogin = Auth.Check(); return (
{this.props.share.source.name} {sizeToString(this.props.share.source.size)}
{this.props.share.preview && ( )}
{/*
*/} {/* */} {/*
*/} {/*
*/} {/* */} {/* 预览*/} {/* */} {/* */} {/* 信息*/} {/* */} {/* */} {/* {({ TransitionProps }) => (*/} {/* */} {/* */} {/* */} {/* 此分享被浏览{this.props.share.views}*/} {/* 次,被下载{this.props.share.downloads}次*/} {/* */} {/* */} {/* */} {/* )}*/} {/* */} {/*
*/}
); } } const SharedFile = connect( mapStateToProps, mapDispatchToProps )(withStyles(styles)(withRouter(SharedFileCompoment))); export default SharedFile;