mirror of
https://github.com/whyour/qinglong.git
synced 2026-08-12 03:10:48 +08:00
修复脚本管理删除、新建增加选择父目录
This commit is contained in:
+57
-14
@@ -113,7 +113,7 @@ const Script = ({ headerStyle, isPhone, theme }: any) => {
|
||||
setValue('加载中...');
|
||||
const newMode = value ? LangMap[value.slice(-3)] : '';
|
||||
setMode(isPhone && newMode === 'typescript' ? 'javascript' : newMode);
|
||||
setSelect(value);
|
||||
setSelect(node.key);
|
||||
setTitle(node.parent || node.value);
|
||||
setCurrentNode(node);
|
||||
getDetail(node);
|
||||
@@ -167,7 +167,7 @@ const Script = ({ headerStyle, isPhone, theme }: any) => {
|
||||
const cancelEdit = () => {
|
||||
setIsEditing(false);
|
||||
setValue('加载中...');
|
||||
getDetail({ value: select });
|
||||
getDetail(currentNode);
|
||||
};
|
||||
|
||||
const saveFile = () => {
|
||||
@@ -177,7 +177,7 @@ const Script = ({ headerStyle, isPhone, theme }: any) => {
|
||||
<>
|
||||
确认保存文件
|
||||
<Text style={{ wordBreak: 'break-all' }} type="warning">
|
||||
{select}
|
||||
{currentNode.value}
|
||||
</Text>{' '}
|
||||
,保存后不可恢复
|
||||
</>
|
||||
@@ -190,7 +190,7 @@ const Script = ({ headerStyle, isPhone, theme }: any) => {
|
||||
request
|
||||
.put(`${config.apiPrefix}scripts`, {
|
||||
data: {
|
||||
filename: select,
|
||||
filename: currentNode.value,
|
||||
path: currentNode.parent || '',
|
||||
content,
|
||||
},
|
||||
@@ -230,15 +230,30 @@ const Script = ({ headerStyle, isPhone, theme }: any) => {
|
||||
request
|
||||
.delete(`${config.apiPrefix}scripts`, {
|
||||
data: {
|
||||
filename: select,
|
||||
filename: currentNode.value,
|
||||
path: currentNode.parent || '',
|
||||
},
|
||||
})
|
||||
.then((_data: any) => {
|
||||
if (_data.code === 200) {
|
||||
message.success(`删除成功`);
|
||||
let newData = [...data];
|
||||
const index = newData.findIndex((x) => x.value === select);
|
||||
newData.splice(index, 1);
|
||||
if (currentNode.parent) {
|
||||
const parentNodeIndex = newData.findIndex(
|
||||
(x) => x.key === currentNode.parent,
|
||||
);
|
||||
const parentNode = newData[parentNodeIndex];
|
||||
const index = parentNode.children.findIndex(
|
||||
(y) => y.key === currentNode.key,
|
||||
);
|
||||
parentNode.children.splice(index, 1);
|
||||
newData.splice(parentNodeIndex, 1, { ...parentNode });
|
||||
} else {
|
||||
const index = newData.findIndex(
|
||||
(x) => x.key === currentNode.key,
|
||||
);
|
||||
newData.splice(index, 1);
|
||||
}
|
||||
setData(newData);
|
||||
} else {
|
||||
message.error(_data);
|
||||
@@ -256,12 +271,27 @@ const Script = ({ headerStyle, isPhone, theme }: any) => {
|
||||
};
|
||||
|
||||
const addFileModalClose = (
|
||||
{ filename }: { filename: string } = { filename: '' },
|
||||
{ filename, path, key }: { filename: string; path: string; key: string } = {
|
||||
filename: '',
|
||||
path: '',
|
||||
key: '',
|
||||
},
|
||||
) => {
|
||||
if (filename) {
|
||||
const newData = [...data];
|
||||
const _file = { title: filename, key: filename, value: filename };
|
||||
newData.unshift(_file);
|
||||
const _file = { title: filename, key, value: filename, parent: path };
|
||||
if (path) {
|
||||
const parentNodeIndex = newData.findIndex((x) => x.key === path);
|
||||
const parentNode = newData[parentNodeIndex];
|
||||
if (parentNode.children && parentNode.children.length > 0) {
|
||||
parentNode.children.unshift(_file);
|
||||
} else {
|
||||
parentNode.children = [_file];
|
||||
}
|
||||
newData.splice(parentNodeIndex, 1, { ...parentNode });
|
||||
} else {
|
||||
newData.unshift(_file);
|
||||
}
|
||||
setData(newData);
|
||||
onSelect(_file.value, _file);
|
||||
setIsEditing(true);
|
||||
@@ -273,7 +303,7 @@ const Script = ({ headerStyle, isPhone, theme }: any) => {
|
||||
request
|
||||
.post(`${config.apiPrefix}scripts/download`, {
|
||||
data: {
|
||||
filename: select,
|
||||
filename: currentNode.value,
|
||||
},
|
||||
})
|
||||
.then((_data: any) => {
|
||||
@@ -281,7 +311,7 @@ const Script = ({ headerStyle, isPhone, theme }: any) => {
|
||||
const url = URL.createObjectURL(blob);
|
||||
const a = document.createElement('a');
|
||||
a.href = url;
|
||||
a.download = select;
|
||||
a.download = currentNode.value;
|
||||
document.documentElement.appendChild(a);
|
||||
a.click();
|
||||
document.documentElement.removeChild(a);
|
||||
@@ -319,10 +349,20 @@ const Script = ({ headerStyle, isPhone, theme }: any) => {
|
||||
<Menu.Item key="add" icon={<PlusOutlined />} onClick={addFile}>
|
||||
添加
|
||||
</Menu.Item>
|
||||
<Menu.Item key="edit" icon={<EditOutlined />} onClick={editFile}>
|
||||
<Menu.Item
|
||||
key="edit"
|
||||
icon={<EditOutlined />}
|
||||
onClick={editFile}
|
||||
disabled={!select}
|
||||
>
|
||||
编辑
|
||||
</Menu.Item>
|
||||
<Menu.Item key="delete" icon={<DeleteOutlined />} onClick={deleteFile}>
|
||||
<Menu.Item
|
||||
key="delete"
|
||||
icon={<DeleteOutlined />}
|
||||
onClick={deleteFile}
|
||||
disabled={!select}
|
||||
>
|
||||
删除
|
||||
</Menu.Item>
|
||||
</Menu>
|
||||
@@ -368,6 +408,7 @@ const Script = ({ headerStyle, isPhone, theme }: any) => {
|
||||
</Tooltip>,
|
||||
<Tooltip title="编辑">
|
||||
<Button
|
||||
disabled={!select}
|
||||
type="primary"
|
||||
onClick={editFile}
|
||||
icon={<EditOutlined />}
|
||||
@@ -376,6 +417,7 @@ const Script = ({ headerStyle, isPhone, theme }: any) => {
|
||||
<Tooltip title="删除">
|
||||
<Button
|
||||
type="primary"
|
||||
disabled={!select}
|
||||
onClick={deleteFile}
|
||||
icon={<DeleteOutlined />}
|
||||
/>
|
||||
@@ -459,6 +501,7 @@ const Script = ({ headerStyle, isPhone, theme }: any) => {
|
||||
/>
|
||||
<EditScriptNameModal
|
||||
visible={isAddFileModalVisible}
|
||||
treeData={data}
|
||||
handleCancel={addFileModalClose}
|
||||
/>
|
||||
</div>
|
||||
|
||||
Reference in New Issue
Block a user