forked from Gitlink/forgeplus-react
同级文件夹名称重复bug fix
This commit is contained in:
parent
3c60293cd5
commit
dc686b3f7a
|
|
@ -179,14 +179,14 @@ export function findNodeByKey(list, key){
|
|||
}
|
||||
|
||||
// 找到children中有相同key的数组
|
||||
export function findNodeByChildrenKey(list, key){
|
||||
export function findBrotherNodesByKey(list, key){
|
||||
for (let index = 0; index < list.length; index++) {
|
||||
const element = list[index];
|
||||
if (element.key == key) {
|
||||
return list;
|
||||
}else if (element.children.length) {
|
||||
let result = findNodeByChildrenKey(element.children, key);
|
||||
if (result) {
|
||||
}else if (element.children && element.children.length) {
|
||||
let result = findBrotherNodesByKey(element.children, key);
|
||||
if (result.length) {
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@ import { Tree, Dropdown, Menu, message, Modal, Input } from 'antd';
|
|||
import DelModal from '../../components/ModalFun';
|
||||
import './index.scss';
|
||||
import '../../components/ModalFun/index.scss';
|
||||
import { deleteWiki, findNodeByChildrenKey, findNodeByKey, getWiki, treeToMd, updateWiki } from '../../api';
|
||||
import { deleteWiki, findBrotherNodesByKey, findNodeByKey, getWiki, treeToMd, updateWiki } from '../../api';
|
||||
import { useEffect } from 'react';
|
||||
import { Base64 } from 'js-base64';
|
||||
import { splicingTabs } from '../../utils';
|
||||
|
|
@ -356,20 +356,21 @@ export default function Sidebar(props) {
|
|||
}else{
|
||||
// isEditName 1 编辑目录名称 2编辑页面名称
|
||||
const titleToJudge = isEditName === 2 ? `[[${menuName}]]` : `- ${menuName}`;
|
||||
const {children, node, title, key} = visible;
|
||||
const list = findNodeByChildrenKey(menuList, key) || [];
|
||||
const {title, key} = visible;
|
||||
if(title.trim() === titleToJudge){
|
||||
setAddMenuError("请修改名称");
|
||||
return
|
||||
}
|
||||
// 找兄弟节点
|
||||
const list = findBrotherNodesByKey(menuList, key) || [];
|
||||
if(list.map(item=>item.title.trim()).includes(titleToJudge)){
|
||||
message.error("不能与同级目录名称相同");
|
||||
setAddMenuError("不能与同级目录名称相同");
|
||||
return
|
||||
}
|
||||
// wiki名称不可重复
|
||||
const sameNameWiki = fileArrInit.filter(item=>item.name === menuName)
|
||||
if(isEditName === 2 && sameNameWiki.length){
|
||||
message.error("wiki名称不可重复");
|
||||
setAddMenuError("wiki名称不可重复");
|
||||
return
|
||||
}
|
||||
// 编辑sidebar
|
||||
|
|
|
|||
Loading…
Reference in New Issue