Skip to content

Commit 99e05df

Browse files
committed
feat: v1.3.1
1 parent e94813a commit 99e05df

File tree

6 files changed

+35
-11
lines changed

6 files changed

+35
-11
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# 更新日志
22

3+
## 1.3.1
4+
5+
- 新增打开不存在文件,编辑后可选择新增并保存
6+
37
## 1.3.0
48

59
- 优化资源加载方式,大幅度提升加载速度

app/manifest

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
appname=code.editor
2-
version=1.3.0
2+
version=1.3.1
33
desc=`<div>VS Code 同源库,支持多种编码文件的操作,更有语法高亮、代码补全。</div>
44
<div>text、txt、js、ts、html、htm、css、scss、less、json、md、py、java、c、cpp、cc、cxx、go、rs、php、rb、sh、sql、xml、yaml、yml、vue 后缀文件直接双击文件或右键选择代码编辑器打开。</div><div>非上述后缀文件,右键【详细信息】-【复制原始路径】,点击桌面图标访问后粘贴路径打开。</div>
55
<div>提示:编辑用户目录中的文件需【系统设置】-【应用】-【代码编辑器】进行文件夹授权,应用文件夹中目录下可直接编辑;</div><div>提示:移动端暂未做 UI 适配,访问可能布局错乱;访问二进制文件将显示乱码,请谨慎操作。</div>`

backend/src/router/save.js

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,31 @@
11
const fs = require("fs");
22
const iconv = require("iconv-lite");
3+
const { dirname } = require("path");
34

45
module.exports = async function read({ body }) {
5-
const { path, encode, value } = body;
6+
const { path, encode, value, force } = body;
67

78
if (!path) {
89
return { code: 400, msg: "缺少文件路径参数", data: body };
910
}
1011

1112
try {
12-
if (!fs.existsSync(path)) {
13-
return { code: 404, msg: "文件不存在", data: body };
14-
}
13+
const fileExists = fs.existsSync(path);
14+
15+
if (fs.existsSync(path)) {
16+
const stat = fs.statSync(path);
17+
if (!stat.isFile()) {
18+
return { code: 400, msg: "路径不是文件", data: body };
19+
}
1520

16-
const stat = fs.statSync(path);
17-
if (!stat.isFile()) {
18-
return { code: 400, msg: "路径不是文件", data: body };
21+
fs.writeFileSync(path, iconv.encode(value, encode));
22+
} else {
23+
if (Number(force) === 1) {
24+
const dir = dirname(path);
25+
fs.existsSync(dir) || fs.mkdirSync(dir, { recursive: true });
26+
} else {
27+
return { code: 404, msg: "文件不存在", data: body };
28+
}
1929
}
2030

2131
fs.writeFileSync(path, iconv.encode(value, encode));
@@ -27,7 +37,7 @@ module.exports = async function read({ body }) {
2737
} else if (err.code === "ENOENT") {
2838
return { code: 400, msg: "目录不存在,无法写入文件", data: body };
2939
} else {
30-
return { code: 400, msg: "文件操作错误", data: body };
40+
return { code: 400, msg: `文件操作错误: ${err.message}`, data: body };
3141
}
3242
}
3343
};

code.editor.fpk

-690 Bytes
Binary file not shown.

frontend/src/hooks/useCode.ts

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,14 +66,15 @@ export default function useCode(option: {
6666
}
6767
}
6868

69-
const upload = async () => {
69+
const upload = async (force?: 1) => {
7070
try {
7171
const { data: value }: any = await axios.post(
7272
HOST,
7373
{
7474
encode: code.encode,
7575
value: code.value,
7676
path: option.path,
77+
force,
7778
},
7879
{ params: { _api: 'save' } },
7980
)
@@ -85,7 +86,15 @@ export default function useCode(option: {
8586

8687
option.onSave()
8788
} else {
88-
ElMessage({ type: 'error', message: value.msg })
89+
if (value.code === 404) {
90+
ElMessageBox.confirm('文件不存在,是否创建并保存?', '提示', {
91+
confirmButtonText: '继续',
92+
cancelButtonText: '取消',
93+
type: 'info',
94+
}).then(() => upload(1))
95+
} else {
96+
ElMessage({ type: 'error', message: value.msg })
97+
}
8998
}
9099
} catch {
91100
ElMessage({ type: 'error', message: '操作失败' })

frontend/src/hooks/usePath.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ export default function usePath() {
2626
showCancelButton: !force,
2727
confirmButtonText: '确认',
2828
cancelButtonText: '取消',
29+
inputPlaceholder: '不存在的文件路径在编辑后可新增并保存',
2930
},
3031
)
3132
.then(({ value }) => value)

0 commit comments

Comments
 (0)