Files
sryang 577060bc78 chore: 首次簽入 Thinkyu ASP.NET 專案
- 加入 Visual Studio / ASP.NET .gitignore
- 排除建置輸出、IDE 設定、NuGet packages、大型 MSI 安裝檔
2026-09-10 09:42:37 +08:00

36 lines
1.3 KiB
JavaScript

// Vue Mixin - Base64 工具
// 提供 Base64 字串轉換為 Blob 的功能
var Base64Mixin = {
methods: {
/**
* 將 Base64 字串轉換為 Blob 物件
* @param {string} base64 - Base64 編碼字串
* @returns {Blob} Excel 格式的 Blob 物件
*/
Base64ToBlob: function(base64) {
try {
if (!base64 || typeof base64 !== 'string') {
throw new Error('Invalid input: Base64 string is required');
}
var cleanBase64 = base64.replace(/\s/g, '');
if (!cleanBase64 || !/^[A-Za-z0-9+/]*={0,2}$/.test(cleanBase64)) {
throw new Error('Invalid Base64 string format');
}
var binaryString = atob(cleanBase64);
var bytes = new Uint8Array(binaryString.length);
for (var i = 0; i < binaryString.length; i++) {
bytes[i] = binaryString.charCodeAt(i);
}
return new Blob([bytes], { type: 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet' });
} catch (error) {
console.error('Base64ToBlob error:', error);
throw error;
}
}
}
};