撤回wiki名称支持特殊字符修改
This commit is contained in:
parent
c440b60d97
commit
88e2d00368
|
|
@ -18,7 +18,7 @@ export default Form.create()(({ form, history, showNotification, projectDetail,
|
|||
let wikiName = ''
|
||||
let key = '';
|
||||
if (!pathname.endsWith('/wiki/add')) {
|
||||
wikiName = pathname.split('/')[4];
|
||||
wikiName = decodeURI(pathname.split('/')[4]);
|
||||
key = pathname.split('/')[5];
|
||||
}else{
|
||||
key = search.split('=').pop();
|
||||
|
|
@ -116,6 +116,12 @@ export default Form.create()(({ form, history, showNotification, projectDetail,
|
|||
};
|
||||
validateFields((err, values) => {
|
||||
if (!err) {
|
||||
let regEn = /[\\/:*?"<>|[\]-]/g;
|
||||
if (regEn.test(values.title)) {
|
||||
message.error('文件名不能有特殊字符: \\ / : * ? \" < > | [ \] -');
|
||||
setOperateFlag(false);
|
||||
return;
|
||||
}
|
||||
const {md_content, title} = values;
|
||||
if (wikiName && search!== "?copy") {
|
||||
updateWiki({
|
||||
|
|
@ -124,7 +130,7 @@ export default Form.create()(({ form, history, showNotification, projectDetail,
|
|||
projectId: project.id,
|
||||
pageName: wikiName,
|
||||
title,
|
||||
message: '',
|
||||
commit_message: '',
|
||||
content_base64: Base64.encode(md_content)
|
||||
}).then(res => dealRes(res, title));
|
||||
} else {
|
||||
|
|
@ -217,7 +223,7 @@ export default Form.create()(({ form, history, showNotification, projectDetail,
|
|||
projectId: project.id,
|
||||
pageName: '_Sidebar',
|
||||
title: '_Sidebar',
|
||||
message: '',
|
||||
commit_message: '',
|
||||
content_base64: Base64.encode(content)
|
||||
}).then(res => {
|
||||
if (res && res.message === "200") {
|
||||
|
|
@ -327,7 +333,7 @@ export default Form.create()(({ form, history, showNotification, projectDetail,
|
|||
"title",
|
||||
[
|
||||
{ required: true, message: "请输入标题" },
|
||||
{ pattern: /^(?!-).*$/, message: '不能以-开头' }
|
||||
// { pattern: /[^`\[\]\/:*?''<>|%-+_]/g, message: '不允许部分特殊字符' }
|
||||
],
|
||||
<Input
|
||||
placeholder={"请输入标题"}
|
||||
|
|
|
|||
|
|
@ -115,7 +115,7 @@ export default (props) => {
|
|||
project && checkItem.name && getWiki({
|
||||
owner: owner,
|
||||
repo: projectsId,
|
||||
pageName: checkItem.sub_url,
|
||||
pageName: checkItem.name,
|
||||
projectId: project.id
|
||||
}).then(res => {
|
||||
if (res && res.message === "200") {
|
||||
|
|
@ -190,6 +190,11 @@ export default (props) => {
|
|||
setAddMenuError("不能仅输入空格");
|
||||
return;
|
||||
}
|
||||
const regEn = /[\\/:*?"<>|[\]-]/g;
|
||||
if (regEn.test(menuName)) {
|
||||
setAddMenuError("不能有特殊字符: \\ / : * ? \" < > | [ \] -");
|
||||
return;
|
||||
}
|
||||
// 校验一级目录中是否有相同名称
|
||||
const oneMenuList = fileList.filter(item=>!item.title.trim().startsWith('[[')).map(i=>i.title.trim())
|
||||
if(oneMenuList.includes(`- ${menuName}`)){
|
||||
|
|
@ -210,7 +215,7 @@ export default (props) => {
|
|||
projectId: project.id,
|
||||
pageName: '_Sidebar',
|
||||
title: '_Sidebar',
|
||||
message: '',
|
||||
commit_message: '',
|
||||
content_base64: Base64.encode(treeToMd(sidebarList))
|
||||
}).then(res => {
|
||||
if (res && res.message === "200") {
|
||||
|
|
@ -228,7 +233,7 @@ export default (props) => {
|
|||
}
|
||||
|
||||
function goEdit(params) {
|
||||
history.push(`/${owner}/${projectsId}/wiki/${encodeURI(checkItem.sub_url)}/${checkItem.key}/edit${params}`);
|
||||
history.push(`/${owner}/${projectsId}/wiki/${encodeURI(checkItem.name)}/${checkItem.key}/edit${params}`);
|
||||
}
|
||||
|
||||
function preview() {
|
||||
|
|
|
|||
|
|
@ -63,7 +63,7 @@ export default (props) => {
|
|||
projectsId && checkItem.name && getWiki({
|
||||
owner: owner,
|
||||
repo: projectsId,
|
||||
pageName: checkItem.sub_url,
|
||||
pageName: checkItem.name,
|
||||
projectId: projectId,
|
||||
}).then(res => {
|
||||
if (res && res.message === "200") {
|
||||
|
|
|
|||
|
|
@ -116,16 +116,13 @@ export function markdownToTree(markdownText){
|
|||
lines.map((item, index) =>{
|
||||
const title = item.trim();
|
||||
const isFile = title.startsWith('[[') && title.endsWith(']]');
|
||||
const titleStr = isFile ? title.substring(2, title.length - 2) : title.substring(2, title.length)
|
||||
const node = {
|
||||
// 带空格+[[]]或者- 标识
|
||||
title: item,
|
||||
children: [],
|
||||
key: undefined,
|
||||
// 纯内容
|
||||
titleStr,
|
||||
// 编码后的title,获取wiki内容用title_sub
|
||||
title_sub: encodeURIComponent(titleStr),
|
||||
titleStr: isFile ? title.substring(2, title.length - 2) : title.substring(2, title.length),
|
||||
// 是否是wiki文件
|
||||
isFile: isFile
|
||||
}
|
||||
|
|
|
|||
|
|
@ -163,7 +163,7 @@ export default function Sidebar(props) {
|
|||
const {node, children, key} = item;
|
||||
if(isFile){
|
||||
// 删除页面
|
||||
deleteWiki({owner: owner, repo: projectsId, projectId: project.id, pageName: item.title_sub}).then(res => {
|
||||
deleteWiki({owner: owner, repo: projectsId, projectId: project.id, pageName: title}).then(res => {
|
||||
if(res && res.message === "204"){
|
||||
// 递归过滤相同key值的节点,执行删除操作
|
||||
const menuListByDel = findSameKeyByDel(menuList, key);
|
||||
|
|
@ -267,7 +267,7 @@ export default function Sidebar(props) {
|
|||
projectId: project.id,
|
||||
pageName: '_Sidebar',
|
||||
title: '_Sidebar',
|
||||
message: '',
|
||||
commit_message: '',
|
||||
content_base64: Base64.encode(content)
|
||||
}).then(res => {
|
||||
if (res && res.message === "200") {
|
||||
|
|
@ -303,18 +303,20 @@ export default function Sidebar(props) {
|
|||
e.stopPropagation();
|
||||
setVisible(item);
|
||||
setIsEditName(type);
|
||||
const {titleStr, title_sub} = item;
|
||||
let title = item.title.trim();
|
||||
const isFile = title.startsWith('[[') && title.endsWith(']]');
|
||||
title = isFile ? title.substring(2,title.length-2) : title.substring(2, title.length);
|
||||
type === 2 && getWiki({
|
||||
owner: owner,
|
||||
repo: projectsId,
|
||||
pageName: title_sub,
|
||||
pageName: title,
|
||||
projectId: project.id
|
||||
}).then(res => {
|
||||
if (res && res.message === "200") {
|
||||
setWikiContent(res.data.md_content);
|
||||
}
|
||||
})
|
||||
setMenuName(titleStr);
|
||||
setMenuName(title);
|
||||
}
|
||||
|
||||
// 新增子目录 或者 重命名目录
|
||||
|
|
@ -327,8 +329,9 @@ export default function Sidebar(props) {
|
|||
setAddMenuError("不能仅输入空格");
|
||||
return;
|
||||
}
|
||||
if (isEditName === 2 && /^-/.test(menuName)) {
|
||||
setAddMenuError('不能以-开头');
|
||||
const regEn = /[\\/:*?"<>|[\]-]/g;
|
||||
if (regEn.test(menuName)) {
|
||||
setAddMenuError('不能有特殊字符: \\ / : * ? \" < > | [ \] -');
|
||||
return;
|
||||
}
|
||||
if(!isEditName){
|
||||
|
|
@ -353,15 +356,14 @@ export default function Sidebar(props) {
|
|||
}else{
|
||||
// isEditName 1 编辑目录名称 2编辑页面名称
|
||||
const titleToJudge = isEditName === 2 ? `[[${menuName}]]` : `- ${menuName}`;
|
||||
const {key, titleStr, title_sub} = visible;
|
||||
// 判断是否有修改名称
|
||||
if(titleStr === menuName){
|
||||
const {title, key} = visible;
|
||||
if(title.trim() === titleToJudge){
|
||||
setAddMenuError("请修改名称");
|
||||
return
|
||||
}
|
||||
// 找兄弟节点
|
||||
const list = findBrotherNodesByKey(menuList, key) || [];
|
||||
if(list.map(item=>item.titleStr).includes(menuName)){
|
||||
if(list.map(item=>item.title.trim()).includes(titleToJudge)){
|
||||
setAddMenuError("不能与同级目录名称相同");
|
||||
return
|
||||
}
|
||||
|
|
@ -379,16 +381,17 @@ export default function Sidebar(props) {
|
|||
})
|
||||
if(isEditName === 2){
|
||||
// 编辑页面名称-> 修改wiki
|
||||
const oldTitle = title.substring(title.indexOf('[[')+2, title.indexOf(']]'))
|
||||
updateWiki({
|
||||
owner,
|
||||
repo: projectsId,
|
||||
projectId: project.id,
|
||||
// 原名称
|
||||
pageName: title_sub,
|
||||
pageName: oldTitle,
|
||||
// 现名称
|
||||
title: menuName,
|
||||
content_base64: wikiContent,
|
||||
message: '',
|
||||
commit_message: '',
|
||||
}).then(res=>{
|
||||
if(res && res.message === '200'){
|
||||
// 修改wiki名称接口请求成功,更新sidebar
|
||||
|
|
|
|||
|
|
@ -59,8 +59,10 @@ export default function UploadWiki(props) {
|
|||
message.error('只能上传md、txt文件');
|
||||
return false;
|
||||
}
|
||||
if (/^-/.test(file.name)) {
|
||||
message.error('文件名不能以-开头');
|
||||
|
||||
let regEn = /[\\/:*?"<>|[\]-]/g;
|
||||
if (regEn.test(file.name)) {
|
||||
message.error('文件名不能有特殊字符: \\ / : * ? \" < > | [ \] -');
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
@ -84,7 +86,7 @@ export default function UploadWiki(props) {
|
|||
projectId: project.id,
|
||||
pageName: '_Sidebar',
|
||||
title: '_Sidebar',
|
||||
message: '',
|
||||
commit_message: '',
|
||||
content_base64: Base64.encode(treeToMd(sidebarList))
|
||||
}).then(res => {
|
||||
if (res && res.message === "200") {
|
||||
|
|
|
|||
Loading…
Reference in New Issue