mirror of
https://github.com/whyour/qinglong.git
synced 2025-05-22 22:36:06 +08:00
修复脚本管理增加文件夹
This commit is contained in:
parent
03a23f6f31
commit
8009634b44
|
@ -27,6 +27,7 @@ const EditScriptNameModal = ({
|
||||||
filename: string;
|
filename: string;
|
||||||
path: string;
|
path: string;
|
||||||
key: string;
|
key: string;
|
||||||
|
type: string;
|
||||||
}) => void;
|
}) => void;
|
||||||
}) => {
|
}) => {
|
||||||
const [form] = Form.useForm();
|
const [form] = Form.useForm();
|
||||||
|
@ -52,11 +53,12 @@ const EditScriptNameModal = ({
|
||||||
directory ? intl.get('创建文件夹成功') : intl.get('创建文件成功'),
|
directory ? intl.get('创建文件夹成功') : intl.get('创建文件成功'),
|
||||||
);
|
);
|
||||||
const key = path ? `${path}/` : '';
|
const key = path ? `${path}/` : '';
|
||||||
const filename = file ? file.name : inputFilename;
|
const filename = file ? file.name : (directory || inputFilename);
|
||||||
handleCancel({
|
handleCancel({
|
||||||
filename,
|
filename,
|
||||||
path,
|
path,
|
||||||
key: `${key}${filename}`,
|
key: `${key}${filename}`,
|
||||||
|
type: directory ? 'directory' : 'file',
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
setLoading(false);
|
setLoading(false);
|
||||||
|
|
|
@ -347,18 +347,29 @@ const Script = () => {
|
||||||
setIsAddFileModalVisible(true);
|
setIsAddFileModalVisible(true);
|
||||||
};
|
};
|
||||||
|
|
||||||
const addFileModalClose = (
|
const addFileModalClose = async (
|
||||||
{ filename, path, key }: { filename: string; path: string; key: string } = {
|
{
|
||||||
|
filename,
|
||||||
|
path,
|
||||||
|
key,
|
||||||
|
type,
|
||||||
|
}: { filename: string; path: string; key: string; type?: string } = {
|
||||||
filename: '',
|
filename: '',
|
||||||
path: '',
|
path: '',
|
||||||
key: '',
|
key: '',
|
||||||
},
|
},
|
||||||
) => {
|
) => {
|
||||||
if (filename) {
|
if (filename) {
|
||||||
let newData = [...data];
|
const res = await request.get(`${config.apiPrefix}scripts`);
|
||||||
const _file = { title: filename, key, parent: path };
|
let newData = res.data;
|
||||||
|
if (type === 'directory' && filename.includes('/')) {
|
||||||
|
const parts = filename.split('/');
|
||||||
|
parts.pop();
|
||||||
|
const parentPath = parts.join('/');
|
||||||
|
path = path ? `${path}/${parentPath}` : parentPath;
|
||||||
|
}
|
||||||
|
const item = findNode(newData, (c) => c.key === key);
|
||||||
if (path) {
|
if (path) {
|
||||||
newData = depthFirstSearch(newData, (c) => c.key === path, _file);
|
|
||||||
const keys = path.split('/');
|
const keys = path.split('/');
|
||||||
const sKeys: string[] = [];
|
const sKeys: string[] = [];
|
||||||
keys.reduce((p, c) => {
|
keys.reduce((p, c) => {
|
||||||
|
@ -366,35 +377,14 @@ const Script = () => {
|
||||||
return `${p}/${c}`;
|
return `${p}/${c}`;
|
||||||
});
|
});
|
||||||
setExpandedKeys([...expandedKeys, ...sKeys, path]);
|
setExpandedKeys([...expandedKeys, ...sKeys, path]);
|
||||||
} else {
|
|
||||||
newData.unshift(_file);
|
|
||||||
}
|
}
|
||||||
setData(newData);
|
setData(newData);
|
||||||
onSelect(_file.title, _file);
|
onSelect(item.title, item);
|
||||||
handleIsEditing(_file.title, true);
|
handleIsEditing(item.title, true);
|
||||||
}
|
}
|
||||||
setIsAddFileModalVisible(false);
|
setIsAddFileModalVisible(false);
|
||||||
};
|
};
|
||||||
|
|
||||||
const downloadFile = () => {
|
|
||||||
request
|
|
||||||
.post(`${config.apiPrefix}scripts/download`, {
|
|
||||||
filename: currentNode.title,
|
|
||||||
})
|
|
||||||
.then(({ code, data }) => {
|
|
||||||
if (code === 200) {
|
|
||||||
const blob = new Blob([data], { type: 'application/json' });
|
|
||||||
const url = URL.createObjectURL(blob);
|
|
||||||
const a = document.createElement('a');
|
|
||||||
a.href = url;
|
|
||||||
a.download = currentNode.title;
|
|
||||||
document.documentElement.appendChild(a);
|
|
||||||
a.click();
|
|
||||||
document.documentElement.removeChild(a);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
};
|
|
||||||
|
|
||||||
const initState = () => {
|
const initState = () => {
|
||||||
setSelect(intl.get('请选择脚本文件'));
|
setSelect(intl.get('请选择脚本文件'));
|
||||||
setCurrentNode(null);
|
setCurrentNode(null);
|
||||||
|
@ -703,10 +693,7 @@ const Script = () => {
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
) : (
|
) : (
|
||||||
<UnsupportedFilePreview
|
<UnsupportedFilePreview onForceOpen={handleForceOpen} />
|
||||||
filename={currentNode?.title || ''}
|
|
||||||
onForceOpen={handleForceOpen}
|
|
||||||
/>
|
|
||||||
)}
|
)}
|
||||||
</SplitPane>
|
</SplitPane>
|
||||||
)}
|
)}
|
||||||
|
|
|
@ -295,7 +295,7 @@ export function findNode<T extends Record<string, any> & { children?: T[] }>(
|
||||||
|
|
||||||
find(c);
|
find(c);
|
||||||
|
|
||||||
return item;
|
return item as T | undefined;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function logEnded(log: string): boolean {
|
export function logEnded(log: string): boolean {
|
||||||
|
|
Loading…
Reference in New Issue
Block a user