Skip to content

Commit

Permalink
refactor: 优化代码保存逻辑并移除不再使用的 test.html 文件
Browse files Browse the repository at this point in the history
在多个文件中进行了以下更改:
- 在 `index.js` 中移除了 `Assemblies` 属性,优化了 `saveCode` 函数,使用递归方法更新文件内容。
- 删除了不再使用的 `test.html` 文件,简化项目结构。

这些更改提升了代码的可维护性和清晰度。
  • Loading branch information
gaoconggit committed Dec 17, 2024
1 parent 465d601 commit 56c7250
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 52 deletions.
17 changes: 11 additions & 6 deletions SharpPad/wwwroot/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -358,7 +358,6 @@ async function runCode(code) {

const request = {
SourceCode: code,
Assemblies: [],
Packages: packages.map(p => ({
Id: p.id,
Version: p.version
Expand Down Expand Up @@ -668,7 +667,6 @@ function addFolder() {
}

function saveCode(code) {

try {
const fileId = document.querySelector('#fileListItems a.selected')?.getAttribute('data-file-id');
if (!fileId) {
Expand Down Expand Up @@ -703,11 +701,18 @@ function saveCode(code) {
// 保存到文件列表
const filesData = localStorage.getItem('controllerFiles');
const files = filesData ? JSON.parse(filesData) : [];
files.forEach(file => {
if (file.id === fileId) {
file.content = code;
const updateFileContent = (files, targetId, newCode) => {
for (const file of files) {
if (file.id === targetId) {
file.content = newCode;
return;
}
if (file.type === 'folder' && file.files) {
updateFileContent(file.files, targetId, newCode);
}
}
});
};
updateFileContent(files, fileId, code);
localStorage.setItem('controllerFiles', JSON.stringify(files));
showNotification('保存成功', 'success');
} catch (error) {
Expand Down
46 changes: 0 additions & 46 deletions SharpPad/wwwroot/test.html

This file was deleted.

0 comments on commit 56c7250

Please sign in to comment.