锚点跳转

This commit is contained in:
caishi 2020-12-15 18:01:16 +08:00
parent 68eb499a8c
commit 2129a222e5
11 changed files with 33 additions and 12 deletions

5
package-lock.json generated
View File

@ -3888,6 +3888,11 @@
"randomfill": "^1.0.3"
}
},
"crypto-js": {
"version": "4.0.0",
"resolved": "https://registry.npm.taobao.org/crypto-js/download/crypto-js-4.0.0.tgz",
"integrity": "sha1-KQSrJnep0EKFai6i74DekuSjbcw="
},
"crypto-random-string": {
"version": "1.0.0",
"resolved": "https://registry.npmjs.org/crypto-random-string/-/crypto-random-string-1.0.0.tgz",

View File

@ -27,7 +27,7 @@ if (isDev) {
}
debugType = window.location.search.indexOf('debug=t') !== -1 ? 'teacher' :
window.location.search.indexOf('debug=s') !== -1 ? 'student' :
window.location.search.indexOf('debug=a') !== -1 ? 'admin' : parsed.debug || 'student'
window.location.search.indexOf('debug=a') !== -1 ? 'admin' : parsed.debug || 'admin'
}
function clearAllCookie() {
cookie.remove('_educoder_session', { path: '/' });

View File

@ -2,7 +2,7 @@ import React, { useEffect, useRef, useMemo } from 'react'
import 'katex/dist/katex.min.css'
import marked, { getTocContent, cleanToc, getMathExpressions, resetMathExpressions } from '../common/marked';
import 'code-prettify'
import dompurify from 'dompurify'
import dompurify from 'dompurify';
import { renderToString } from 'katex'
@ -14,12 +14,14 @@ function _unescape(str) {
}
export default ({
value = '',
className,
style = {},
url
}) => {
let str = String(value)
let str = String(value);
const html = useMemo(() => {
let rs = marked(str)
@ -36,7 +38,21 @@ export default ({
resetMathExpressions()
return dompurify.sanitize(rs)
}, [str])
}, [str]);
// #id
useEffect(()=>{
if(url && url.hash && html){
let u = url.hash;
if(u){
let id = decodeURIComponent(u.split("#")[1]);
let ele = document.getElementById(id);
if(ele){
window.scrollTo(0, ele.offsetTop - window.innerHeight / 5);
}
}
}
},[url])
const el = useRef();
function onAncherHandler(e) {

View File

@ -116,7 +116,7 @@ function Index(props){
:
<div style={{padding:"20px 0px"}}>
{content ?
<RenderHtml className="break_word_comments imageLayerParent" value={content} />
<RenderHtml className="break_word_comments imageLayerParent" value={content} url={this.props.history.location}/>
:
<div>暂无简介~</div>
}

View File

@ -308,7 +308,7 @@ class CoderRootDirectory extends Component {
</div>
<div className="commonBox-info">
{readMeContent[0].content ?
<RenderHtml className="break_word_comments imageLayerParent" value={readMeContent[0].content} />
<RenderHtml className="break_word_comments imageLayerParent" value={readMeContent[0].content} url={this.props.history.location}/>
:
<span>暂无~</span>
}

View File

@ -260,7 +260,7 @@ class CoderRootFileDetail extends Component {
) : (
md && readOnly ?
<div className="files-md">
<RenderHtml className="file-md imageLayerParent" value={description} />
<RenderHtml className="file-md imageLayerParent" value={description} url={this.props.history.location}/>
</div>
:
<Meditor

View File

@ -209,7 +209,7 @@ class MessageCount extends Component {
};
commentCtx = (v) => {
return <RenderHtml className="break_word_comments imageLayerParent" value={v} />;
return <RenderHtml className="break_word_comments imageLayerParent" value={v} url={this.props.history.location}/>;
};
setCopyVisible=(e)=>{

View File

@ -182,7 +182,7 @@ class Detail extends Component {
};
commentCtx = (v) => {
return <RenderHtml className="break_word_comments imageLayerParent" value={v} />;
return <RenderHtml className="break_word_comments imageLayerParent" value={v} url={this.props.history.location} />;
};
render() {

View File

@ -86,7 +86,7 @@ class children_comments extends Component {
};
commentCtx = (v) => {
return <RenderHtml className="break_word_comments imageLayerParent" value={v} />;
return <RenderHtml className="break_word_comments imageLayerParent" value={v} url={this.props.history.location}/>;
};
Paginations =()=> {

View File

@ -51,7 +51,7 @@ class children_journals extends Component {
};
commentCtx = (v) => {
return <RenderHtml className="break_word_comments imageLayerParent" value={v} />;
return <RenderHtml className="break_word_comments imageLayerParent" value={v} url={this.props.history.location}/>;
};
Paginations =()=> {

View File

@ -263,7 +263,7 @@ class comments extends Component {
}
commentCtx = (v) => {
return <RenderHtml className="break_word_comments imageLayerParent" value={v} />;
return <RenderHtml className="break_word_comments imageLayerParent" value={v} url={this.props.history.location}/>;
};
Paginations = ()=>{
const { page, limit, search_count } = this.state;