From 7b430d825782c1f7f15cbe53936655cda5bdadf4 Mon Sep 17 00:00:00 2001 From: caishi <1149225589@qq.com> Date: Tue, 18 Apr 2023 15:31:51 +0800 Subject: [PATCH] md --- .../tpm/challengesnew/tpm-md-editor.js | 596 ++++++++++++++++-- .../tpm/challengesnew/tpm-md-editor1.js | 273 ++++++++ 2 files changed, 825 insertions(+), 44 deletions(-) create mode 100644 src/modules/tpm/challengesnew/tpm-md-editor1.js diff --git a/src/modules/tpm/challengesnew/tpm-md-editor.js b/src/modules/tpm/challengesnew/tpm-md-editor.js index 157f0e94e..af89ed0b2 100644 --- a/src/modules/tpm/challengesnew/tpm-md-editor.js +++ b/src/modules/tpm/challengesnew/tpm-md-editor.js @@ -1,16 +1,19 @@ - -import React, { Fragment, useEffect, useRef, useState } from 'react' -import { getUploadActionUrl, getUrl } from 'educoder' +import React, { Fragment, useEffect, useRef, useState } from 'react'; +import { getUploadActionUrl, getUrl } from 'educoder'; import ResizeObserver from 'resize-observer-polyfill'; +// import myxss from '../../../common/filterXss'; import xss from 'xss'; -import '../../courses/css/Courses.css' -import './css/TPMchallengesnew.css' -import 'codemirror/lib/codemirror.css' +import { getImageUrl } from 'educoder'; +import axios from 'axios'; +import '../../courses/css/Courses.css'; +import './css/TPMchallengesnew.css'; +import 'codemirror/lib/codemirror.css'; +import './css/newquestion.css'; const $ = window.$ -const mdIcons = ["bold", "italic", "|", "list-ul", "list-ol", "|", "code", "code-block", "link", "|", "inline-latex", "latex", '|', "image", "table", '|', "line-break", "watch", "clear"] +const mdIcons = ["bold", "italic", "|", "list-ul", "list-ol", "|", "code", "code-block", "link", "|", "inline-latex", "latex", '|', "image", "table", '|', "line-break", "watch", "clear","fullscreen"]; -const NULL_CH = '▁' +const NULL_CH = '▁'; function md_add_data(k, mdu, d) { window.sessionStorage.setItem(k + mdu, d); @@ -39,10 +42,9 @@ function md_rec_data(k, mdu, id) { } window.md_rec_data = md_rec_data; - function md_elocalStorage(editor, mdu, id) { let oc = window.sessionStorage.getItem('content' + mdu) - if (oc !== null && oc != editor.getValue()) { + if (oc !== null && oc !== editor.getValue()) { $("#e_tips_" + id).data('editor', editor); let h = '您上次有已保存的数据,是否恢复 ? / 不恢复'; $("#e_tips_" + id).html(h) @@ -56,15 +58,15 @@ function md_elocalStorage(editor, mdu, id) { m = m < 10 ? '0' + m : m; s = s < 10 ? '0' + s : s; - if (editor.getValue().trim() != "") { + if (editor.getValue().trim() !== "") { md_add_data("content", mdu, editor.getValue()); let id2 = "#e_tips_" + id; - let textStart = " 数据已于 " + let textStart = " 数据已于 "; let text = textStart + h + ':' + m + ':' + s + " 保存 "; // 占位符 let oldHtml = $(id2).html(); - if (oldHtml && oldHtml != ' ' && oldHtml.startsWith(textStart) == false) { + if (oldHtml && oldHtml !== ' ' && oldHtml.startsWith(textStart) === false) { $(id2).html(oldHtml.split(' (')[0] + ` (${text})`); } else { $(id2).html(text); @@ -74,33 +76,257 @@ function md_elocalStorage(editor, mdu, id) { return tid } +export default ({ mdID, onChange, onCMBeforeChange, onCMBlur, error = false, className = '', noStorage = false, imageExpand = true, placeholder = '', width = '100%', height = 400, initValue = '', emoji, watch=true, showNullButton = false, showResizeBar = false, startInit = true , forMember = true , isCanAtme = false , isQuoteIssue = false , changeAtWhoLoginList, owner, projectsId , isFocus = true}) => { + + const editorEl = useRef(); + const resizeBarEl = useRef(); + const [editorInstance, setEditorInstance] = useState(); + const [atWhoVisible, setAtWhoVisible] = useState(false); + const [atWhoLoginListState, setAtWhoLoginListState] = useState([]); + //调用member.json接口获取到的用户列表 + const [users, setUsers] = useState([]); + //可以@的全部用户 + const [allUsers, setAllUsers] = useState([]); + const atWhoLoginList = useRef([]); + const atWhoVisibleRef = useRef(false); + const containerId = `mdEditor_${mdID}`; + const editorBodyId = `mdEditors_${mdID}`; + const tipId = `e_tips_mdEditor_${mdID}`; -export default ({ mdID, onChange, onCMBeforeChange, onCMBlur, error = false, className = '', noStorage = false, imageExpand = true, placeholder = '', width = '100%', height = 400, initValue = '', emoji, watch, showNullButton = false, showResizeBar = false, startInit = true }) => { + // quote相关 + const [issues, setIssues ] = useState([]); + const [quoteVisible, setQuoteVisible] = useState(false); + const [screenIssues, setScreenIssues ] = useState([]); + const quoteVisibleRef = useRef(false); + const chooseIssuesList = useRef([]); - const editorEl = useRef() - const resizeBarEl = useRef() - const [editorInstance, setEditorInstance] = useState() - const containerId = `mdEditor_${mdID}` - const editorBodyId = `mdEditors_${mdID}` - const tipId = `e_tips_mdEditor_${mdID}` + useEffect(()=>{ + //请求members接口获取全部可@列表 + isCanAtme && axios.get(`/${owner}/${projectsId}/members.json`).then(response=>{ + if(response.data.total_count !== 0){ + setAllUsers(response.data.users); + setUsers(response.data.users); + } + }) + //点击其他地方关闭弹框 + document.addEventListener('click',()=>{ + atWhoVisibleRef.current = false; + setAtWhoVisible(false); + quoteVisibleRef.current = false; + setQuoteVisible(false); + }) + + isQuoteIssue && getIssueList(); + },[]) + + // 请求issues接口获取全部可quote的issue列表 + function getIssueList(keyword){ + axios.get(`/v1/${owner}/${projectsId}/issues`,{params:{ + only_name:true,keyword,sort_direction:"desc",sort_by:"issues.created_on" + }}).then(result=>{ + if(result){ + !keyword && setIssues(result.data.issues); + let data = result.data.issues; + setScreenIssues(data && data.length > 0 ? data:undefined); + } + }) + } + + + // # 引用的弹框div + const QuoteDiv = ( +