From 424ca05ff63cb8d6a17e6f9ce3d6b0cf2ad7e553 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=B0=A2=E6=80=9D?= <2897217417@qq.com> Date: Wed, 19 Jul 2023 11:44:01 +0800 Subject: [PATCH] issue --- src/forge/Information/Pages/help.jsx | 71 ++++++++++++++------- src/forge/Information/Pages/zoneVIP.jsx | 2 +- src/forge/Information/index.scss | 35 +++++----- src/forge/Wiki/components/sidebar/index.jsx | 65 ++++++++++--------- src/forge/Wiki/utils.js | 8 +++ 5 files changed, 114 insertions(+), 67 deletions(-) create mode 100644 src/forge/Wiki/utils.js diff --git a/src/forge/Information/Pages/help.jsx b/src/forge/Information/Pages/help.jsx index 077b76000..f32cbe477 100644 --- a/src/forge/Information/Pages/help.jsx +++ b/src/forge/Information/Pages/help.jsx @@ -1,6 +1,6 @@ import React, { useEffect, useState } from 'react'; -import { Box, LongWidth } from '../../Component/layout'; -import { Affix, Input, message, Spin, Tree } from 'antd'; +import { Box, LongWidth, FlexAJ } from '../../Component/layout'; +import { Affix, Button, Input, message, Spin, Tree } from 'antd'; import Nodata from '../../Nodata'; import nodata from '../img/nodata.png'; import { tempEnum } from '../tempInfo'; @@ -20,7 +20,7 @@ function ProjectSource(props) { const [expandedKeys, setExpandedKeys] = useState(undefined); const [wiki, setWiki] = useState(undefined); const [wikiDetail, setWikiDetail] = useState(undefined); - const [autoExpandParent, setAutoExpandParent] = useState(true); + const [autoExpandParent, setAutoExpandParent] = useState(false); const [searchValue, setSearchValue] = useState(""); const [wikiContMenu, setWikiContMenu] = useState(undefined); const { temp, history, data } = props; @@ -46,7 +46,8 @@ function ProjectSource(props) { // 默认打开第一个wiki const firstWiki = findFirstWiki(menuList); if(firstWiki){ - setWiki(firstWiki.titleStr); + setExpandedKeys([getParentKey(firstWiki.key, menuList)+"", firstWiki.key+""]); + setWiki(firstWiki); } setFlattenedMenuList(generateList(menuList)); setInitMenuList(menuList); @@ -63,7 +64,7 @@ function ProjectSource(props) { // 获取wiki内容 setLoading(true); getWiki({ - pageName: wiki, + pageName: wiki.titleStr, ...wikiParams }).then(res=>{ setLoading(false); @@ -75,7 +76,7 @@ function ProjectSource(props) { message.error("加载失败") } }) - }, [wiki]) + }, [wiki && wiki.titleStr]) useEffect(() => { if (scroller) { @@ -95,7 +96,7 @@ function ProjectSource(props) { scroller .setup({ step: '.wikiContentHC .markdown_anchors', - offset: 0.3, + offset: 0.2, }) .onStepEnter(({ element }) => { [].forEach.call(document.querySelectorAll('.wikiContMenuBox li a'), node => { @@ -108,16 +109,39 @@ function ProjectSource(props) { }) }, [wikiDetail]) + useEffect(() =>{ + const handleClick = (event) => { + let target = event.target; + if (target.tagName.toUpperCase() === 'A') { + let ancher = target.getAttribute('href'); + if (ancher && ancher.startsWith('#')) { + event.preventDefault() + let viewEl = document.getElementById(ancher.replace('#', '')) + if (viewEl) { + viewEl.scrollIntoView(true); + // 滚动结束后向下偏移170像素 + window.scrollBy(0,-170); + } + } + } + }; + document.addEventListener("click", handleClick); + return () => { + document.removeEventListener("click", handleClick); + }; + }, []) + function changeSearchValue(value) { if (value) { + const va = value.trim(); // 找到命中搜索的item的父元素 const expandedKeys = flattenedMenuList.map(item => { - if (item.title.match(new RegExp(value, 'i'))) { + if (item.title.match(new RegExp(va, 'i'))) { return getParentKey(item.key, initMenuList); } return null; }).filter((item, i, self) => item && self.indexOf(item) === i); - setSearchValue(value); + setSearchValue(va); setExpandedKeys(expandedKeys); } else { setSearchValue(""); @@ -132,28 +156,26 @@ function ProjectSource(props) { // 选中节点 function selectTree(keys,event){ - let {titleStr, isFile} = event.node.props.dataRef; + let {isFile} = event.node.props.dataRef; if(isFile){ - setWiki(titleStr); + setWiki(event.node.props.dataRef); } } function renderTreeNodes(data) { return data && data.length > 0 && data.map((item) => { - const index = item.titleStr.indexOf(searchValue); - const beforeStr = item.titleStr.substr(0, index); - const afterStr = item.titleStr.substr(index + searchValue.length); - const title = index > -1 ? ( + const matchResult = item.titleStr.match(new RegExp(searchValue, 'i')); + const title = matchResult ? ( - {beforeStr} - {searchValue} - {afterStr} + {item.titleStr.substr(0, matchResult.index)} + {item.titleStr.substring(matchResult.index, matchResult.index+searchValue.length)} + {item.titleStr.substr(matchResult.index+searchValue.length)} ) : ( {item.titleStr} ); return ( - + {renderTreeNodes(item.children)} ); @@ -183,9 +205,14 @@ function ProjectSource(props) { {wikiDetail && -
{wikiDetail.name}
- {wikiDetail.commit &&
更新时间:{wikiDetail.commit.author.date}
} - {wikiDetail.md_content && } + +
+
{wikiDetail.name}
+ {wikiDetail.commit &&
更新时间:{wikiDetail.commit.author.date || '刚刚'}
} +
+ +
+ {wikiDetail.md_content && }
{wikiContMenu && wikiContMenu !== "
    " &&
    diff --git a/src/forge/Information/Pages/zoneVIP.jsx b/src/forge/Information/Pages/zoneVIP.jsx index 6ab83a536..4541c2c80 100644 --- a/src/forge/Information/Pages/zoneVIP.jsx +++ b/src/forge/Information/Pages/zoneVIP.jsx @@ -76,7 +76,7 @@ function ZoneVIP(props){

    { tempConfig[temp].member }

    { tempConfig[temp].vipDesc }

    - { memberStatus === memberStatusEnum.notMember && } + { memberStatus === memberStatusEnum.notMember && } { memberStatus === memberStatusEnum.applying &&
    您的申请已提交,请耐心等待管理员审核!
    } setApplyVisible(!applyVisible)} current_user={props.current_user}/> diff --git a/src/forge/Information/index.scss b/src/forge/Information/index.scss index d5013dc89..753bf27ff 100644 --- a/src/forge/Information/index.scss +++ b/src/forge/Information/index.scss @@ -1,5 +1,20 @@ @import './theme.scss'; +// 按钮 +.zone_apply_button { + flex-grow: 0; + margin-top: 20px; + width: 111px; + height: 40px; + color: var(--primary-color); + border-color: var(--primary-color); + font-size: 15px; + &:hover, &:active, &:focus { + color: var(--primary-color); + border-color: var(--primary-color); + } +} + .information_main{ background-color:#f3f5f8; min-height: 100vh; @@ -72,7 +87,7 @@ line-height: 88px; border-bottom: none!important; padding:0px ; - margin-right: 100px!important; + margin-right: 80px!important; img{ margin-right: 10px; } @@ -1010,19 +1025,6 @@ } } .zone_VIP_box, .zone1_VIP_box { - .apply_button { - flex-grow: 0; - margin-top: 20px; - width: 111px; - height: 40px; - color: var(--primary-color); - border-color: var(--primary-color); - font-size: 15px; - &:hover, &:active, &:focus { - color: var(--primary-color); - border-color: var(--primary-color); - } - } .tips { width: 100%; font-size: 15px; @@ -1356,7 +1358,7 @@ &::-webkit-scrollbar{ display: none; } - background-image: linear-gradient(269.73deg,#ffffff 0%,rgba(255, 255, 255, 0) 100%); + background: #ffffff; padding: 25px 15px; .ant-tree.ant-tree-directory > .menuHcNode span.ant-tree-node-content-wrapper.ant-tree-node-selected, .ant-tree.ant-tree-directory .ant-tree-child-tree > .menuHcNode span.ant-tree-node-content-wrapper.ant-tree-node-selected{ color: var(--primary-color); @@ -1413,6 +1415,9 @@ background-color: var(--primary-color); } } + &:hover{ + color: var(--primary-color); + } } } } diff --git a/src/forge/Wiki/components/sidebar/index.jsx b/src/forge/Wiki/components/sidebar/index.jsx index d8b3254a2..f9b8a683b 100644 --- a/src/forge/Wiki/components/sidebar/index.jsx +++ b/src/forge/Wiki/components/sidebar/index.jsx @@ -6,6 +6,7 @@ import '../../components/ModalFun/index.scss'; import { deleteWiki, findNodeByChildrenKey, findNodeByKey, getWiki, treeToMd, updateWiki } from '../../api'; import { useEffect } from 'react'; import { Base64 } from 'js-base64'; +import { splicingTabs } from '../../utils'; const Search = Input.Search; const {DirectoryTree, TreeNode} = Tree; @@ -281,8 +282,10 @@ export default function Sidebar(props) { setVisible(false); message.success('重命名成功'); }else{ - console.log('修改文件目录顺序成功'); + // message.success('修改文件目录顺序成功'); } + }else{ + message.error(res.message); } }); } @@ -447,10 +450,10 @@ export default function Sidebar(props) { dragObj = item; }); // 如果拖拽的是目录,那么需要遍历所有的子节点,改变\t个数 - if(dragObj.title.indexOf('- ') !== -1){ + if(!dragObj.isFile){ // 放入的节点标题 const title = info.node.props.dataRef.title; - const addBool = !info.dropToGap || ((info.node.props.children || []).length > 0 && dropPosition === 1) + const addBool = !info.dropToGap upTitle(dragObj.children, addBool ? `\t${title}` : title); } @@ -459,52 +462,56 @@ export default function Sidebar(props) { // dropToGap: true拖拽在节点中间 false拖拽到节点之上 if (!info.dropToGap) { - // 追加到尾部 + // 拖拽到节点之上->追加到尾部 loop(data, dropKey, (item, index, arr) => { - const {title} = item; + const {title, key} = item; if(title.indexOf('- ') === -1){ + message.error('不能拖拽到页面上'); return; } - const childrenName = item.children.map(item=>item.title.trim()); - if(childrenName.includes(dragObj.title.trim())){ + const childrenName = item.children.map(item=>item.titleStr); + if(childrenName.includes(dragObj.titleStr)){ message.error('不能与同级目录名称相同'); return; } - dragObj.title = `\t${title.substring(0, title.indexOf('- '))}${dragObj.title.trim()}`; + dragObj.title = `${splicingTabs(key.split('-').length)}${dragObj.title.trim()}`; item.children = item.children || []; item.children.push(dragObj); bool = true; }); - } else if ( - (info.node.props.children || []).length > 0 && // Has children - dropPosition === 1 // On the bottom gap - ) { - // 拖拽到目录节点下 - loop(data, dropKey, item => { - const childrenName = item.children.map(item=>item.title.trim()) - if(childrenName.includes(dragObj.title.trim())){ - message.error('不能与同级目录名称相同'); - return; - } - const {title} = item; - dragObj.title = `\t${title.substring(0, title.indexOf('- '))}${dragObj.title.trim()}`; - item.children = item.children || []; - item.children.unshift(dragObj); - }); - bool = true; - } else { + } + // else if ( + // (info.node.props.children || []).length > 0 && // Has children + // dropPosition === 1 // On the bottom gap + // ) { + // // 拖拽到目录节点下 + // loop(data, dropKey, item => { + // const childrenName = item.children.map(item=>item.title.trim()) + // if(childrenName.includes(dragObj.title.trim())){ + // message.error('不能与同级目录名称相同'); + // return; + // } + // console.log('item', item, 'dragObj', dragObj); + // const {title} = item; + // dragObj.title = `\t${title.substring(0, title.indexOf('- '))}${dragObj.title.trim()}`; + // item.children = item.children || []; + // item.children.unshift(dragObj); + // }); + // bool = true; + // } + else { let ar; let i; loop(data, dropKey, (item, index, arr) => { ar = arr; i = index; }); - const childrenName = ar.map(item=>item.title.trim()) - if(childrenName.includes(dragObj.title.trim())){ + const childrenName = ar.map(item=>item.titleStr) + if(childrenName.includes(dragObj.titleStr)){ message.error('不能与同级目录名称相同'); return; } - dragObj.title = `${ar[i].title.substring(0, ar[i].title.indexOf('- '))}${dragObj.title.trim()}`; + dragObj.title = `${splicingTabs(ar[i].key.split('-').length-1)}${dragObj.title.trim()}`; if (dropPosition === -1) { ar.splice(i, 0, dragObj); } else { diff --git a/src/forge/Wiki/utils.js b/src/forge/Wiki/utils.js new file mode 100644 index 000000000..c04eca2de --- /dev/null +++ b/src/forge/Wiki/utils.js @@ -0,0 +1,8 @@ +// 拼接\t +export function splicingTabs(count) { + var tabs = ""; + for (var i = 0; i < count; i++) { + tabs += "\t"; + } + return tabs; +} \ No newline at end of file