feat: 支持右键菜单图片二维码识别
- 在 qrCodeParser.ts 中添加 parseQrCodeFromUrl 函数,支持从图片 URL 解析二维码 - 在 QrCodeToUrlSection 中使用 useContextMenuData 接收右键菜单传递的图片 URL - 自动下载图片并解析二维码,显示解析结果
This commit is contained in:
@@ -35,3 +35,24 @@ export async function parseQrCodeFromFile(file: File): Promise<QrCodeParseResult
|
||||
return { success: false, error: errorMsg };
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 从图片 URL 解析二维码
|
||||
* 先下载图片,然后调用 parseQrCodeFromFile
|
||||
*/
|
||||
export async function parseQrCodeFromUrl(imageUrl: string): Promise<QrCodeParseResult> {
|
||||
try {
|
||||
const response = await fetch(imageUrl);
|
||||
if (!response.ok) {
|
||||
return { success: false, error: '无法下载图片' };
|
||||
}
|
||||
|
||||
const blob = await response.blob();
|
||||
const file = new File([blob], 'qrcode.jpg', { type: blob.type || 'image/jpeg' });
|
||||
|
||||
return await parseQrCodeFromFile(file);
|
||||
} catch (err) {
|
||||
const errorMsg = err instanceof Error ? err.message : String(err);
|
||||
return { success: false, error: `下载图片失败: ${errorMsg}` };
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user