feat:更新和移除目录
This commit is contained in:
parent
9adb97e9f6
commit
dc537ef714
|
@ -1,6 +1,7 @@
|
||||||
import React, {useEffect, useMemo, useState} from 'react';
|
import React, {useEffect, useMemo, useState} from 'react';
|
||||||
import {Input, Tree} from 'antd';
|
import {Input, Tree} from 'antd';
|
||||||
import {FolderOutlined, FileMarkdownOutlined, FileOutlined} from '@ant-design/icons';
|
import {FolderOutlined, FileMarkdownOutlined, FileOutlined, DeleteOutlined, RedoOutlined} from '@ant-design/icons';
|
||||||
|
import {message, Popconfirm} from 'antd';
|
||||||
import "./index.less"
|
import "./index.less"
|
||||||
|
|
||||||
const {Search} = Input;
|
const {Search} = Input;
|
||||||
|
@ -51,7 +52,7 @@ function generateChildList(fileList) {
|
||||||
}
|
}
|
||||||
result.push({
|
result.push({
|
||||||
"key": filePath,
|
"key": filePath,
|
||||||
"title": fileName,
|
"title": titleExtended(fileName,dirFlag),
|
||||||
"icon": dirFlag ? <FolderOutlined/> : fileName.endsWith(".md") ? <FileMarkdownOutlined/> : <FileOutlined/>,
|
"icon": dirFlag ? <FolderOutlined/> : fileName.endsWith(".md") ? <FileMarkdownOutlined/> : <FileOutlined/>,
|
||||||
"dirFlag": dirFlag,
|
"dirFlag": dirFlag,
|
||||||
"children": childListM
|
"children": childListM
|
||||||
|
@ -60,6 +61,41 @@ function generateChildList(fileList) {
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const titleExtended = (fileName, dirFlag) => {
|
||||||
|
|
||||||
|
const confirm = (e) => {
|
||||||
|
console.log(e);
|
||||||
|
message.success('Click on Yes');
|
||||||
|
};
|
||||||
|
const cancel = (e) => {
|
||||||
|
console.log(e);
|
||||||
|
message.error('Click on No');
|
||||||
|
};
|
||||||
|
return <span >{fileName}
|
||||||
|
{dirFlag && <span style={{float: "right"}}>
|
||||||
|
<Popconfirm
|
||||||
|
title="更新当前目录"
|
||||||
|
description="更新当前目录内容"
|
||||||
|
onConfirm={confirm}
|
||||||
|
onCancel={cancel}
|
||||||
|
okText="确认"
|
||||||
|
cancelText="取消"
|
||||||
|
>
|
||||||
|
<RedoOutlined/>
|
||||||
|
</Popconfirm>
|
||||||
|
<Popconfirm
|
||||||
|
title="关闭当前目录"
|
||||||
|
description="从列表中移除目录并不会删除本地文件"
|
||||||
|
onConfirm={confirm}
|
||||||
|
onCancel={cancel}
|
||||||
|
okText="确认"
|
||||||
|
cancelText="取消"
|
||||||
|
>
|
||||||
|
<DeleteOutlined/>
|
||||||
|
</Popconfirm>
|
||||||
|
</span>}
|
||||||
|
</span>
|
||||||
|
}
|
||||||
/**
|
/**
|
||||||
* 将文件信息改为树信息
|
* 将文件信息改为树信息
|
||||||
* @param fileDirDate
|
* @param fileDirDate
|
||||||
|
@ -78,17 +114,18 @@ const flushTree = (fileDirDate) => {
|
||||||
}
|
}
|
||||||
defaultValueStateSet.push({
|
defaultValueStateSet.push({
|
||||||
"key": filePath,
|
"key": filePath,
|
||||||
"title": fileName,
|
"title": titleExtended(fileName.substring(fileName.lastIndexOf("/")+1), dirFlag),
|
||||||
"icon": <FolderOutlined/>,
|
"icon": <FolderOutlined/>,
|
||||||
"dirFlag": dirFlag,
|
"dirFlag": dirFlag,
|
||||||
"children": childListM
|
"children": childListM
|
||||||
});
|
});
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return defaultValueStateSet;
|
return defaultValueStateSet;
|
||||||
}
|
}
|
||||||
const ItemTree = (prop) => {
|
const ItemTree = (prop) => {
|
||||||
console.log("prop.filePath:",prop.filePath)
|
console.log("prop.filePath:", prop.filePath)
|
||||||
const [expandedKeys, setExpandedKeys] = useState([]);
|
const [expandedKeys, setExpandedKeys] = useState([]);
|
||||||
const [searchValue, setSearchValue] = useState('');
|
const [searchValue, setSearchValue] = useState('');
|
||||||
const dispatch = useDispatch()
|
const dispatch = useDispatch()
|
||||||
|
@ -105,7 +142,7 @@ const ItemTree = (prop) => {
|
||||||
|
|
||||||
const addChildNode = (valueState, fileStateList) => {
|
const addChildNode = (valueState, fileStateList) => {
|
||||||
valueState.forEach(file => {
|
valueState.forEach(file => {
|
||||||
if (fileStateList[0].key.startsWith(file.key)){
|
if (fileStateList[0].key.startsWith(file.key)) {
|
||||||
if (file.key === fileStateList[0].key) {
|
if (file.key === fileStateList[0].key) {
|
||||||
file.children = fileStateList[0].children
|
file.children = fileStateList[0].children
|
||||||
} else if (Array.isArray(file.children) && file.children.length > 0) {
|
} else if (Array.isArray(file.children) && file.children.length > 0) {
|
||||||
|
@ -141,7 +178,7 @@ const ItemTree = (prop) => {
|
||||||
// 添加下级节点
|
// 添加下级节点
|
||||||
addChildNode(defaultValueState, flushTree(fileStateList))
|
addChildNode(defaultValueState, flushTree(fileStateList))
|
||||||
const result = [...defaultValueState]
|
const result = [...defaultValueState]
|
||||||
console.log("[...defaultValueState]:",result)
|
console.log("[...defaultValueState]:", result)
|
||||||
setDefaultValueState(result)
|
setDefaultValueState(result)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
@ -192,7 +229,7 @@ const ItemTree = (prop) => {
|
||||||
// return loop(defaultData);
|
// return loop(defaultData);
|
||||||
// }, [searchValue]);
|
// }, [searchValue]);
|
||||||
return (
|
return (
|
||||||
<div>
|
<div style={{height: "100%"}}>
|
||||||
<Search
|
<Search
|
||||||
style={{marginBottom: 8,}}
|
style={{marginBottom: 8,}}
|
||||||
placeholder="Search"
|
placeholder="Search"
|
||||||
|
|
|
@ -1,7 +1,28 @@
|
||||||
@import '~antd/dist/antd.less';
|
@import '~antd/dist/antd.less';
|
||||||
.ant-tree-node-content-wrapper {
|
.ant-tree-node-content-wrapper {
|
||||||
display: inline-block;
|
display: inline-block;
|
||||||
width: 176px;
|
width: 200px;
|
||||||
|
white-space: nowrap;
|
||||||
|
overflow: hidden;
|
||||||
|
text-overflow: ellipsis;
|
||||||
|
}
|
||||||
|
.ant-tree-treenode-switcher-close{
|
||||||
|
display: inline-block;
|
||||||
|
width: 200px;
|
||||||
|
white-space: nowrap;
|
||||||
|
overflow: hidden;
|
||||||
|
text-overflow: ellipsis;
|
||||||
|
}
|
||||||
|
.ant-tree-treenode-switcher-close{
|
||||||
|
display: inline-block;
|
||||||
|
width: 200px;
|
||||||
|
white-space: nowrap;
|
||||||
|
overflow: hidden;
|
||||||
|
text-overflow: ellipsis;
|
||||||
|
}
|
||||||
|
.ant-tree-treenode-switcher-open{
|
||||||
|
display: inline-block;
|
||||||
|
width: 200px;
|
||||||
white-space: nowrap;
|
white-space: nowrap;
|
||||||
overflow: hidden;
|
overflow: hidden;
|
||||||
text-overflow: ellipsis;
|
text-overflow: ellipsis;
|
||||||
|
|
|
@ -1,4 +1,8 @@
|
||||||
.HlexicalName {
|
.HlexicalName {
|
||||||
height: 100vh;
|
// 顶上有标题设置100h后下面会多处一部分
|
||||||
|
// height: 100vh;
|
||||||
width: auto;
|
width: auto;
|
||||||
}
|
}
|
||||||
|
.ant-tabs-top .ant-tabs-nav{
|
||||||
|
margin-bottom: 0;
|
||||||
|
}
|
|
@ -16,13 +16,30 @@ export const dirMessageSlice = createSlice({
|
||||||
dirAdd: (state, action) => {
|
dirAdd: (state, action) => {
|
||||||
console.log("dirMessage:dirAdd", state, action)
|
console.log("dirMessage:dirAdd", state, action)
|
||||||
if (action.payload) {
|
if (action.payload) {
|
||||||
// 新添加进来的目录,要判断是否重复,如果重复则提示
|
// 新添加进来的目录,要判断是否包含或者被包含,如果包含则统一树结构
|
||||||
let filter = state.data.filter((fileMessage) =>
|
let fileFilter = state.data.filter((fileMessage) =>
|
||||||
fileMessage.filePath === action.payload[0].filePath
|
fileMessage.filePath.startsWith(action.payload[0].filePath)
|
||||||
);
|
);
|
||||||
if (filter.length > 0) {
|
let actionFilter = state.data.filter((fileMessage) =>
|
||||||
console.log('filter', filter)
|
action.payload[0].filePath.startsWith(fileMessage.filePath)
|
||||||
} else {
|
);
|
||||||
|
let equalsFilter = state.data.filter((fileMessage) =>
|
||||||
|
action.payload[0].filePath===fileMessage.filePath
|
||||||
|
);
|
||||||
|
// 打开相同目录不用处理
|
||||||
|
if (equalsFilter.length > 0) {
|
||||||
|
console.log('equalsFilter', filter)
|
||||||
|
}
|
||||||
|
// 打开上级目录
|
||||||
|
else if (actionFilter.length>0){
|
||||||
|
|
||||||
|
}
|
||||||
|
// 打开下级目录
|
||||||
|
else if (fileFilter.length>0){
|
||||||
|
|
||||||
|
}
|
||||||
|
// 无关目录
|
||||||
|
else {
|
||||||
// 添加进当前目录
|
// 添加进当前目录
|
||||||
state.data = [...new Set([...state.data, ...action.payload])];
|
state.data = [...new Set([...state.data, ...action.payload])];
|
||||||
console.log('state.data:', state.data)
|
console.log('state.data:', state.data)
|
||||||
|
|
|
@ -1,8 +0,0 @@
|
||||||
const schema = {
|
|
||||||
"fileId": {
|
|
||||||
type: 'number',
|
|
||||||
maximum: 100,
|
|
||||||
minimum: 1,
|
|
||||||
default: 50
|
|
||||||
}
|
|
||||||
}
|
|
Loading…
Reference in New Issue