Merge pull request '合并代码' (#822) from gitlink_ssr_head into pre_gitlink_ssr
This commit is contained in:
commit
7e080c33b4
|
|
@ -1,7 +1,7 @@
|
|||
import React , { useEffect , useState } from 'react';
|
||||
import { Badge, Breadcrumb } from 'antd';
|
||||
import SourceFile from '../img/sourceFile.png';
|
||||
import { getSourceDetail } from '../api';
|
||||
import { getFileByZone, getSourceDetail } from '../api';
|
||||
import { Link } from 'react-router-dom';
|
||||
import { httpUrl } from '../fetch';
|
||||
import { AlignCenter, FlexAJ } from '../../Component/layout';
|
||||
|
|
@ -9,11 +9,17 @@ import SourceIcon from '../img/sourceIcon.png';
|
|||
import { addMeta, setSeoMeta } from 'educoder';
|
||||
import {getUniqueIdentifier,getUserName,getBrowserPlatform,getBrowserBrand} from '../utils';
|
||||
import {setZoneVisits} from '../api'
|
||||
import axios from 'axios';
|
||||
import RenderHtml from '../../../components/render-html';
|
||||
|
||||
|
||||
function SourceDetail(props){
|
||||
const { deptId , sourceid } = props.match.params;
|
||||
const [ detail , setDetail ] = useState(undefined);
|
||||
const [files, setFiles] = useState([]);
|
||||
const [mdFiles, setMdFiles] = useState([]);
|
||||
const [mdContents, setMdContents] = useState(undefined);
|
||||
|
||||
const zonedetail = props.data;
|
||||
const {temp} = props;
|
||||
|
||||
|
|
@ -51,12 +57,51 @@ function SourceDetail(props){
|
|||
}
|
||||
}
|
||||
|
||||
function getDetails(){
|
||||
getSourceDetail(sourceid).then(response=>{
|
||||
if(response){
|
||||
function getDetails() {
|
||||
getSourceDetail(sourceid).then(response => {
|
||||
if (response) {
|
||||
setDetail(response.data.data);
|
||||
const { fileList } = response.data.data;
|
||||
if (deptId === "NSCC") {
|
||||
initMDContent(fileList)
|
||||
}else{
|
||||
setFiles(fileList);
|
||||
}
|
||||
|
||||
}
|
||||
}).catch(error=>{})
|
||||
}).catch(error => { })
|
||||
}
|
||||
|
||||
async function initMDContent(fileList) {
|
||||
const mdFileList = fileList.filter(item =>
|
||||
item.fileOriginName && item.fileOriginName.toLowerCase().endsWith('.md')
|
||||
);
|
||||
|
||||
const nonMdFiles = fileList.filter(item =>
|
||||
!item.fileOriginName || !item.fileOriginName.toLowerCase().endsWith('.md')
|
||||
);
|
||||
setFiles(nonMdFiles);
|
||||
|
||||
if (mdFileList.length > 0) {
|
||||
setMdFiles(mdFileList);
|
||||
|
||||
try {
|
||||
const contents = await Promise.all(
|
||||
mdFileList.map(async (file) => {
|
||||
const res = await axios.get(`${httpUrl}/file/open/download/${file.fileId}`, {
|
||||
responseType: 'text'
|
||||
});
|
||||
return { [file.fileId]: res.data };
|
||||
})
|
||||
);
|
||||
|
||||
// 合并所有结果为单个对象
|
||||
setMdContents(contents.reduce((acc, item) => ({ ...acc, ...item }), {}));
|
||||
|
||||
} catch (error) {
|
||||
console.error('获取 md 文件失败:', error);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return(
|
||||
|
|
@ -84,12 +129,18 @@ function SourceDetail(props){
|
|||
{detail.auditStatus === '0' && <Badge color={temp === "zone" ? "#466aff" : "#089f7f"} text="待审核" className='pass'/> }
|
||||
{detail.auditStatus === '2' && <Badge color="#eb1212" text="未通过" className='failed'/> }
|
||||
</div>
|
||||
<div className='pb20' dangerouslySetInnerHTML={{ __html: detail.summary }} ></div>
|
||||
{mdContents && Object.keys(mdContents).length > 0 ? <div className="md-preview-box">
|
||||
{mdFiles.map((file) => (
|
||||
<div key={file.fileId} className="pb20">
|
||||
<RenderHtml className="editor-content-panel mt20 imageLayerParent" value={ mdContents[file.fileId] || '加载中...' } url={history.location}/>
|
||||
</div>
|
||||
))}
|
||||
</div> : <div className='pb20' dangerouslySetInnerHTML={{ __html: detail.summary }} ></div>}
|
||||
{
|
||||
detail.fileList && detail.fileList.length > 0 &&
|
||||
files && files.length > 0 &&
|
||||
<ul className="files_box">
|
||||
{
|
||||
detail.fileList.map((i,k)=>{
|
||||
files.map((i,k)=>{
|
||||
return(
|
||||
<li>
|
||||
<img src={SourceFile} alt="" width="20px" className="mr12"/>
|
||||
|
|
|
|||
|
|
@ -5,6 +5,14 @@ export function getImage(identifier) {
|
|||
return `${ httpUrl }/file/open/downloadByIdentifier/${ identifier }`
|
||||
}
|
||||
|
||||
export function getFileByZone(fileId) {
|
||||
return fetch({
|
||||
url: `${ httpUrl }/file/open/download/${ fileId }`,
|
||||
method: 'get',
|
||||
params
|
||||
});
|
||||
}
|
||||
|
||||
/**入口页接口***/
|
||||
export function getMainInfos(deptId, params) {
|
||||
return fetch({
|
||||
|
|
|
|||
|
|
@ -2069,6 +2069,8 @@
|
|||
border: none;
|
||||
}
|
||||
&.zone_source_box .sources .source_left_ul{
|
||||
width: 272px;
|
||||
align-items: flex-start;
|
||||
border-right: 1px solid rgba(76, 88, 118, 0.1);
|
||||
}
|
||||
&.zone_source_box .sources .source_left_ul li.active{
|
||||
|
|
@ -2092,6 +2094,7 @@
|
|||
}
|
||||
}
|
||||
&.zone_source_box .sources .source_lists .source_lists_card{
|
||||
width: 280px;
|
||||
background-image: url('./img/sourceCardBack1.png');
|
||||
background-color: transparent;
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue