// * desc: 下载导出文件 // * @param blob :返回数据的blob对象或链接 // * @param fileName :下载后文件名标记 // * @param fileType :文件类 word(docx) excel(xlsx) ppt等 function downloadExportFile( blob: Blob | MediaSource, fileName: string, fileType: string, ) { const downloadElement = document.createElement('a'); let href: string | Blob | MediaSource = blob; if (typeof blob === 'string') { downloadElement.target = '_blank'; } else { href = window.URL.createObjectURL(blob); // 创建下载的链接 } downloadElement.href = href as any; downloadElement.download = fileName + '.' + fileType; // 下载后文件名 document.body.appendChild(downloadElement); downloadElement.click(); // 触发点击下载 document.body.removeChild(downloadElement); // 下载完成移除元素 if (typeof blob !== 'string') { window.URL.revokeObjectURL(href as any); // 释放掉blob对象 } } // * desc: base64转文件并下载 // * @param base64 {String} : base64数据 // * @param fileType {String} : 要导出的文件类型png,pdf,doc,mp3等 // * @param fileName {String} : 文件名 export function downloadFile(base64: string, fileName: any, fileType: string) { const typeHeader = 'data:application/' + fileType + ';base64,'; // 定义base64 头部文件类型 const converedBase64 = typeHeader + base64; // 拼接最终的base64 const blob = this.base64ToBlob(converedBase64, fileType); // 转成blob对象 downloadExportFile(blob, fileName, fileType); // 下载文件 } import ar from '../i18n/ar_SA.json'; import cs from '../i18n/cs_CZ.json'; import da from '../i18n/da_DK.json'; import de from '../i18n/de_DE.json'; import el from '../i18n/el_GR.json'; import en from '../i18n/en_US.json'; import es from '../i18n/es_ES.json'; import fi from '../i18n/fi_FI.json'; import fr from '../i18n/fr_FR.json'; import he from '../i18n/he_IL.json'; import hr from '../i18n/hr_HR.json'; import hu from '../i18n/hu_HU.json'; import it from '../i18n/it_IT.json'; import ka from '../i18n/ka_GE.json'; import ko from '../i18n/ko_KR.json'; import nl from '../i18n/nl_NL.json'; import pl from '../i18n/pl_PL.json'; import pt from '../i18n/pt_PT.json'; import ro from '../i18n/ro_RO.json'; import ru from '../i18n/ru_RU.json'; import sk from '../i18n/sk_SK.json'; import sl from '../i18n/sl_SI.json'; import sv from '../i18n/sv_SE.json'; import th from '../i18n/th_TH.json'; import tr from '../i18n/tr_TR.json'; import uk from '../i18n/uk_UA.json'; import vi from '../i18n/vi_VN.json'; import zh from '../i18n/zh_CN.json'; import tw from '../i18n/zh_TW.json'; const langMap = { 'ar-SA': ar, 'cs-CZ': cs, 'da-DK': da, 'de-DE': de, 'el-GR': el, en: en, 'en-US': en, 'es-ES': es, 'fi-FI': fi, 'fr-FR': fr, 'he-IL': he, 'hr-HR': hr, 'hu-HU': hu, 'it-IT': it, 'ka-GE': ka, 'ko-KR': ko, 'nl-NL': nl, 'pl-PL': pl, 'pt-PT': pt, 'ro-RO': ro, 'ru-RU': ru, 'sk-SK': sk, 'sl-SI': sl, 'sv-SE': sv, 'th-TH': th, 'tr-TR': tr, 'uk-UA': uk, 'vi-VN': vi, 'zh-cn': zh, 'zh-CN': zh, 'zh-TW': tw, }; export const translate = (key: string, lang?: string) => { const curLang = sessionStorage.getItem(`ibuilding-locale`) || localStorage.getItem(`ibuilding-locale`) || 'zh-CN'; return langMap[lang]?.[key] || langMap[curLang]?.[key]; };