diff --git a/src/views/demo/signature.vue b/src/views/demo/signature.vue index c90e2ec8..51bc32f3 100644 --- a/src/views/demo/signature.vue +++ b/src/views/demo/signature.vue @@ -102,14 +102,17 @@ const handleSaveImg = () => { const dataURLtoFile = (dataurl: string, filename: string) => { const arr: string[] = dataurl.split(","); if (!arr.length) return; - const mime = arr[0]?.match(/:(.*?);/)[1]; - const bstr = atob(arr[1]); - let n = bstr.length; - const u8arr = new Uint8Array(n); - while (n--) { - u8arr[n] = bstr.charCodeAt(n); + + const mime = arr[0].match(/:(.*?);/); + if (mime && !mime.length) { + const bstr = atob(arr[1]); + let n = bstr.length; + const u8arr = new Uint8Array(n); + while (n--) { + u8arr[n] = bstr.charCodeAt(n); + } + return new File([u8arr], filename, { type: mime[0] }); } - return new File([u8arr], filename, { type: mime }); }; // canvas 画图 function paint(