fix some bug
This commit is contained in:
@@ -124,6 +124,7 @@ document.getElementById("renameOption").onclick = () => {
|
||||
selectedItem.name = newName;
|
||||
selectedItem.div.textContent = newName;
|
||||
loadFileTree();
|
||||
showNotification('success', '文件已成功重命名!');
|
||||
});
|
||||
|
||||
}
|
||||
@@ -146,6 +147,7 @@ document.getElementById("copyOption").onclick = () => {
|
||||
if (selectedItem) {
|
||||
copiedItem = selectedItem;
|
||||
console.log("Item copied:", copiedItem);
|
||||
showNotification('info', '文件已成功复制!');
|
||||
}
|
||||
hideContextMenu();
|
||||
};
|
||||
@@ -160,7 +162,7 @@ document.getElementById("pasteOption").onclick = (event) => {
|
||||
newPath = selectedItem.path;
|
||||
}
|
||||
fetch(`/vsc-like/copy-files`, { method: 'POST', body: JSON.stringify({ oldPath: copiedItem.path+'/'+copiedItem.name, newPath: newPath }) , headers: { 'Content-Type': 'application/json' } })
|
||||
.then(() => loadFileTree());
|
||||
.then(() => {loadFileTree();showNotification('success', '文件已成功粘贴!')});
|
||||
console.log("Item pasted:", selectedItem);
|
||||
}
|
||||
hideContextMenu();
|
||||
@@ -172,7 +174,7 @@ document.getElementById("deleteOption").onclick = (event) => {
|
||||
if (confirm("Are you sure you want to delete selected file/folder?")) {
|
||||
if (selectedItem) {
|
||||
fetch(`/vsc-like/delete-file`, { method: 'POST', body: JSON.stringify({ path: selectedItem.path+'/'+selectedItem.name }) , headers: { 'Content-Type': 'application/json' } })
|
||||
.then(() => loadFileTree());
|
||||
.then(() => {loadFileTree();showNotification('success', '文件已成功删除!')});
|
||||
}
|
||||
}
|
||||
hideContextMenu();
|
||||
@@ -257,6 +259,8 @@ function loadFileContent(item) {
|
||||
editor.setValue(data.content);
|
||||
}
|
||||
});
|
||||
// 设置编辑器语言
|
||||
setEditorLanguageBasedOnFile(item.name);
|
||||
// code-like 打开文件
|
||||
ChangeActiveTextEditor(item.path+'/'+item.name);
|
||||
}
|
||||
@@ -278,15 +282,15 @@ function createNewFile(event) {
|
||||
if (selectedItem) {
|
||||
if (selectedItem.type === 'directory') {
|
||||
fetch(`/vsc-like/create-file`, { method: 'POST', body: JSON.stringify({ path: fileName, parent: selectedItem.path+'/'+selectedItem.name }) , headers: { 'Content-Type': 'application/json' } })
|
||||
.then(() => loadFileTree());
|
||||
.then(() => {loadFileTree();showNotification('success', '文件已成功创建!')});
|
||||
} else {
|
||||
console.log("selectedItem.path",selectedItem.path);
|
||||
fetch(`/vsc-like/create-file`, { method: 'POST', body: JSON.stringify({ path: fileName, parent: selectedItem.path }) , headers: { 'Content-Type': 'application/json' } })
|
||||
.then(() => loadFileTree());
|
||||
.then(() => {loadFileTree();showNotification('success', '文件已成功创建!')});
|
||||
}
|
||||
}else{
|
||||
fetch(`/vsc-like/create-file`, { method: 'POST', body: JSON.stringify({ path: fileName, parent: '.' }) , headers: { 'Content-Type': 'application/json' } })
|
||||
.then(() => loadFileTree());
|
||||
.then(() => {loadFileTree();showNotification('success', '文件已成功创建!')});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -299,21 +303,48 @@ function createNewFolder(event) {
|
||||
if (folderName) {
|
||||
if (selectedItem) {
|
||||
if (selectedItem.type === 'directory') {
|
||||
fetch(`/vsc-like/create-folder`, { method: 'POST', body: JSON.stringify({ path: fileName, parent: selectedItem.path+'/'+selectedItem.name }) , headers: { 'Content-Type': 'application/json' } })
|
||||
.then(() => loadFileTree());
|
||||
fetch(`/vsc-like/create-folder`, { method: 'POST', body: JSON.stringify({ path: folderName, parent: selectedItem.path+'/'+selectedItem.name }) , headers: { 'Content-Type': 'application/json' } })
|
||||
.then(() => {loadFileTree();showNotification('success', '文件夹已成功创建!')});
|
||||
} else {
|
||||
fetch(`/vsc-like/create-folder`, { method: 'POST', body: JSON.stringify({ path: fileName, parent: selectedItem.path }) , headers: { 'Content-Type': 'application/json' } })
|
||||
.then(() => loadFileTree());
|
||||
fetch(`/vsc-like/create-folder`, { method: 'POST', body: JSON.stringify({ path: folderName, parent: selectedItem.path }) , headers: { 'Content-Type': 'application/json' } })
|
||||
.then(() => {loadFileTree();showNotification('success', '文件夹已成功创建!')});
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 触发保存成功时按钮的动画
|
||||
function triggerSaveAnimation() {
|
||||
const saveButton = document.getElementById('saveBtn');
|
||||
|
||||
// 先清除已有的动画类
|
||||
saveButton.classList.remove('bounce-animation', 'bigger-color');
|
||||
|
||||
// 添加新的动画类
|
||||
saveButton.classList.add('bounce-animation', 'bigger-color');
|
||||
|
||||
// 动画完成后移除动画类(确保可以重复触发动画)
|
||||
setTimeout(() => {
|
||||
saveButton.classList.remove('bounce-animation', 'bigger-color');
|
||||
}, 500); // 500ms后移除动画
|
||||
}
|
||||
|
||||
function postSaveFile(path, content){
|
||||
|
||||
fetch(`/vsc-like/save-file`, { method: 'POST', body: JSON.stringify({ path: path, content: content }) , headers: { 'Content-Type': 'application/json' } })
|
||||
.then(() => loadFileTree());
|
||||
.then(() => {
|
||||
loadFileTree();
|
||||
triggerSaveAnimation(); // 触发按钮动画
|
||||
showNotification('success', '文件已成功保存!');
|
||||
});
|
||||
}
|
||||
document.addEventListener('keydown', function(event) {
|
||||
// 检查是否按下Ctrl+S
|
||||
if (event.ctrlKey && event.key === 's') {
|
||||
event.preventDefault(); // 阻止默认的保存操作
|
||||
postSaveFile(selectedItem.path+'/'+selectedItem.name, editor.getValue()); // 手动保存
|
||||
}
|
||||
});
|
||||
|
||||
// 保存文件
|
||||
function saveFile(event) {
|
||||
|
||||
46
code-server-like/static/js/notification.js
Normal file
46
code-server-like/static/js/notification.js
Normal file
@@ -0,0 +1,46 @@
|
||||
let notificationCount = 0; // 当前显示的提示框数量
|
||||
|
||||
function showNotification(type, message) {
|
||||
// 判断是否有超过3个提示框
|
||||
if (notificationCount >= 3) {
|
||||
// 删除第一个(最早的)提示框
|
||||
const firstNotification = document.querySelector('.notification');
|
||||
if (firstNotification) {
|
||||
firstNotification.remove();
|
||||
notificationCount--;
|
||||
}
|
||||
}
|
||||
|
||||
// 创建新的提示框
|
||||
const notification = document.createElement('div');
|
||||
notification.classList.add('notification', type);
|
||||
|
||||
// 设置提示框图标和文本
|
||||
const icon = document.createElement('div');
|
||||
icon.classList.add('icon');
|
||||
notification.appendChild(icon);
|
||||
|
||||
const text = document.createElement('div');
|
||||
text.textContent = message;
|
||||
notification.appendChild(text);
|
||||
|
||||
// 添加提示框到页面
|
||||
const container = document.getElementById('notificationsContainer');
|
||||
container.appendChild(notification);
|
||||
|
||||
// 增加提示框数量
|
||||
notificationCount++;
|
||||
|
||||
// 设置5秒后自动消失
|
||||
setTimeout(() => {
|
||||
notification.style.opacity = 0;
|
||||
setTimeout(() => notification.remove(), 500); // 完全消失后移除
|
||||
notificationCount--;
|
||||
}, 5000); // 5秒后渐渐消失
|
||||
}
|
||||
|
||||
// 示例:调用方法
|
||||
// showNotification('success', '文件已成功保存!');
|
||||
// showNotification('warning', '保存的文件有部分丢失数据!');
|
||||
// showNotification('error', '文件保存失败,请重试!');
|
||||
// showNotification('info', '有新通知!');
|
||||
Reference in New Issue
Block a user