diff --git a/package-lock.json b/package-lock.json index 1c5d1e40..2c5f2c41 100644 --- a/package-lock.json +++ b/package-lock.json @@ -14939,8 +14939,8 @@ }, "react-player": { "version": "1.15.3", - "resolved": "https://registry.npmjs.org/react-player/-/react-player-1.15.3.tgz", - "integrity": "sha512-8fc0R1AipFIy7l4lKgnIg+gMU2IY32ZMxxBlINjXAq/YnN3HUP3hOaE+aQ0lQv+a1/MMZgbekWD86ZGDO7kB8g==", + "resolved": "https://registry.npm.taobao.org/react-player/download/react-player-1.15.3.tgz", + "integrity": "sha1-0AzxRfnIYYTLCgcaH7+Oy3tomH8=", "requires": { "deepmerge": "^4.0.0", "load-script": "^1.0.0", @@ -14949,8 +14949,8 @@ "dependencies": { "deepmerge": { "version": "4.2.2", - "resolved": "https://registry.npmjs.org/deepmerge/-/deepmerge-4.2.2.tgz", - "integrity": "sha512-FJ3UgI4gIl+PHZm53knsuSFpE+nESMr7M4v9QcgB7S63Kj/6WqMiFQJpBBYz1Pt+66bZpP3Q7Lye0Oo9MPKEdg==" + "resolved": "https://registry.npm.taobao.org/deepmerge/download/deepmerge-4.2.2.tgz", + "integrity": "sha1-RNLqNnm49NT/ujPwPYZfwee/SVU=" } } }, diff --git a/package.json b/package.json index 0bcaa7fc..0b17601d 100644 --- a/package.json +++ b/package.json @@ -14,7 +14,6 @@ "babel-eslint": "7.2.3", "babel-jest": "20.0.3", "babel-loader": "7.1.2", - "code-prettify": "^0.1.0", "babel-plugin-syntax-dynamic-import": "^6.18.0", "babel-preset-react-app": "^3.1.1", "babel-runtime": "6.26.0", @@ -24,6 +23,7 @@ "chalk": "1.1.3", "classnames": "^2.2.5", "clipboard": "^2.0.6", + "code-prettify": "^0.1.0", "codemirror": "^5.53.0", "connected-react-router": "4.4.1", "css-loader": "^3.5.2", diff --git a/src/AppConfig.js b/src/AppConfig.js index dadadc5f..153780b3 100644 --- a/src/AppConfig.js +++ b/src/AppConfig.js @@ -64,8 +64,8 @@ export function initAxiosInterceptors(props) { initOnlineOfflineListener() // TODO 避免重复的请求 https://github.com/axios/axios#cancellation var - proxy = "http://localhost:3000" - proxy = "https://testforgeplus.trustie.net" + // proxy = "http://localhost:3000" + proxy = "https://forgeplus.trustie.net" const requestMap = {}; window.setfalseInRequestMap = function (keyName) { diff --git a/src/forge/Upload/attachment.js b/src/forge/Upload/attachment.js index 664fa15c..78e9871c 100644 --- a/src/forge/Upload/attachment.js +++ b/src/forge/Upload/attachment.js @@ -1,82 +1,187 @@ -import React, { Component } from 'react'; -import {Link} from 'react-router-dom'; +import React, { Component } from "react"; +import { Link } from "react-router-dom"; import axios from "axios"; -import {Popconfirm} from "antd"; -class Attachment extends Component{ - constructor(props){ +import { Popconfirm, Modal, Spin } from "antd"; +import Videos from "./videos"; +class Attachment extends Component { + constructor(props) { super(props); - this.state={ + this.state = { canDelete: false, - Deleted:[] - } + show_video: false, + video_url: undefined, + video_title: undefined, + video_id: undefined, + move_spin: false, + Deleted: [], + }; } - componentDidMount=()=>{ + componentDidMount = () => { this.getDetail(); - } + }; - getDetail=()=>{ + getDetail = () => { this.setState({ - canDelete: this.props.canDelete - }) - } + canDelete: this.props.canDelete, + }); + }; + + show_video_modal = (item) => { + this.setState({ + video_title: item.title, + move_spin: true, + video_id: item.id, + }); + this.move_attachment(item.id, "preview"); + }; + hide_video_modal = () => { + const { video_id } = this.state; + this.setState({ + video_title: undefined, + }); + this.move_attachment(video_id, "close"); + }; + + move_attachment = (id, status) => { + axios + .post(`/attachments/${id}/preview_attachment`, { status: status }) + .then((result) => { + if (result) { + this.setState({ + show_video: status === "preview", + video_url: + status === "preview" + ? "https://forgeplus.trustie.net" + result.data.url + : undefined, + move_spin: false, + }); + } else { + this.setState({ + move_spin: false, + }); + } + }) + .catch((error) => { + this.setState({ + move_spin: false, + }); + console.log(error); + }); + }; + + is_video = (name) => { + const video_names = ["mp4", "flv", "mkv", "3gp"]; + return video_names.indexOf(name.split(".").pop()) > -1; + }; deleteAttachment = (id) => { - const url = `/attachments/${id}.json` - axios.delete(url, { - }).then((response) => { - if (response.data) { - if (response.data.status === 0) { - this.setState({ - Deleted: this.state.Deleted.concat(id) - }); - this.props.showNotification("附件删除成功") - }else{ - this.props.showNotification(response.data.message) + const url = `/attachments/${id}.json`; + axios + .delete(url, {}) + .then((response) => { + if (response.data) { + if (response.data.status === 0) { + this.setState({ + Deleted: this.state.Deleted.concat(id), + }); + this.props.showNotification("附件删除成功"); + } else { + this.props.showNotification(response.data.message); + } } - } - }).catch(function (error) { - console.log(error); - }); - } + }) + .catch(function (error) { + console.log(error); + }); + }; - render(){ - const { Deleted , canDelete } = this.state; - const { attachments }= this.props - return( + render() { + const { + Deleted, + canDelete, + show_video, + video_url, + video_title, + move_spin, + } = this.state; + const { attachments } = this.props; + return (