FileSystem
移动端 Capacitor filesystem;桌面 Electron;Web 回退 localStorage。
- write, read, delete, exists, getUri, stat
TSXFileSystem — CRUD helper
1import { FileSystem, toast } from "@quan-erp/shared-frontend-core";
2
3const DRAFT = "notes/draft.txt";
4
5export async function saveDraft(text: string) {
6 const fs = FileSystem.instance;
7 try {
8 await fs.write(DRAFT, text);
9 } catch (e) {
10 toast.error((e as Error).message ?? "Write failed");
11 }
12}
13
14export async function loadDraft() {
15 const fs = FileSystem.instance;
16 try {
17 if (!(await fs.exists(DRAFT))) return "";
18 return await fs.read(DRAFT);
19 } catch (e) {
20 toast.error((e as Error).message ?? "Read failed");
21 return "";
22 }
23}
24
25export async function clearDraft() {
26 const fs = FileSystem.instance;
27 if (await fs.exists(DRAFT)) await fs.delete(DRAFT);
28}
29
30export async function draftMeta() {
31 const fs = FileSystem.instance;
32 const uri = await fs.getUri();
33 const stat = await fs.stat();
34 return { uri, stat };
35}