添加删除文件功能

This commit is contained in:
Eleven 2020-11-24 23:00:12 +08:00
parent 95db1ed7c4
commit 1493ebbe59
2 changed files with 79 additions and 4 deletions

View File

@ -96,4 +96,16 @@ export function getFileList(params) {
method: 'post',
data: params
})
}
/**
* 删除文件
* @param {id, path, name} params x
*/
export function deleteFile(params) {
return axios({
url: '/node/ssh/delete.json',
method: 'post',
data: params
})
}

View File

@ -33,7 +33,7 @@
</a-layout>
</template>
<script>
import { getRootFileList, getFileList } from '../../api/ssh';
import { getRootFileList, getFileList, deleteFile } from '../../api/ssh';
export default {
props: {
ssh: {
@ -46,6 +46,7 @@ export default {
listQuery: {},
treeList: [],
fileList: [],
tempNode: {},
tableHeight: '80vh',
replaceFields: {
children: 'children',
@ -57,7 +58,7 @@ export default {
{title: '文件类型', dataIndex: 'dir', width: 100, ellipsis: true, scopedSlots: {customRender: 'dir'}},
{title: '文件大小', dataIndex: 'size', width: 120, ellipsis: true, scopedSlots: {customRender: 'size'}},
{title: '修改时间', dataIndex: 'modifyTime', width: 170, ellipsis: true},
{title: '操作', dataIndex: 'operation', scopedSlots: {customRender: 'operation'}, width: 330}
{title: '操作', dataIndex: 'operation', scopedSlots: {customRender: 'operation'}, width: 280}
]
}
},
@ -93,7 +94,8 @@ export default {
},
//
onSelect(selectedKeys, {node}) {
return new Promise(resolve => {
return new Promise(resolve => {
this.tempNode = node.dataRef;
if (node.dataRef.disabled) {
resolve();
return;
@ -124,7 +126,10 @@ export default {
})
} else {
//
this.fileList.push(element);
this.fileList.push({
path: node.dataRef.path,
...element
});
}
})
//
@ -136,6 +141,40 @@ export default {
resolve();
});
},
//
loadFileList() {
if (!this.tempNode) {
this.$notification.warn({
message: '请选择一个节点',
duration: 2
});
return false;
}
//
const params = {
id: this.ssh.id,
path: this.tempNode.path,
children: this.tempNode.parentDir
}
this.fileList = [];
this.loading = true;
//
getFileList(params).then(res => {
if (res.code === 200) {
//
res.data.forEach(element => {
if (!element.dir) {
//
this.fileList.push({
path: this.tempNode.path,
...element
});
}
})
}
this.loading = false;
})
},
//
handlePreview(record) {
console.log(record)
@ -147,6 +186,30 @@ export default {
//
handleDelete(record) {
console.log(record)
this.$confirm({
title: '系统提示',
content: '真的要删除节点么?',
okText: '确认',
cancelText: '取消',
onOk: () => {
//
const params = {
id: this.ssh.id,
path: record.path,
name: record.parentDir
}
//
deleteFile(params).then((res) => {
if (res.code === 200) {
this.$notification.success({
message: res.msg,
duration: 2
});
this.loadFileList();
}
})
}
});
}
}
}