feat(md-deck): Add fallback copy dialog for clipboard failure

This commit is contained in:
hyper
2026-08-07 12:13:40 +08:00
parent e3daac3080
commit 9e081891df
2 changed files with 94 additions and 31 deletions
+8 -4
View File
@@ -145,7 +145,7 @@ export interface DeckActions {
clearError: () => void;
generateCode: (backLayersStr?: string) => string;
copyCode: (backLayersStr?: string) => Promise<void>;
copyCode: (fallback?: (code: string) => void) => Promise<void>;
setExporting: (exporting: boolean) => void;
exportDeck: () => void;
@@ -514,14 +514,18 @@ export function createDeckStore(initialSrc: string = ""): DeckStore {
return parts.join("");
};
const copyCode = async (backLayersStr?: string) => {
const code = generateCode(backLayersStr);
const copyCode = async (fallback?: (code: string) => void) => {
const code = generateCode();
try {
await navigator.clipboard.writeText(code);
alert("已复制到剪贴板!");
} catch (err) {
console.error("复制失败:", err);
alert("复制失败,请手动复制");
if (fallback) {
fallback(code);
} else {
alert("复制失败,请手动复制");
}
}
};