diff --git a/config/paths.js b/config/paths.js index c116b362a..c9e2c21fa 100644 --- a/config/paths.js +++ b/config/paths.js @@ -53,4 +53,5 @@ module.exports = { appNodeModules: resolveApp('node_modules'), publicUrl: getPublicUrl(resolveApp('package.json')), servedPath: getServedPath(resolveApp('package.json')), -}; + proxySetup: resolveApp('src/setupProxy.js'), +}; \ No newline at end of file diff --git a/config/webpackDevServer.config.js b/config/webpackDevServer.config.js index f12d31594..b1c2175b1 100644 --- a/config/webpackDevServer.config.js +++ b/config/webpackDevServer.config.js @@ -5,6 +5,7 @@ const noopServiceWorkerMiddleware = require('react-dev-utils/noopServiceWorkerMi const ignoredFiles = require('react-dev-utils/ignoredFiles'); const config = require('./webpack.config.dev'); const paths = require('./paths'); +const fs = require('fs'); const protocol = process.env.HTTPS === 'true' ? 'https' : 'http'; const host = process.env.HOST || '0.0.0.0'; @@ -90,6 +91,9 @@ module.exports = function(proxy, allowedHost) { // it used the same host and port. // https://github.com/facebookincubator/create-react-app/issues/2272#issuecomment-302832432 app.use(noopServiceWorkerMiddleware()); + if (fs.existsSync(paths.proxySetup)) { + require(paths.proxySetup)(app); + } }, }; }; diff --git a/package.json b/package.json index 3d2d7daf5..53fff77af 100644 --- a/package.json +++ b/package.json @@ -202,7 +202,6 @@ "eslintConfig": { "extends": "react-app" }, - "proxy": "https://testforgeplus.trustie.net", "port": "3007", "devDependencies": { "@babel/core": "^7.23.6", diff --git a/src/forge/Main/Detail.js b/src/forge/Main/Detail.js index 932372ded..ce033477c 100644 --- a/src/forge/Main/Detail.js +++ b/src/forge/Main/Detail.js @@ -135,6 +135,10 @@ const Wiki = Loadable({ loader: () => import('../Wiki/page/index'), loading: Loading, }); +const WikiHisList = Loadable({ + loader: () => import('../Wiki/page/historyList'), + loading: Loading, +}); const WikiEdit = Loadable({ loader: () => import('../Wiki/page/edit'), loading: Loading, @@ -817,6 +821,12 @@ class Detail extends Component { () => () } > + {/* wiki历史列表 */} + () + } + > {/* wiki */} { const {getFieldDecorator, validateFields, getFieldValue} = form; const wikiParams = {owner, repo: repoIdentifier, projectId: project_id}; let editType = pathname.split("/").pop(); //编辑wiki(addWiki addWikiBy${key} edit) + const sha = searchParams.get("sha") || ''; const [loading, setLoading] = useState(false); const [wikiPageInitDetail, setWikiPageInitDetail] = useState({}) @@ -42,9 +43,11 @@ export default Form.create()((props) => { const wikiName = searchParams.get("wiki") const sameNameWiki = findSamaNameWiki(wikiPages, wikiName) document.title = `${titleByEditType[editType]}${sameNameWiki.title}-维基-${projectAuthor && projectAuthor.name}/${projectName}`; - getWiki({ + const func = sha ? getPreviousWiki : getWiki + func({ ...wikiParams, - pageName: sameNameWiki.sub_url + pageName: sameNameWiki.sub_url, + sha }).then(res=>{ if(res && res.code === 200){ res.data.content = Base64.decode(res.data.content_base64) diff --git a/src/forge/Wiki/page/historyList.jsx b/src/forge/Wiki/page/historyList.jsx new file mode 100644 index 000000000..2e80f3dd3 --- /dev/null +++ b/src/forge/Wiki/page/historyList.jsx @@ -0,0 +1,115 @@ +import React, { useEffect, useState } from "react"; +import { Button, Table } from "antd"; +import { getWikiRevisions } from "../api"; + +import './index.scss'; + +export default (props) => { + const {project_id, match:{params:{owner, projectsId: repoIdentifier}}, projectDetail, history, location} = props; + const search = new URLSearchParams(location.search); + const pageName = search.get("wiki") || ''; + const title_sub = search.get("str") || ''; + const wikiParams = {owner, repo: repoIdentifier, projectId: project_id, pageName: title_sub}; + const permission = projectDetail && projectDetail.permission && projectDetail.permission !== "Reporter"; + const { author: projectAuthor, name: projectName} = projectDetail || {}; + + const [reload, setReload] = useState(); + const [loading, setLoading] = useState(); + const [ historyList, setHistoryList ] = useState([]); + + // 弹框编辑目录 + + useEffect(()=>{ + if(!project_id) return + document.title = `${pageName}历史版本-维基-${projectAuthor && projectAuthor.name}/${projectName}`; + getList() + // setWikiPageInitDetail({}) + // // 获取wiki 目录树、sidebar内容 + // getMenuListAndSidebarData(wikiParams).then(res=>{ + // setWikiPageInitDetail(res); + // }) + }, [project_id, reload]) + + function refush(){ + setReload(Math.random()) + } + + const getList = () => { + setLoading(true) + getWikiRevisions(wikiParams).then(res=>{ + setLoading(false) + if(res?.code === 200){ + setHistoryList(res.data?.commits); + } + }) + } + + const columns = [ + { + title: '修改时间', + dataIndex: ['author','date'], + }, + { + title: '修改记录', + dataIndex: 'message', + key: "message", + ellipsis: true, + }, + { + title: '修改人', + dataIndex: 'author', + key: "author", + ellipsis: true, + render:(value)=>{ + return( +
+ + {value?.name} +
+ ) + } + }, + { + title: '操作', + dataIndex: 'sha', + key: 'sha', + render: (text, record) => { + return
+ +
+ +
+ } + } + ]; + + + return
+
+
历史版本
+ +
+ +
+ record.id} + loading={loading} + >
+
+
+} \ No newline at end of file diff --git a/src/forge/Wiki/page/index.jsx b/src/forge/Wiki/page/index.jsx index b4f7c77b8..9d0496a5c 100644 --- a/src/forge/Wiki/page/index.jsx +++ b/src/forge/Wiki/page/index.jsx @@ -126,6 +126,7 @@ export default (props) => { {wikiDetail.userName} 上次修改于{wikiDetail.last_commit ? timeAgo(wikiDetail.last_commit.author.date) : '刚刚'} + 历史版本 {permission &&
diff --git a/src/forge/Wiki/page/index.scss b/src/forge/Wiki/page/index.scss index 0f98f10ee..92b2e9fef 100644 --- a/src/forge/Wiki/page/index.scss +++ b/src/forge/Wiki/page/index.scss @@ -112,7 +112,7 @@ display: flex; justify-content: space-between; align-items: center; - padding: 0 12rem 0 2rem; + padding: 0 2rem 0 2rem; width: 100%; height: 8vh; background: rgb(39, 47, 76); @@ -125,4 +125,26 @@ flex:none } } +} +.history { + .wiki-title { + font-weight: 700; + color: #202d40; + font-size: 17px; + } + .ant-table-thead > tr > th{ + background-color: #fff; + } + .ant-table-column-title { + color: #202d40; + font-size: 16px; + } + .divider { + opacity: 24%; + width: 0px; + height: 7px; + border-right: 1px solid; + border-color: #72748e; + display: inline-block; + } } \ No newline at end of file diff --git a/src/forge/Wiki/page/preview.jsx b/src/forge/Wiki/page/preview.jsx index ef859e248..a41d43003 100644 --- a/src/forge/Wiki/page/preview.jsx +++ b/src/forge/Wiki/page/preview.jsx @@ -1,8 +1,8 @@ import React, { useEffect, useState } from 'react'; import { Link } from 'react-router-dom'; import { Base64 } from 'js-base64'; -import { Divider } from 'antd'; -import { getWiki, getMenuListAndSidebarData, findNodeByFirstOrContrastName, } from '../api'; +import { Divider, Button } from 'antd'; +import { getWiki, getMenuListAndSidebarData, findNodeByFirstOrContrastName, getPreviousWiki } from '../api'; import RenderHtml from '../../../components/render-html'; import TreeByWikiSidebar from '../components/treeByWikiSidebar'; import Clone from '../components/clone'; @@ -15,6 +15,8 @@ export default (props) => { const search = new URLSearchParams(location.search); const projectName = search.get("name") || ''; const wikiBySearch = search.get("wiki") || ''; + const sha = search.get("sha") || ''; + const str = search.get("str") || ''; const [wikiPageInitDetail, setWikiPageInitDetail] = useState({}) const [checkItem, setCheckItem] = useState({}); @@ -24,12 +26,13 @@ export default (props) => { useEffect(()=>{ if(checkItem && checkItem.name){ - document.title = `${checkItem.name}-维基预览` + document.title = `${checkItem.name || wikiBySearch}-维基预览` } }, [checkItem]) useEffect(()=>{ + if (sha) return // 获取wiki 目录树、sidebar内容 getMenuListAndSidebarData(wikiParams).then(res=>{ setWikiPageInitDetail(res); @@ -49,11 +52,13 @@ export default (props) => { setCheckItem(node); }, [menuList, wikiBySearch]) - useEffect(() => { - document.title = `${checkItem && checkItem.titleStr}-维基预览` - checkItem.title_sub && getWiki({ + useEffect(() => { + document.title = `${checkItem && checkItem.titleStr || wikiBySearch}-维基预览` + const func = sha ? getPreviousWiki : getWiki + func({ ...wikiParams, - pageName: checkItem.title_sub + pageName: str, + sha }).then(res => { if(res && res.code === 200){ setItemDetail(res.data); @@ -71,23 +76,35 @@ export default (props) => { {projectName}
-
克隆地址
- - + { + sha ? : <> +
克隆地址
+ + + + }
-
- {/* 读sidebar转换成目录树 */} - { - history.push(`${location.pathname}?name=${projectName}&wiki=${encodeURIComponent(node.titleStr)}`) - }}/> -
- + { + !sha &&
+ {/* 读sidebar转换成目录树 */} + { + history.push(`${location.pathname}?name=${projectName}&wiki=${encodeURIComponent(node.titleStr)}`) + }}/> +
+ } +
-

{checkItem.titleStr}

+

{itemDetail.title}

{itemDetail && itemDetail.content_base64 && }
diff --git a/src/services/project.js b/src/services/project.js index 1aa9345f1..ea2f62e5a 100644 --- a/src/services/project.js +++ b/src/services/project.js @@ -15,13 +15,13 @@ const axiosInstance = axios.create({ }); axiosInstance.interceptors.request.use( config => { - if (window.location.port === "3007") { - if (config.url.indexOf('?') === -1) { - config.url = `${config.url}?debug=admin`; - } else { - config.url = `${config.url}&debug=admin`; - } - } + // if (window.location.port === "3007") { + // if (config.url.indexOf('?') === -1) { + // config.url = `${config.url}?debug=admin`; + // } else { + // config.url = `${config.url}&debug=admin`; + // } + // } return config; }, err => { diff --git a/src/setupProxy.js b/src/setupProxy.js new file mode 100644 index 000000000..2b1f845c4 --- /dev/null +++ b/src/setupProxy.js @@ -0,0 +1,24 @@ +// src/setupProxy.js +const { createProxyMiddleware } = require('http-proxy-middleware'); + +module.exports = function(app) { + app.use( + '/api/wiki', + createProxyMiddleware({ + target: 'http://testgetway.trustie.net/', + changeOrigin: true, + logLevel: 'debug', // 开启 http-proxy-middleware 的日志 + // pathRewrite: { '^/api/wiki': '' }, // 根据需要取消注释和修改 + }) + ); + + app.use( + '/api', + createProxyMiddleware({ + target: 'http://testforgeplus.trustie.net/', + changeOrigin: true, + logLevel: 'debug', // 开启 http-proxy-middleware 的日志 + // pathRewrite: { '^/api': '' }, // 根据需要取消注释和修改 + }) + ); +}; diff --git a/src/ssrUrl.js b/src/ssrUrl.js index 4bf99bf81..05df5203e 100644 --- a/src/ssrUrl.js +++ b/src/ssrUrl.js @@ -1,4 +1,4 @@ -export const url = process.env.NODE_ENV === 'production' ? 'https://www.gitlink.org.cn' : 'https://testforgeplus.trustie.net' +export const url = process.env.NODE_ENV === 'production' ? 'https://www.gitlink.org.cn' : 'https://testforgeplus.trustie.net' export const zoneUrl = process.env.NODE_ENV === 'production' ? 'https://gateway.gitlink.org.cn' : 'https://testgetway.trustie.net' export const host = process.env.NODE_ENV === 'production' ? 'www.gitlink.org.cn' : 'testforgeplus.trustie.net'