feat:只有点击文件时打开

This commit is contained in:
shixiaohua 2024-01-25 17:56:53 +08:00
parent 34fb22536f
commit a178134507
5 changed files with 54 additions and 35 deletions

View File

@ -1,6 +1,7 @@
import React, {useEffect, useMemo, useState} from 'react';
import {Input, Tree} from 'antd';
import {FolderOutlined, FileMarkdownOutlined} from '@ant-design/icons';
const {Search} = Input;
import store from "../../redux/store";
import {clickFile} from "../../redux/clickFile_reducer";
@ -52,6 +53,7 @@ function generateChildList(fileList){
}
return result;
}
const ItemTree = () => {
const [expandedKeys, setExpandedKeys] = useState([]);
const [searchValue, setSearchValue] = useState('');
@ -106,7 +108,7 @@ const ItemTree = () => {
setAutoExpandParent(true);
};
const onSelect = (selectedKeys, e) => {
if (e.selected){
if (e.selected && !e.node.dirFlag) {
console.log('onSelect.selectedKeys', selectedKeys, e)
store.dispatch(clickFile({"fileName": e.node.title, "filePath": e.node.key}))
}

View File

@ -11,6 +11,7 @@ import Hlexical from './Hlexical';
import ItemTree from "../../components/ItemTree";
import './index.less'
import store from "../../redux/store";
import {isEmpty} from "../../utils/ObjectUtils";
const {Header, Sider, Content} = Layout;
const Note = () => {
const [collapsed, setCollapsed] = useState(false);
@ -24,7 +25,7 @@ const Note = () => {
store.subscribe(() => {
const openFile = store.getState().clickFileMessage.data;
console.log("store.getState().clickFileMessage.data:",openFile,items)
if (items.filter(fileItem => fileItem.key === openFile.filePath).length === 0) {
if (items.filter(fileItem => fileItem.key === openFile.filePath).length === 0&& !isEmpty(openFile)) {
setItems([...items,
{
label: openFile.fileName,

View File

@ -3,6 +3,7 @@ import { createSlice } from '@reduxjs/toolkit'
export const clickFileSlice = createSlice({
name: 'clickFile',
initialState: {
type:"clickFile",
data: {}
},
reducers: {

View File

@ -0,0 +1,8 @@
const schema = {
"fileId": {
type: 'number',
maximum: 100,
minimum: 1,
default: 50
}
}

7
src/utils/ObjectUtils.js Normal file
View File

@ -0,0 +1,7 @@
export const isEmpty =(object)=>{
for(let key in object) {
if(object.hasOwnProperty(key))
return false;
}
return true;
}