import React, { Component } from 'react'; import {getImageUrl,markdownToHTML} from 'educoder'; import DetailTop from './DetailTop.js'; import DetailCards from './DetailCards.js' import AddCollaborators from "./addCollaborators.js"; import {Icon,Tooltip} from 'antd'; import { BrowserRouter as Router, Route, Link } from "react-router-dom"; import { DragDropContext , Draggable, Droppable} from 'react-beautiful-dnd'; import '../../paths/ShixunPaths.css'; import "antd/dist/antd.css"; import Modals from '../../modals/Modals'; import axios from 'axios'; import TPMRightSection from "../../tpm/component/TPMRightSection"; import styled from "styled-components"; const getItemStyle = (isDragging, draggableStyle) => ({ // change background colour if dragging background: isDragging ? '#dceeff' : '', // styles we need to apply on draggables ...draggableStyle, }); const getItems = count => Array.from({ length: count }, (v, k) => k).map(k => ({ id: `item-${k}`, content: `item ${k}` })); // a little function to help us with reordering the result const reorder = (list, startIndex, endIndex) => { const result = Array.from(list); const [removed] = result.splice(startIndex, 1); result.splice(endIndex, 0, removed); return result; }; const List = styled.div` background: lightgrey; padding: 10px; `; const Item = styled.div` display: flex; align-items: center; padding: 10px; margin-bottom: 10px; border: 1px solid grey; background: white; &:hover { background: lightgrey; } `; const DragHandle = styled.div` width: 15px; height: 15px; margin-right: 8px; background: grey; visibility: hidden; &:hover { background: black; } ${Item}:hover & { visibility: visible; } `; const $ =window.$ class PathDetailIndex extends Component{ constructor(props){ super(props) this.state={ detailInfoList:undefined, clickdetailInfoListtype:false, Modalstype:false, Modalstopval:undefined, Modalsbottomval:undefined, cardsModalcancel:this.cardsModalcancel, cardsModalsave:this.cardsModalsave, user_id:undefined, loadtype:false, items: getItems(10) } this.onDragEnd = this.onDragEnd.bind(this); } onDragEnd(result) { // dropped outside the list if (!result.destination) { return; } try { }catch (e) { } const items = reorder( this.state.detailInfoList.members, result.source.index, result.destination.index ); this.state.detailInfoList.members=items; this.setState({ detailInfoList:this.state.detailInfoList, items }); console.log(this.state.detailInfoList.members) console.log("items 数组数组数组数组") console.log(items) } cardsModalcancel=()=>{ this.setState({ Modalstype:false, }) // TODO 这个是临时处理,还需要优化,这里要看怎么区分处理 if (this.state.Modalstopval == '你确定要删除该成员吗?') { return; } this.props.history.goBack() } cardsModalsave=()=>{ this.setState({ Modalstype:false, }) this.props.history.goBack() } // 加载markdown updatamakedown=(id)=>{ setTimeout(()=>{ var shixunDescr = window.editormd.markdownToHTML(id, { htmlDecode: "style,script,iframe", taskList: true, tex: true, flowChart: true, sequenceDiagram: true }); $("#"+id+" p:first").addClass("ReactMarkdown"); }, 200) } componentDidMount(){ let pathid=this.props.match.params.pathId; let url="/paths/"+pathid+".json"; axios.get(url).then((result)=>{ if (result.data.status === 407 || result.data.status === 401) { debugger return; } if (result.data.status === 403) { debugger // window.location.href = "/403"; return; } if(result.data.allow_visit===true){ this.setState({ detailInfoList:result.data, items: getItems(result.data.members.length), }) } }).catch((error)=>{ console.log(error); }) } updatadetailInfoList=()=>{ let pathid=this.props.match.params.pathId; let url="/paths/"+pathid+".json"; axios.get(url).then((result)=>{ // TODO 403 让后台返回status 403 比较好 if (result.data.status == 407 || result.data.status == 401) { debugger return; } if (result.data.status === 403 ) { debugger // window.location.href = "/403"; return; } if(result.data.allow_visit===true){ this.setState({ detailInfoList:result.data, items: getItems(result.data.members.length), user_id:undefined, }) } }).catch((error)=>{ console.log(error); }) } clickNewsubscript=(val)=>{ if(val===0){ this.setState({ clickdetailInfoListtype:true }) }else{ this.setState({ clickdetailInfoListtype:false }) } } timeStamp=(value)=>{ var secondTime = parseInt(value);// 秒 var minuteTime = 0;// 分 var hourTime = 0;// 小时 if(secondTime > 60) {//如果秒数大于60,将秒数转换成整数 //获取分钟,除以60取整数,得到整数分钟 minuteTime = parseInt(secondTime / 60); //获取秒数,秒数取佘,得到整数秒数 secondTime = parseInt(secondTime % 60); //如果分钟大于60,将分钟转换成小时 if(minuteTime > 60) { //获取小时,获取分钟除以60,得到整数小时 hourTime = parseInt(minuteTime / 60); //获取小时后取佘的分,获取分钟除以60取佘的分 minuteTime = parseInt(minuteTime % 60); } } var result = "" + parseInt(secondTime) + "秒"; if(minuteTime > 0) { result = "" + parseInt(minuteTime) + "分" + result; } if(hourTime > 0) { result = "" + parseInt(hourTime) + "小时" + result; } return result; } shanchuallow=(id)=>{ this.setState({ user_id:id, Modalstype:true, Modalstopval:"你确定要删除该成员吗?", cardsModalsave:this.delectshanchuallow, loadtype:false }) } delectshanchuallow=()=>{ let{user_id}=this.state; let pathid=this.props.match.params.pathId; let url="/paths/"+pathid+"/delete_member.json"; let param={user_id:user_id}; axios.delete(url,{data:param}).then((response) => { if(response.data.status===1){ this.props.showNotification(response.data.message) this.setState({ Modalstype:false, // Modalstopval:response.data.message, loadtype:false, // cardsModalsave:this.cardsModalsave, }) this.updatadetailInfoList(); } }).catch((error) => { console.log(error) }) } //上移 moveup=(data)=>{ // console.log(data); let pathid=this.props.match.params.pathId; let url=`/paths/${pathid}/up_member_position.json`; axios.post(url,{ user_id:data.id }).then((response) => { if(response.status === 200){ console.log("上移"); // console.log(this.state.detailInfoList.members); // console.log(response); this.state.detailInfoList.members=response.data.members; this.setState({ detailInfoList:this.state.detailInfoList, }); // console.log(this.state.detailInfoList.members); } }).catch((error) => { console.log(error) }) } //下移 movedown =(data) => { // console.log(data); let pathid=this.props.match.params.pathId; let url=`/paths/${pathid}/down_member_position.json`; axios.post(url,{ user_id:data.id }).then((response) => { if( response.status === 200){ console.log("下移"); // console.log(this.state.detailInfoList.members); // console.log(response); this.state.detailInfoList.members=response.data.members; this.setState({ detailInfoList:this.state.detailInfoList, }); // console.log(this.state.detailInfoList.members); } }).catch((error) => { console.log(error) }) } render(){ this.updatamakedown("shixuns_propaedeutics"); this.updatamakedown("subject_learning_notes"); let {detailInfoList, clickdetailInfoListtype, Modalstype, Modalstopval, Modalsbottomval, cardsModalcancel, cardsModalsave, loadtype } = this.state return(

简介 {detailInfoList===undefined?"":detailInfoList.allow_statistics===true? :"" }

{detailInfoList === undefined ? "" :detailInfoList.description===null?"":
}

课程须知 {detailInfoList===undefined?"":detailInfoList.allow_statistics===true? :"" }

{detailInfoList === undefined ? "" :detailInfoList.learning_notes===null?"": }
{detailInfoList === undefined ? "" : detailInfoList.tags === null ? "":

技能标签 {detailInfoList.tags.length}

{ detailInfoList.tags && detailInfoList.tags.map((item,key)=>{ return( {item.tag_name} ) }) }
15&&clickdetailInfoListtype===false?"newsubscript mb9 color-grey-9 fr":"newsubscript mb9 color-grey-9 none"} onClick={()=>this.clickNewsubscript(0)} >...
this.clickNewsubscript(1)}>
} { this.props.checkIfLogin()===false?"":detailInfoList === undefined ? "" : detailInfoList.progress === null ? "" :

我的进展 {detailInfoList.progress.my_score} / {detailInfoList.progress.all_score}

已学 {detailInfoList.progress.learned}% 学习耗时{this.timeStamp(detailInfoList.progress.time)}

} { detailInfoList ===undefined ?"":detailInfoList.members === null ?"":

教学团队

{ detailInfoList===undefined? detailInfoList.members && detailInfoList.members.map((item,key)=>{ return(
头像

{item.name} {/*{*/} {/* detailInfoList===undefined?"":detailInfoList.allow_add_member===true?*/} {/* this.shanchuallow(item.id)}>:""*/} {/*}*/}

{item.school}{item.identity}

) }) :detailInfoList.allow_add_member===true? detailInfoList.members && detailInfoList.members.map((item,key)=>{ return(
头像

{item.name} {/* 新增role 判断是否能删除 1 管理员 2 合作者 */} { detailInfoList===undefined?"":detailInfoList.allow_add_member===true && item.role == 2? this.shanchuallow(item.id)}>:"" }

{item.school}{item.identity}

{ detailInfoList===undefined?"":detailInfoList.allow_add_member===true? :"" }
) }) : detailInfoList.members && detailInfoList.members.map((item,key)=>{ return(
头像

{item.name} {/*{*/} {/* detailInfoList===undefined?"":detailInfoList.allow_add_member===true?*/} {/* this.shanchuallow(item.id)}>:""*/} {/*}*/}

{item.school}{item.identity}

) })}
}
) } } export default PathDetailIndex;