fix: 生成页错误处理,编辑模式支持更新模板文件
This commit is contained in:
parent
696fd54809
commit
fcf3d5c7c2
@ -19,11 +19,11 @@ function saveTemplate({ name, grp = "", file_path, fields = [] }) {
|
||||
return id;
|
||||
}
|
||||
|
||||
function updateTemplate(id, { name, grp, fields }) {
|
||||
function updateTemplate(id, { name, grp, file_path, fields }) {
|
||||
const now = new Date().toISOString();
|
||||
if (name !== undefined || grp !== undefined) {
|
||||
db.prepare("UPDATE templates SET name = COALESCE(?, name), grp = COALESCE(?, grp), updated_at = ? WHERE id = ?")
|
||||
.run(name ?? null, grp ?? null, now, id);
|
||||
if (name !== undefined || grp !== undefined || file_path !== undefined) {
|
||||
db.prepare("UPDATE templates SET name = COALESCE(?, name), grp = COALESCE(?, grp), file_path = COALESCE(?, file_path), updated_at = ? WHERE id = ?")
|
||||
.run(name ?? null, grp ?? null, file_path ?? null, now, id);
|
||||
}
|
||||
if (fields !== undefined) {
|
||||
db.prepare("DELETE FROM fields WHERE template_id = ?").run(id);
|
||||
|
||||
@ -69,6 +69,8 @@ export default function Generate() {
|
||||
filename_pattern: filenamePattern,
|
||||
});
|
||||
setResults(result.results);
|
||||
} catch (err) {
|
||||
alert("生成失败:" + (err.message || String(err)));
|
||||
} finally {
|
||||
setGenerating(false);
|
||||
}
|
||||
|
||||
@ -10,6 +10,7 @@ export default function TemplateConfig() {
|
||||
const [name, setName] = useState("");
|
||||
const [grp, setGrp] = useState("");
|
||||
const [filePath, setFilePath] = useState("");
|
||||
const [originalFilePath, setOriginalFilePath] = useState("");
|
||||
const [fields, setFields] = useState([]);
|
||||
const [autoDetected, setAutoDetected] = useState([]);
|
||||
const [saving, setSaving] = useState(false);
|
||||
@ -22,6 +23,7 @@ export default function TemplateConfig() {
|
||||
setName(t.name);
|
||||
setGrp(t.grp || "");
|
||||
setFilePath(t.file_path);
|
||||
setOriginalFilePath(t.file_path);
|
||||
setFields(t.fields || []);
|
||||
}
|
||||
});
|
||||
@ -60,7 +62,11 @@ export default function TemplateConfig() {
|
||||
const storedPath = await window.api.copyFileToAppData(filePath, tempId);
|
||||
await window.api.saveTemplate({ name, grp, file_path: storedPath, fields });
|
||||
} else {
|
||||
await window.api.updateTemplate(id, { name, grp, fields });
|
||||
let storedPath;
|
||||
if (filePath !== originalFilePath) {
|
||||
storedPath = await window.api.copyFileToAppData(filePath, id);
|
||||
}
|
||||
await window.api.updateTemplate(id, { name, grp, file_path: storedPath, fields });
|
||||
}
|
||||
navigate("/templates");
|
||||
} finally {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user