From da7b009af429fcbdb0cdc2f2b2b5b6a1bd1ab4ca Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=E6=9D=A8=E6=A0=91=E6=98=8E?= <775174143@qq.com>
Date: Sat, 6 Jul 2019 14:54:21 +0800
Subject: [PATCH] =?UTF-8?q?=E8=B0=83=E6=95=B4?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.../shixunHomework/ShixunhomeWorkItem.js | 4 +-
.../tpm/challengesnew/TPMchallengesnew.js | 192 +-----
.../modules/tpm/shixuns/ShixunSearchBar.js | 612 +++++++++---------
.../src/modules/tpm/shixuns/ShixunsIndex.js | 16 +-
4 files changed, 334 insertions(+), 490 deletions(-)
diff --git a/public/react/src/modules/courses/shixunHomework/ShixunhomeWorkItem.js b/public/react/src/modules/courses/shixunHomework/ShixunhomeWorkItem.js
index 3a2366848..459a88e5e 100644
--- a/public/react/src/modules/courses/shixunHomework/ShixunhomeWorkItem.js
+++ b/public/react/src/modules/courses/shixunHomework/ShixunhomeWorkItem.js
@@ -356,9 +356,9 @@ class ShixunhomeWorkItem extends Component{
`
}
- {this.props.isAdmin?
+ {this.props.isAdmin?
:""}
diff --git a/public/react/src/modules/tpm/challengesnew/TPMchallengesnew.js b/public/react/src/modules/tpm/challengesnew/TPMchallengesnew.js
index 465454128..7923f0702 100644
--- a/public/react/src/modules/tpm/challengesnew/TPMchallengesnew.js
+++ b/public/react/src/modules/tpm/challengesnew/TPMchallengesnew.js
@@ -6,6 +6,8 @@ import {BrowserRouter as Router, Route, Link, Switch} from "react-router-dom";
// import "antd/dist/antd.css";
+import TPMMDEditor from '../../tpm/challengesnew/TPMMDEditor';
+
import axios from 'axios';
import './css/TPMchallengesnew.css';
@@ -28,129 +30,10 @@ const Option = Select.Option;
const RadioGroup = Radio.Group;
-// 恢复数据
-function md_rec_data(k,mdu,id, editor){
- if(window.sessionStorage.getItem(k+mdu) !== null){
- editor.setValue(window.sessionStorage.getItem(k+mdu));
- md_clear_data(k,mdu,id);
- }
-}
-
-// 保存数据
-function md_add_data(k,mdu,d){
- window.sessionStorage.setItem(k+mdu,d);
-}
-
-// 清空保存的数据
-function md_clear_data(k,mdu,id){
- window.sessionStorage.removeItem(k+mdu);
- var id1 = "#e_tip_"+id;
- var id2 = "#e_tips_"+id;
- if(k == 'content'){
- $(id2).html("");
- }else{
- $(id1).html("");
- }
-}
-
-function md_elocalStorage(editor,mdu,id){
- if (window.sessionStorage){
- var oc = window.sessionStorage.getItem('content'+mdu);
- if(oc !== null ){
-
- $("#e_tips_"+id).data('editor', editor);
- var h = '您上次有已保存的数据,是否
恢复 ? /
不恢复';
- $("#e_tips_"+id).html(h);
- }
- setInterval(function() {
- var d = new Date();
- var h = d.getHours();
- var m = d.getMinutes();
- var s = d.getSeconds();
- h = h < 10 ? '0' + h : h;
- m = m < 10 ? '0' + m : m;
- s = s < 10 ? '0' + s : s;
- if(editor.getValue().trim() != ""){
- md_add_data("content",mdu,editor.getValue());
- var id1 = "#e_tip_"+id;
- var id2 = "#e_tips_"+id;
-
- $(id1).html(" 数据已于 " + h + ':' + m + ':' + s +" 保存 ");
- $(id2).html("");
- }
- },10000);
-
- }else{
- $("#e_tip_"+id).after('您的浏览器不支持localStorage.无法开启自动保存草稿服务,请升级浏览器!');
- }
-}
-
-
-function create_editorMD(id, width, high, placeholder, imageUrl, callback) {
- var editorName = window.editormd(id, {
- width: width,
- height: high,
- path: path, // "/editormd/lib/"
-
- syncScrolling: "single",
- tex: true,
- tocm: true,
- emoji: true,
- taskList: true,
- codeFold: true,
- searchReplace: true,
- htmlDecode: "style,script,iframe",
- sequenceDiagram: true,
- autoFocus: false,
- toolbarIcons: function () {
- // Or return editormd.toolbarModes[name]; // full, simple, mini
- // Using "||" set icons align right.
- return ["bold", "italic", "|", "list-ul", "list-ol", "|", "code", "code-block", "|", "testIcon", "testIcon1", '|', "image", "table", '|', "watch", "clear"]
- },
- toolbarCustomIcons: {
- testIcon: "
",
- testIcon1: "
"
- },
- //这个配置在simple.html中并没有,但是为了能够提交表单,使用这个配置可以让构造出来的HTML代码直接在第二个隐藏的textarea域中,方便post提交表单。
- saveHTMLToTextarea: true,
- // 用于增加自定义工具栏的功能,可以直接插入HTML标签,不使用默认的元素创建图标
- dialogMaskOpacity: 0.6,
- placeholder: placeholder,
- imageUpload: true,
- imageFormats: ["jpg", "jpeg", "gif", "png", "bmp", "webp", "JPG", "JPEG", "GIF", "PNG", "BMP", "WEBP"],
- imageUploadURL: imageUrl,//url
- onload: function () {
- // this.previewing();
- $("#" + id + " [type=\"latex\"]").bind("click", function () {
- editorName.cm.replaceSelection("```latex");
- editorName.cm.replaceSelection("\n");
- editorName.cm.replaceSelection("\n");
- editorName.cm.replaceSelection("```");
- var __Cursor = editorName.cm.getDoc().getCursor();
- editorName.cm.setCursor(__Cursor.line - 1, 0);
- });
-
- $("#" + id + " [type=\"inline\"]").bind("click", function () {
- editorName.cm.replaceSelection("$$$$");
- var __Cursor = editorName.cm.getDoc().getCursor();
- editorName.cm.setCursor(__Cursor.line, __Cursor.ch - 2);
- editorName.cm.focus();
- });
- $("[type=\"inline\"]").attr("title", "行内公式");
- $("[type=\"latex\"]").attr("title", "多行公式");
-
- md_elocalStorage(editorName, `exercise__${id}`, "Memochallengesnew");
-
- callback && callback()
- }
- });
- return editorName;
-}
-
-
export default class TPMchallengesnew extends Component {
constructor(props) {
super(props)
+ this.exercisememoMDRef=React.createRef();
this.state = {
choice_url: undefined,
practice_url: undefined,
@@ -180,52 +63,6 @@ export default class TPMchallengesnew extends Component {
}
- exerciseMD(initValue, id) {
-
- this.contentChanged = false;
- const placeholder = "";
- // amp;
- // 编辑时要传memoId
- const imageUrl = `/api/attachments.json`;
- // 创建editorMd
-
- const exercise_editormd = create_editorMD(id, '100%', 400, placeholder, imageUrl, () => {
- setTimeout(() => {
- exercise_editormd.resize()
- exercise_editormd.cm && exercise_editormd.cm.refresh()
- }, 500)
-
- if (initValue != undefined) {
- exercise_editormd.setValue(initValue)
- }
- exercise_editormd.cm.on("change", (_cm, changeObj) => {
- console.log('....contentChanged')
- this.contentChanged = true;
- })
- });
- this.exercise_editormd = exercise_editormd;
- window.exercise_editormd = exercise_editormd;
-
- }
-
- formatSearch = (url) => {
- if (typeof url !== "undefined") {
- url = url.substr(1); //从起始索引号提取字符串中指定数目的字符
- var arr = url.split("&"), //把字符串分割为字符串数组
- obj = {},
- newarr = [];
- arr.forEach(function (v, i) { //数组遍历
- // console.log(v);
- // console.log(i);
- newarr = v.split("=");
- if (typeof obj[newarr[0]] === "undefined") {
- obj[newarr[0]] = newarr[1];
- }
- });
- return obj;
- }
- ;
- }
componentDidMount() {
let id = this.props.match.params.shixunId;
let checkpointId=this.props.match.params.checkpointId;
@@ -244,9 +81,11 @@ export default class TPMchallengesnew extends Component {
position: response.data.position,
task_pass_default: response.data.task_pass_default,
submit_url: response.data.submit_url,
- checkpointId:checkpointId
+ checkpointId:checkpointId,
+ exercisememoMDRefval:response.data.task_pass_default
})
- this.exerciseMD(response.data.task_pass_default, "exercisememoMD");
+
+ this.exercisememoMDRef.current.setValue(response.data.task_pass_default||'')
}).catch((error) => {
console.log(error)
});
@@ -296,11 +135,13 @@ export default class TPMchallengesnew extends Component {
exec_time:response.data.exec_time,
tab2url: "/shixuns/" + id + "/challenges/"+checkpointId+"/tab=2",
tab3url: "/shixuns/" + id + "/challenges/"+checkpointId+"/tab=3",
+ exercisememoMDRefval:response.data.task_pass
})
if(response.data.power===false){
this.props.showSnackbar("你没有权限修改");
}
- this.exerciseMD(response.data.task_pass, "exercisememoMD");
+
+ this.exercisememoMDRef.current.setValue(response.data.task_pass||'')
}).catch((error) => {
console.log(error)
});
@@ -372,8 +213,7 @@ export default class TPMchallengesnew extends Component {
return
}
- const exercise_editormdvalue = this.exercise_editormd.getValue();
-
+ const exercise_editormdvalue = this.exercisememoMDRef.current.getValue().trim();
let id = this.props.match.params.shixunId;
let url = "/shixuns/" + id + "/challenges.json";
@@ -457,7 +297,7 @@ export default class TPMchallengesnew extends Component {
let {shixunCreatePractice, shixunCreatePracticeGroup, onshixunsmarkvalue, shixunsskillvaluelist,checkpointId,exec_time} = this.state;
- const exercise_editormdvalue = this.exercise_editormd.getValue();
+ const exercise_editormdvalue = this.exercisememoMDRef.current.getValue().trim();
let id = this.props.match.params.shixunId;
@@ -631,11 +471,9 @@ export default class TPMchallengesnew extends Component {
过关任务
-
+
+
diff --git a/public/react/src/modules/tpm/shixuns/ShixunSearchBar.js b/public/react/src/modules/tpm/shixuns/ShixunSearchBar.js
index 1f0e46d92..b05732e31 100644
--- a/public/react/src/modules/tpm/shixuns/ShixunSearchBar.js
+++ b/public/react/src/modules/tpm/shixuns/ShixunSearchBar.js
@@ -1,306 +1,306 @@
-import React, { Component } from 'react';
-
-import { Select, Input } from 'antd';
-
-import 'antd/lib/style/index.css';
-
-import 'antd/lib/select/style/index.css';
-
-import 'antd/lib/input/style/index.css';
-
-import './shixunCss/ShixunSearchBar.css';
-
-import axios from 'axios';
-
-const $ = window.$;
-
-const Option = Select.Option;
-
-const Search = Input.Search;
-
-
-class ShixunSearchBar extends Component {
-
- constructor(props) {
- super(props)
- this.state = {
- status: undefined,
- diff: undefined,
- InputValue: undefined,
- shixunhoverData: [],
- shixunchildValues:'',
- shixunsearchAllvalue:"a",
- openStatus:false,
- openLevel:false
- }
-}
-
- //状态筛选
- status_search = (value) => {
- let newvalue = value;
- if (newvalue === "0") {
- newvalue = " "
- } else if (newvalue === "1") {
- newvalue = 2
- } else if (newvalue === "2") {
- newvalue = 1
- } else if (newvalue === "3") {
- newvalue = 3
- }
-
- this.setState({
- status: newvalue,
- openStatus:false
- })
- let list = [{'type': 1}, {'value': newvalue}];
- this.props.StatusEnquiry(list);
-}
-
- //难度筛选
-diff_search = (value) => {
- this.setState({
- diff: value,
- openLevel:false
- })
- let list=[{'type':2},{'value':value}];
- this.props.StatusEnquiry(list);
-}
-
- //输入框搜索
-Input_search = (value) => {
- this.setState({
- InputValue: value
- })
- this.props.OnSearchInput(value);
-}
- //查询
-shixunsearchAll = (e) => {
- let{shixunsearchAllvalue}=this.state;
- let id = e.target.value;
-
- if(shixunsearchAllvalue===id){
- return
- }
- if(id===0){
- id=" "
- this.setState({
- InputValue: " "
- })
- this.props.OnSearchInput("");
- }
- let list=[{'tag_level':1},{'tag_id':id}];
- if(id!=undefined){
- this.setState({
- shixunsearchAllvalue:id,
- shixunchildValues:""
- })
- this.props.Updatasearchlist(list);
- }
-
-}
-
- shixunsearchall=(e)=>{
- let{shixunsearchAllvalue}=this.state;
- let id = "a";
-
- if(shixunsearchAllvalue===id){
- return
- }
- this.setState({
- shixunsearchAllvalue:"a",
- shixunchildValues:""
- })
- this.props.allUpdatashixunlist();
- }
-
- //选择Tab页详情
-getshixunchildValue = (e) => {
- let id = e.target.name;
- let newid=e.target.id;
- let list=[{'tag_level':2},{'tag_id':id}];
- if(id!=undefined||newid!=undefined){
- this.setState({
- shixunsearchAllvalue:newid
- })
- this.props.Updatasearchlist(list);
- }
-}
-
-getshixunchildValues = (e) => {
- let id = e.target.id;
- let newid=e.target.name;
- let list=[{'tag_level':3},{'tag_id':id}];
- if(id!=undefined||newid!=undefined){
- this.setState({
- shixunchildValues:id,
- shixunsearchAllvalue:newid
- })
- this.props.Updatasearchlist(list);
- }
-
-}
-
-componentDidMount() {
- let hoverUrlArr = [];
- let hoverUrl = `/shixuns/menus.json`;
- axios.get(hoverUrl
- ).then((response) => {
- hoverUrlArr = response.data;
- hoverUrlArr.reverse();
- this.setState({
- shixunhoverData: hoverUrlArr
- })
- }).catch((error) => {
- console.log(error)
- })
-}
-
-
- // componentWillReceiveProps(nextProps) {
- // console.log(nextProps.parsedid)
- // if(nextProps.newtag_level===1){
- // this.setState({
- // InputValue: this.props.keyword,
- // shixunsearchAllvalue:nextProps.parsedid
- //
- // })
- // }else if(nextProps.newtag_level===2){
- // this.setState({
- // InputValue: this.props.keyword,
- // shixunsearchAllvalue:nextProps.newpalce,
- // shixunchildValues:nextProps.parsedid
- //
- // })
- // }else if(nextProps.newtag_level===3){
- // this.setState({
- // InputValue: this.props.keyword,
- // shixunsearchAllvalue:nextProps.newpalce,
- // shixunchildValues:nextProps.parsedid
- //
- // })
- // }
- //
- //
- // }
- openStatusOption=()=>{
- this.setState({
- openLevel:false,
- openStatus:true
- })
- }
- openLevelOption=()=>{
- this.setState({
- openLevel:true,
- openStatus:false
- })
- }
- openStatusOptions=()=>{
- this.setState({
- openLevel:false,
- openStatus:false
- })
- }
-
- Input_searchs = (e) => {
- this.setState({
- InputValue: e.target.value
- })
- }
-render() {
- let {shixunhoverData, shixunchildValues, shixunsearchAllvalue, InputValue,openStatus,openLevel} = this.state;
- let {typepvisible} = this.props;
- //实训首页筛选的移入和点击事件
- $(".shaiItem").hover(function(){
- var hei=parseInt($(".shaiAllItem").height())-2;
- $(this).find(".subshaicontent").css("top", '34px');
- $(this).find(".subshaicontent").show();
- },function(){
- $(this).find(".subshaicontent").hide();
- });
-
- $(".shaiItem").live("click",function(){
- $(".shaiItem").removeClass("active");
- $(this).addClass("active");
- $(".subshaicontent").hide();
- });
-
- $(".subshaicontent").live("click", function(event){
- $(".subshaicontent").hide();
- event.stopPropagation();
- });
- return (
-