2024-02-19 03:11:55 -05:00
|
|
|
|
import React, {useRef, useState} from 'react';
|
|
|
|
|
import {Input, message, Modal} from 'antd';
|
2024-02-19 23:38:49 -05:00
|
|
|
|
import {useDispatch, useSelector} from "react-redux";
|
2024-02-19 03:11:55 -05:00
|
|
|
|
import {newFile} from "../../../utils/File";
|
|
|
|
|
import {dirFileAdd} from "../../../redux/dirMessage_reducer";
|
|
|
|
|
import {addTableBarItem} from "../../../redux/tableBarItem_reducer";
|
|
|
|
|
import {isEmpty} from "../../../utils/ObjectUtils";
|
2024-02-20 01:57:14 -05:00
|
|
|
|
import {fileNameFormat, fullFileNameFormat} from "../../../utils/PathOperate";
|
2024-02-19 03:11:55 -05:00
|
|
|
|
|
|
|
|
|
const DirAddFile = (prop) => {
|
|
|
|
|
console.log("prop",prop)
|
|
|
|
|
const [isModalOpen, setIsModalOpen] = useState(false);
|
|
|
|
|
const dispatch = useDispatch();
|
|
|
|
|
const inputValue = useRef(null);
|
|
|
|
|
const [messageApi, contextHolder] = message.useMessage();
|
|
|
|
|
|
|
|
|
|
const showModal = () => {
|
|
|
|
|
setIsModalOpen(true);
|
|
|
|
|
};
|
|
|
|
|
const handleOk = () => {
|
|
|
|
|
console.log("inputValue",inputValue.current.input.value)
|
|
|
|
|
// 如果为空则提示
|
|
|
|
|
if (isEmpty(inputValue.current.input.value)){
|
|
|
|
|
let messageType = messageApi.open({
|
|
|
|
|
type: 'error',
|
|
|
|
|
content: '文件名不能为空',
|
|
|
|
|
});
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
// 新建文件
|
2024-02-22 03:11:01 -05:00
|
|
|
|
let fileName = inputValue.current.input.value+prop.fileExt;
|
2024-02-20 01:57:14 -05:00
|
|
|
|
let filePath = fullFileNameFormat(prop.fileDir,fileName)
|
|
|
|
|
newFile(filePath)
|
2024-02-19 03:11:55 -05:00
|
|
|
|
// 更新树
|
2024-02-20 01:57:14 -05:00
|
|
|
|
dispatch(dirFileAdd({"fileDir":prop.fileDir,"filePath":filePath,fileName}))
|
2024-02-19 03:11:55 -05:00
|
|
|
|
// 选中key,添加bar
|
|
|
|
|
dispatch(addTableBarItem({
|
2024-02-20 01:57:14 -05:00
|
|
|
|
label: fileName,
|
|
|
|
|
children: filePath,
|
|
|
|
|
key: filePath,
|
|
|
|
|
activeKey: filePath
|
2024-02-19 03:11:55 -05:00
|
|
|
|
}))
|
|
|
|
|
setIsModalOpen(false);
|
|
|
|
|
};
|
|
|
|
|
const handleCancel = () => {
|
|
|
|
|
setIsModalOpen(false);
|
|
|
|
|
};
|
|
|
|
|
return <>
|
|
|
|
|
{contextHolder}
|
2024-02-22 03:11:01 -05:00
|
|
|
|
<span className="menuItemClick" onClick={showModal}>{prop.fileExt}</span>
|
2024-02-19 03:11:55 -05:00
|
|
|
|
<Modal title="新建文件名" open={isModalOpen} onOk={handleOk} onCancel={handleCancel}>
|
|
|
|
|
<Input ref={inputValue} placeholder="文件名不能为空" />
|
|
|
|
|
</Modal>
|
|
|
|
|
</>;
|
|
|
|
|
};
|
|
|
|
|
export default DirAddFile;
|