添加现有代码V1.6
This commit is contained in:
@@ -0,0 +1,117 @@
|
||||
// 文件树和文件操作模块
|
||||
|
||||
let fileTree = null;
|
||||
|
||||
// 初始化文件树
|
||||
function initFileTree(onFileSelect) {
|
||||
if (!fileTree) {
|
||||
fileTree = $('#fileTree').jstree({
|
||||
'core': {
|
||||
'data': {
|
||||
'url': function(node) {
|
||||
const url = node.id === '#' ? '/api/script/list' : '/api/script/list?path=' + node.id;
|
||||
return url;
|
||||
},
|
||||
'data': function(node) {
|
||||
return { 'id': node.id };
|
||||
},
|
||||
'dataFilter': function(data) {
|
||||
var json = {};
|
||||
try {
|
||||
json = JSON.parse(data);
|
||||
} catch (e) {
|
||||
return "[]";
|
||||
}
|
||||
if (json.success && Array.isArray(json.data)) {
|
||||
return JSON.stringify(json.data);
|
||||
}
|
||||
return "[]";
|
||||
},
|
||||
'error': function(jqXHR, textStatus, errorThrown) {
|
||||
showToast('加载文件列表失败:' + textStatus);
|
||||
}
|
||||
},
|
||||
'themes': {
|
||||
'name': 'default',
|
||||
'responsive': true
|
||||
},
|
||||
'check_callback': true,
|
||||
'multiple': false
|
||||
},
|
||||
'types': {
|
||||
'default': {
|
||||
'icon': 'bi bi-file-text'
|
||||
},
|
||||
'folder': {
|
||||
'icon': 'bi bi-folder'
|
||||
},
|
||||
'python': {
|
||||
'icon': 'bi bi-filetype-py'
|
||||
},
|
||||
'json': {
|
||||
'icon': 'bi bi-filetype-json'
|
||||
},
|
||||
'shell': {
|
||||
'icon': 'bi bi-filetype-sh'
|
||||
}
|
||||
},
|
||||
'plugins': ['types']
|
||||
}).on('ready.jstree', function() {
|
||||
// 文件树初始化完成
|
||||
});
|
||||
|
||||
// 文件树节点点击事件
|
||||
$('#fileTree').on('select_node.jstree', function(e, data) {
|
||||
const node = data.node;
|
||||
if (node.original.type != 'folder') {
|
||||
if (onFileSelect) {
|
||||
onFileSelect(node.id);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
return fileTree;
|
||||
}
|
||||
|
||||
// 刷新文件树
|
||||
function refreshFileTree() {
|
||||
if (fileTree) {
|
||||
console.log('刷新文件树');
|
||||
$('#fileTree').jstree('refresh');
|
||||
}
|
||||
}
|
||||
|
||||
// 初始化文件操作按钮事件
|
||||
function initFileOperations(saveFileCallback, deleteFileCallback) {
|
||||
// 保存文件
|
||||
$('#saveFile').click(function() {
|
||||
if (saveFileCallback) {
|
||||
saveFileCallback();
|
||||
}
|
||||
});
|
||||
|
||||
// 删除文件
|
||||
$('#deleteFile').click(function() {
|
||||
if (deleteFileCallback) {
|
||||
deleteFileCallback();
|
||||
}
|
||||
});
|
||||
|
||||
// 刷新文件树
|
||||
$('#refreshTree').click(function() {
|
||||
refreshFileTree();
|
||||
});
|
||||
}
|
||||
|
||||
// 获取文件树实例
|
||||
function getFileTree() {
|
||||
return fileTree;
|
||||
}
|
||||
|
||||
// 导出模块
|
||||
export {
|
||||
initFileTree,
|
||||
refreshFileTree,
|
||||
initFileOperations,
|
||||
getFileTree
|
||||
};
|
||||
Reference in New Issue
Block a user